|
|
@ -2,6 +2,7 @@ package com.win.module.wms.service.workstation; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.google.common.annotations.VisibleForTesting; |
|
|
|
import com.win.framework.common.exception.ServiceException; |
|
|
|
import com.win.framework.common.pojo.PageResult; |
|
|
|
import com.win.framework.datapermission.core.util.DataPermissionUtils; |
|
|
@ -17,12 +18,13 @@ import org.springframework.validation.annotation.Validated; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import static com.win.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
|
|
import static com.win.module.system.enums.ErrorCodeConstants.USER_IMPORT_LIST_IS_EMPTY; |
|
|
|
import static com.win.module.wms.enums.workstation.ErrorCodeConstants.*; |
|
|
|
import static com.win.module.wms.enums.itembasic.ErrorCodeConstants.*; |
|
|
|
import static com.win.module.wms.enums.workstation.ErrorCodeConstants.CODE_EXISTS; |
|
|
|
import static com.win.module.wms.enums.workstation.ErrorCodeConstants.WORKSTATION_NOT_EXISTS; |
|
|
|
|
|
|
|
/** |
|
|
|
* 工位 Service 实现类 |
|
|
@ -38,6 +40,7 @@ public class WorkstationServiceImpl implements WorkstationService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public Long createWorkstation(WorkstationCreateReqVO createReqVO) { |
|
|
|
validateWorkstationForCreateOrUpdate(createReqVO.getId(),createReqVO.getCode(),createReqVO.getWorkshopCode(),createReqVO.getProductionLineCode(),createReqVO.getAvailable()); |
|
|
|
// 插入
|
|
|
|
WorkstationDO workstation = WorkstationConvert.INSTANCE.convert(createReqVO); |
|
|
|
workstationMapper.insert(workstation); |
|
|
@ -47,6 +50,7 @@ public class WorkstationServiceImpl implements WorkstationService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void updateWorkstation(WorkstationUpdateReqVO updateReqVO) { |
|
|
|
validateWorkstationForCreateOrUpdate(updateReqVO.getId(),updateReqVO.getCode(),updateReqVO.getWorkshopCode(),updateReqVO.getProductionLineCode(),updateReqVO.getAvailable()); |
|
|
|
// 校验存在
|
|
|
|
validateWorkstationExists(updateReqVO.getId()); |
|
|
|
// 更新
|
|
|
@ -62,12 +66,6 @@ public class WorkstationServiceImpl implements WorkstationService { |
|
|
|
workstationMapper.deleteById(id); |
|
|
|
} |
|
|
|
|
|
|
|
private void validateWorkstationExists(Long id) { |
|
|
|
if (workstationMapper.selectById(id) == null) { |
|
|
|
throw exception(WORKSTATION_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public WorkstationDO getWorkstation(Long id) { |
|
|
|
return workstationMapper.selectById(id); |
|
|
@ -91,53 +89,65 @@ public class WorkstationServiceImpl implements WorkstationService { |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
|
|
|
public WorkstationImportRespVO importUserList(List<WorkstationImportExcelVo> workstations, Integer mode,Boolean updatePart) { |
|
|
|
public List<WorkstationImportExcelVo> importWorkstationList(List<WorkstationImportExcelVo> workstations, Integer mode,Boolean updatePart) { |
|
|
|
if (CollUtil.isEmpty(workstations)) { |
|
|
|
throw exception(USER_IMPORT_LIST_IS_EMPTY); |
|
|
|
} |
|
|
|
WorkstationImportRespVO respVO = WorkstationImportRespVO.builder().createWorkstations(new ArrayList<>()) |
|
|
|
.updateWorkstations(new ArrayList<>()).failureWorkstations(new LinkedHashMap<>()).build(); |
|
|
|
List<WorkstationImportExcelVo> errorList = new ArrayList<>(); |
|
|
|
workstations.forEach(workstation -> { |
|
|
|
// 校验,判断是否有不符合的原因
|
|
|
|
try { |
|
|
|
validateUserForCreateOrUpdate(null,workstation.getCode()); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
respVO.getFailureWorkstations().put(workstation.getCode(), ex.getMessage()); |
|
|
|
if(mode != null){ |
|
|
|
validateWorkstationForCreateOrUpdate(null,workstation.getCode(),workstation.getWorkshopCode(),workstation.getProductionLineCode(),workstation.getAvailable()); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (ServiceException ex) { |
|
|
|
errorList.add(workstation); |
|
|
|
return; |
|
|
|
} |
|
|
|
// 判断如果不存在,在进行插入
|
|
|
|
WorkstationDO existWorkstation = workstationMapper.selectByCode(workstation.getCode()); |
|
|
|
if (existWorkstation == null&& mode != 3) { |
|
|
|
WorkstationDO existAccountcalendar = workstationMapper.selectByCode(workstation.getCode()); |
|
|
|
if (existAccountcalendar == null&& mode != 3) { |
|
|
|
workstationMapper.insert(WorkstationConvert.INSTANCE.convert(workstation)); |
|
|
|
respVO.getCreateWorkstations().add(workstation.getCode()); |
|
|
|
} |
|
|
|
else if (existWorkstation != null && mode != 2) {// 如果存在,判断是否允许更新
|
|
|
|
WorkstationDO workstationDO = WorkstationConvert.INSTANCE.convert(workstation); |
|
|
|
workstationDO.setId(existWorkstation.getId()); |
|
|
|
workstationMapper.updateById(workstationDO); |
|
|
|
respVO.getUpdateWorkstations().add(workstation.getCode()); |
|
|
|
else if (existAccountcalendar != null && mode != 2) {// 如果存在,判断是否允许更新
|
|
|
|
WorkstationDO workstationDo = WorkstationConvert.INSTANCE.convert(workstation); |
|
|
|
workstationDo.setId(existAccountcalendar.getId()); |
|
|
|
workstationMapper.updateById(workstationDo); |
|
|
|
} |
|
|
|
}); |
|
|
|
//错误不为空并非部分更新,手工回滚
|
|
|
|
if(respVO.getUpdateWorkstations().isEmpty() && !updatePart) { |
|
|
|
respVO.setUpdateWorkstations(new ArrayList<>()); |
|
|
|
respVO.setCreateWorkstations(new ArrayList<>()); |
|
|
|
if(!errorList.isEmpty() && !updatePart) { |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
} |
|
|
|
return respVO; |
|
|
|
return errorList; |
|
|
|
} |
|
|
|
|
|
|
|
private void validateUserForCreateOrUpdate(Long id,String code) { |
|
|
|
private void validateWorkstationForCreateOrUpdate(Long id,String code,String workshopCode,String productionLineCode,String available) { |
|
|
|
// 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确
|
|
|
|
DataPermissionUtils.executeIgnore(() -> { |
|
|
|
// 校验code唯一
|
|
|
|
codeExists(id,code); |
|
|
|
validateWorkstationExists(id); |
|
|
|
validateCodeExists(id,code); |
|
|
|
validateWorkshopCodeExists(workshopCode); |
|
|
|
validateProductionLineCodeExists(productionLineCode); |
|
|
|
validateAvailableExists(available); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private void codeExists(Long id, String code) { |
|
|
|
@VisibleForTesting |
|
|
|
private void validateWorkstationExists(Long id) { |
|
|
|
if (id == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
WorkstationDO workstation = workstationMapper.selectById(id); |
|
|
|
if (workstation == null) { |
|
|
|
throw exception(WORKSTATION_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
@VisibleForTesting |
|
|
|
private void validateCodeExists(Long id, String code) { |
|
|
|
if (code.isEmpty()) { |
|
|
|
throw exception(CODE_EXISTS); |
|
|
|
throw exception(CODE_NOT_EXISTS); |
|
|
|
} |
|
|
|
if (StrUtil.isBlank(code)) { |
|
|
|
return; |
|
|
@ -154,4 +164,22 @@ public class WorkstationServiceImpl implements WorkstationService { |
|
|
|
throw exception(CODE_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
@VisibleForTesting |
|
|
|
private void validateWorkshopCodeExists(String workshopCode) { |
|
|
|
if (workshopCode.isEmpty()) { |
|
|
|
throw exception(TYPE_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
@VisibleForTesting |
|
|
|
private void validateProductionLineCodeExists(String productionLineCode) { |
|
|
|
if (productionLineCode == null) { |
|
|
|
throw exception(VALIDITY_DAYS_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
@VisibleForTesting |
|
|
|
private void validateAvailableExists(String available) { |
|
|
|
if (available == null) { |
|
|
|
throw exception(AVAIABLE_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|