|
@@ -0,0 +1,101 @@
|
|
|
+package com.fdkankan.manage.factory;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.fdkankan.manage.common.ResultCode;
|
|
|
+import com.fdkankan.manage.constant.CameraOutTypeEnum;
|
|
|
+import com.fdkankan.manage.entity.AgentNew;
|
|
|
+import com.fdkankan.manage.exception.BusinessException;
|
|
|
+import com.fdkankan.manage.service.IAgentNewService;
|
|
|
+import com.fdkankan.manage.service.ICameraService;
|
|
|
+import com.fdkankan.manage.service.IExcelService;
|
|
|
+import com.fdkankan.manage.vo.request.CameraInOutParam;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Component("deviceOut")
|
|
|
+public class DeviceOutHandler implements ImportExcelHandler{
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IAgentNewService agentNewService;
|
|
|
+ @Autowired
|
|
|
+ private IExcelService excelService;
|
|
|
+ @Autowired
|
|
|
+ private ICameraService cameraService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int importExcel(List<HashMap<Integer, String>> excelRowList) {
|
|
|
+
|
|
|
+ if(CollUtil.isEmpty(excelRowList)){
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<CameraInOutParam> params = new ArrayList<>();
|
|
|
+ List<Integer> errorIndex = new ArrayList<>();
|
|
|
+
|
|
|
+ Integer index = 0;
|
|
|
+ for (HashMap<Integer, String> map : excelRowList) {
|
|
|
+ index ++;
|
|
|
+ if(index == 0 && !map.get(0).equals("设备出库模板")){
|
|
|
+ throw new BusinessException(ResultCode.TEMPLATE_TYPE_ERROR);
|
|
|
+ }
|
|
|
+ if(index <4){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String snCode = map.get(0);
|
|
|
+ String outTypeString = map.get(1);
|
|
|
+ String companyName = map.get(2);
|
|
|
+ String orderSn = map.get(3);
|
|
|
+ String agentName = map.get(4);
|
|
|
+ CameraOutTypeEnum outTypeEnum = CameraOutTypeEnum.getByMsg(outTypeString);
|
|
|
+ if(outTypeEnum == null || StringUtils.isBlank(snCode)){
|
|
|
+ log.error("outError-->出库错误:出库类型为空或snCode为空:snCode:{},outType:{},companyName:{},orderSn:{},agentName:{}"
|
|
|
+ ,snCode,outTypeString,companyName,orderSn,agentName);
|
|
|
+ errorIndex.add(index -3);
|
|
|
+ }
|
|
|
+ CameraInOutParam param = new CameraInOutParam();
|
|
|
+ if(outTypeEnum != null){
|
|
|
+ int outType = outTypeEnum.getCode();
|
|
|
+ param.setOutType(outType);
|
|
|
+ }
|
|
|
+ if(param.getOutType() != null && param.getOutType() == 4 && StringUtils.isBlank(agentName)){
|
|
|
+ log.error("outError-->出库错误:经销商为空错误:snCode:{},outType:{},companyName:{},orderSn:{},agentName:{}"
|
|
|
+ ,snCode,outTypeString,companyName,orderSn,agentName);
|
|
|
+ errorIndex.add(index -3);
|
|
|
+ }
|
|
|
+ if(param.getOutType() != null && param.getOutType() != 4 && StringUtils.isNotBlank(agentName)){
|
|
|
+ log.error("outError-->出库错误:出库类型错误:snCode:{},outType:{},companyName:{},orderSn:{},agentName:{}"
|
|
|
+ ,snCode,outTypeString,companyName,orderSn,agentName);
|
|
|
+ errorIndex.add(index -3);
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(agentName)){
|
|
|
+ AgentNew agentNew = agentNewService.getByName(agentName);
|
|
|
+ if(agentNew == null){
|
|
|
+ log.error("outError-->出库错误:代理商不存在:snCode:{},outType:{},companyName:{},orderSn:{},agentName:{}"
|
|
|
+ ,snCode,outTypeString,companyName,orderSn,agentName);
|
|
|
+ errorIndex.add(index -3);
|
|
|
+ }else {
|
|
|
+ param.setAgentId(agentNew.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ param.setCompanyName(companyName);
|
|
|
+ param.setOrderSn(orderSn);
|
|
|
+ param.setSnCode(snCode);
|
|
|
+ params.add(param);
|
|
|
+ }
|
|
|
+
|
|
|
+ excelService.toExcelError(errorIndex);
|
|
|
+
|
|
|
+ if(params.size() <=0){
|
|
|
+ throw new BusinessException(ResultCode.OUT_TEMPLATE_EMPTY);
|
|
|
+ }
|
|
|
+
|
|
|
+ return cameraService.outs(params);
|
|
|
+ }
|
|
|
+}
|