package com.neusoft.smart.pos.gateway.service;

import com.neusoft.smart.pos.dto.org.response.PostOrgResponse;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import com.neusoft.smart.pos.framework.exception.BusinessCommonException;
import com.neusoft.smart.pos.gateway.service.feignService.RemoteOrgService;
import com.neusoft.smart.pos.redis.bean.DeviceInfo;
import com.neusoft.smart.pos.utils.PosDeviceRedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GoodsService {
    @Autowired
    RemoteOrgService remoteOrgService;

    public String getIndustryBySnCode(String snCode) {
        DeviceInfo deviceInfo = PosDeviceRedisUtils.getDeviceInfoBySerialNo(snCode);

        if (null == deviceInfo) {
            throw new BusinessCommonException("11001", "获取不到设备信息");
        }

        Integer orgId = deviceInfo.getOrganizationId();

        ResponseData<PostOrgResponse> response = remoteOrgService.getOrgDetail(orgId);
        if (!"200".equals(response.getCode()) || response.getResult() == null) {
            throw new RuntimeException("获取不到集团信息");
        }

        return response.getResult().getType();
    }
}
