|
@@ -9,10 +9,7 @@ import com.fdkankan.manage.entity.AgentNew;
|
|
|
import com.fdkankan.manage.exception.BusinessException;
|
|
|
import com.fdkankan.manage.constant.CameraOutTypeEnum;
|
|
|
import com.fdkankan.manage.entity.Company;
|
|
|
-import com.fdkankan.manage.service.IAgentNewService;
|
|
|
-import com.fdkankan.manage.service.ICameraService;
|
|
|
-import com.fdkankan.manage.service.ICompanyService;
|
|
|
-import com.fdkankan.manage.service.IExcelService;
|
|
|
+import com.fdkankan.manage.service.*;
|
|
|
import com.fdkankan.manage.util.ExcelUtil;
|
|
|
import com.fdkankan.manage.vo.request.CameraInOutParam;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -48,6 +45,8 @@ public class ExcelServiceImpl implements IExcelService {
|
|
|
ICameraService cameraService;
|
|
|
@Autowired
|
|
|
IAgentNewService agentNewService;
|
|
|
+ @Autowired
|
|
|
+ IJyUserPlatformService jyUserPlatformService;
|
|
|
|
|
|
public void commonExport(HttpServletRequest request, HttpServletResponse response,String name,List<?> result,ExcelWriter excelWriter) throws Exception {
|
|
|
response.setContentType("application/vnd.ms-excel");
|
|
@@ -91,110 +90,17 @@ public class ExcelServiceImpl implements IExcelService {
|
|
|
try {
|
|
|
excelRowList = ExcelUtil.getExcelRowList(file);
|
|
|
}catch (Exception e){
|
|
|
+ log.info("updateExcel-error:{}",e);
|
|
|
throw new BusinessException(ResultCode.TEMPLATE_TYPE_ERROR);
|
|
|
}
|
|
|
- List<String> wifiNameList = new ArrayList<>();
|
|
|
- List<CameraInOutParam> params = new ArrayList<>();
|
|
|
- List<CameraInOutParam> companyParams = new ArrayList<>();
|
|
|
- List<Integer> errorIndex = new ArrayList<>();
|
|
|
- Integer index = 0;
|
|
|
- for (HashMap<Integer, String> map : excelRowList) {
|
|
|
- index ++;
|
|
|
- if(type == 0){ //入库
|
|
|
- if(index == 0 && !map.get(0).equals("设备入库模板")){
|
|
|
- throw new BusinessException(ResultCode.TEMPLATE_TYPE_ERROR);
|
|
|
- }
|
|
|
- if(index <4){ //从第四行开始
|
|
|
- continue;
|
|
|
- }
|
|
|
- String wifiName = map.get(0);
|
|
|
- if(StringUtils.isBlank(wifiName)){
|
|
|
- errorIndex.add(index -3);
|
|
|
- }
|
|
|
- wifiNameList.add(wifiName);
|
|
|
- }else if(type == 1){ //出库
|
|
|
- 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);
|
|
|
- }else if(type == 2){ //关联客户
|
|
|
- if(index == 0 && !map.get(0).equals("客户关联模板")){
|
|
|
- throw new BusinessException(ResultCode.TEMPLATE_TYPE_ERROR);
|
|
|
- }
|
|
|
- if(index <4){
|
|
|
- continue;
|
|
|
- }
|
|
|
- CameraInOutParam param = new CameraInOutParam();
|
|
|
- param.setCompanyName(map.get(0));
|
|
|
- param.setSnCode(map.get(1));
|
|
|
- if(StringUtils.isBlank(param.getSnCode()) || StringUtils.isBlank(param.getCompanyName())){
|
|
|
- errorIndex.add(index -3 );
|
|
|
- }
|
|
|
- companyParams.add(param);
|
|
|
- }
|
|
|
- }
|
|
|
- this.toExcelError(errorIndex);
|
|
|
-
|
|
|
- if(type == 0 && wifiNameList.size() <=0){
|
|
|
- throw new BusinessException(ResultCode.IN_TEMPLATE_EMPTY);
|
|
|
- }else if(type == 1 && params.size() <=0){
|
|
|
-
|
|
|
- throw new BusinessException(ResultCode.OUT_TEMPLATE_EMPTY);
|
|
|
- }else if(type == 2 && companyParams.size() <=0){
|
|
|
- throw new BusinessException(ResultCode.COMPANY_TEMPLATE_EMPTY);
|
|
|
- }
|
|
|
- if(wifiNameList.size() >0){
|
|
|
- return cameraService.ins(wifiNameList);
|
|
|
- }
|
|
|
- if(params.size() >0){
|
|
|
- return cameraService.outs(params);
|
|
|
- }
|
|
|
- if(companyParams.size() >0){
|
|
|
- return cameraService.updateCompany(companyParams);
|
|
|
+ switch (type){
|
|
|
+ case 0 :return cameraService.insExcelList(excelRowList);
|
|
|
+ case 1 :return cameraService.outExcelList(excelRowList);
|
|
|
+ case 2 :return cameraService.companyExcelList(excelRowList);
|
|
|
+ case 6 :return jyUserPlatformService.addPlatformUser(excelRowList);
|
|
|
+ default:
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
}
|
|
|
- return 0;
|
|
|
}
|
|
|
|
|
|
@Override
|