|
@ -2,13 +2,17 @@ package com.win.module.wms.service.project; |
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
import cn.hutool.core.util.StrUtil; |
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.google.common.annotations.VisibleForTesting; |
|
|
import com.google.common.annotations.VisibleForTesting; |
|
|
import com.win.framework.common.exception.ServiceException; |
|
|
import com.win.framework.common.exception.ServiceException; |
|
|
import com.win.framework.common.pojo.CustomConditions; |
|
|
import com.win.framework.common.pojo.CustomConditions; |
|
|
import com.win.framework.common.pojo.PageResult; |
|
|
import com.win.framework.common.pojo.PageResult; |
|
|
import com.win.framework.datapermission.core.util.DataPermissionUtils; |
|
|
import com.win.framework.datapermission.core.util.DataPermissionUtils; |
|
|
|
|
|
import com.win.module.wms.controller.bom.vo.BomImportErrorVO; |
|
|
import com.win.module.wms.controller.project.vo.*; |
|
|
import com.win.module.wms.controller.project.vo.*; |
|
|
|
|
|
import com.win.module.wms.convert.bom.BomConvert; |
|
|
import com.win.module.wms.convert.project.ProjectConvert; |
|
|
import com.win.module.wms.convert.project.ProjectConvert; |
|
|
|
|
|
import com.win.module.wms.dal.dataobject.bom.BomDO; |
|
|
import com.win.module.wms.dal.dataobject.owner.OwnerDO; |
|
|
import com.win.module.wms.dal.dataobject.owner.OwnerDO; |
|
|
import com.win.module.wms.dal.dataobject.project.ProjectDO; |
|
|
import com.win.module.wms.dal.dataobject.project.ProjectDO; |
|
|
import com.win.module.wms.dal.mysql.project.ProjectMapper; |
|
|
import com.win.module.wms.dal.mysql.project.ProjectMapper; |
|
@ -86,37 +90,56 @@ public class ProjectServiceImpl implements ProjectService { |
|
|
return projectMapper.selectList(exportReqVO); |
|
|
return projectMapper.selectList(exportReqVO); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String validateProjectImport( ProjectDO project ){ |
|
|
|
|
|
StringBuilder message = new StringBuilder(); |
|
|
|
|
|
try { |
|
|
|
|
|
validateProjectForCreateOrUpdate(null,project.getCode(),project.getAvailable()); |
|
|
|
|
|
} catch (ServiceException ex) { |
|
|
|
|
|
message.append(ex.getMessage()).append(","); |
|
|
|
|
|
} |
|
|
|
|
|
return message.toString(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ProjectDO existProjectDO(ProjectDO project){ |
|
|
|
|
|
QueryWrapper<ProjectDO> queryWrapper = new QueryWrapper(); |
|
|
|
|
|
queryWrapper.eq("code",project.getCode()); |
|
|
|
|
|
ProjectDO projectDO = projectMapper.selectOne(queryWrapper); |
|
|
|
|
|
return projectDO; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public List<ProjectImportExcelVO> importProjectList(List<ProjectImportExcelVO> projects, Integer mode, Boolean updatePart) { |
|
|
public List<ProjectImportErrorVO> importProjectList(List<ProjectImportExcelVO> projects, Integer mode, Boolean updatePart) { |
|
|
if (CollUtil.isEmpty(projects)) { |
|
|
if (CollUtil.isEmpty(projects)) { |
|
|
throw exception(PROJECT_IMPORT_LIST_IS_EMPTY); |
|
|
throw exception(PROJECT_IMPORT_LIST_IS_EMPTY); |
|
|
} |
|
|
} |
|
|
List<ProjectImportExcelVO> errorList = new ArrayList<>(); |
|
|
List<ProjectImportErrorVO> errorList = new ArrayList<>(); |
|
|
projects.forEach(project -> { |
|
|
projects.forEach(project -> { |
|
|
|
|
|
ProjectDO projectDo = ProjectConvert.INSTANCE.convert(project); |
|
|
// 校验,判断是否有不符合的原因
|
|
|
// 校验,判断是否有不符合的原因
|
|
|
try { |
|
|
String message = this.validateProjectImport(projectDo); |
|
|
if(mode != null){ |
|
|
boolean flag = true; |
|
|
validateProjectForCreateOrUpdate(null,project.getCode(),project.getAvailable()); |
|
|
if(!message.isEmpty()){ |
|
|
} |
|
|
ProjectImportErrorVO importErrorVO = ProjectConvert.INSTANCE.convert2(projectDo); |
|
|
} catch (ServiceException ex) { |
|
|
importErrorVO.setImportStatus("失败"); |
|
|
errorList.add(project); |
|
|
importErrorVO.setImportRemark(message.substring(0, message.length() - 1)); |
|
|
return; |
|
|
errorList.add(importErrorVO); |
|
|
} |
|
|
flag = false; |
|
|
// 判断如果不存在,在进行插入
|
|
|
|
|
|
OwnerDO existConfigurationSetting = null; |
|
|
|
|
|
if (existConfigurationSetting == null&& mode != 3) { |
|
|
|
|
|
projectMapper.insert(ProjectConvert.INSTANCE.convert(project)); |
|
|
|
|
|
} |
|
|
} |
|
|
else if (existConfigurationSetting != null && mode != 2) {// 如果存在,判断是否允许更新
|
|
|
if(flag) { |
|
|
ProjectDO projectDo = ProjectConvert.INSTANCE.convert(project); |
|
|
// 判断如果不存在,在进行插入
|
|
|
projectDo.setId(existConfigurationSetting.getId()); |
|
|
ProjectDO existConfigurationSetting = existProjectDO(projectDo); |
|
|
projectMapper.updateById(projectDo); |
|
|
if (existConfigurationSetting == null && mode != 3) { |
|
|
|
|
|
projectMapper.insert(ProjectConvert.INSTANCE.convert(project)); |
|
|
|
|
|
} else if (existConfigurationSetting != null && mode != 2) {// 如果存在,判断是否允许更新
|
|
|
|
|
|
projectDo.setId(existConfigurationSetting.getId()); |
|
|
|
|
|
projectMapper.updateById(projectDo); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
//错误不为空并非部分更新,手工回滚
|
|
|
|
|
|
if(!errorList.isEmpty() && !updatePart) { |
|
|
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
|
|
} |
|
|
|
|
|
return errorList; |
|
|
return errorList; |
|
|
} |
|
|
} |
|
|
private void validateProjectForCreateOrUpdate(Long id, String code,String available) { |
|
|
private void validateProjectForCreateOrUpdate(Long id, String code,String available) { |
|
@ -125,7 +148,6 @@ public class ProjectServiceImpl implements ProjectService { |
|
|
validateProjectExists(id); |
|
|
validateProjectExists(id); |
|
|
validateCodeExists(id,code); |
|
|
validateCodeExists(id,code); |
|
|
validateAvailableExists(available); |
|
|
validateAvailableExists(available); |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
private void validateProjectExists(Long id) { |
|
|
private void validateProjectExists(Long id) { |
|
|