package com.glxp.api.service.thrsys; import cn.hutool.core.bean.BeanUtil; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.constant.ConstantStatus; import com.glxp.api.entity.thrsys.ThrProductsEntity; import com.glxp.api.entity.thrsys.ThrSystemDetailEntity; import com.glxp.api.http.ErpBasicClient; import com.glxp.api.req.thrsys.FilterThrProductsRequest; import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.thrsys.ThrProductsResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; /** * 根据系统设置,获取对应的第三方数据信息 */ @Service public class ThrDataService { @Resource private ThrSystemDetailService thrSystemDetailService; @Resource private ThrProductsService thrProductsService; @Resource private ErpBasicClient erpBasicClient; final Logger logger = LoggerFactory.getLogger(ThrDataService.class); public ThrProductsEntity getProducts(String code, String thirdSys) { ThrSystemDetailEntity thrSystemDetailEntity = thrSystemDetailService.selectByKey("piQueryUrl", thirdSys); if (thrSystemDetailEntity == null || !thrSystemDetailEntity.getEnabled()) { logger.info("第三方系统产品信息接口服务未启用"); return null; } if (thrSystemDetailEntity.getFromType() == 0) { FilterThrProductsRequest filterErpGoodsRequest = new FilterThrProductsRequest(); filterErpGoodsRequest.setCode(code); filterErpGoodsRequest.setPage(1); filterErpGoodsRequest.setLimit(1); BaseResponse> udiDlDeviceResponse = erpBasicClient.getErpProducts(filterErpGoodsRequest); if (udiDlDeviceResponse.getCode() == 20000) { List erpProductsResponses = udiDlDeviceResponse.getData().getList(); if (erpProductsResponses != null) { ThrProductsEntity thrProductsEntity = new ThrProductsEntity(); BeanUtil.copyProperties(erpProductsResponses.get(0), thrProductsEntity); return thrProductsEntity; } } } else { FilterThrProductsRequest filterThrProductsRequest = new FilterThrProductsRequest(); filterThrProductsRequest.setCode(code); filterThrProductsRequest.setThirdSysFk(thirdSys); List thrProductsEntitys = thrProductsService.filterThrProducts(filterThrProductsRequest); if (thrProductsEntitys != null && thrProductsEntitys.size() > 0) { return thrProductsEntitys.get(0); } } return null; } }