| | |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.process.vo.MesProProcessImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.process.vo.MesProProcessImportRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.process.vo.MesProProcessPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.process.vo.MesProProcessSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.process.MesProProcessDO; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; |
| | |
| | | /** |
| | | * MES 生产工序 Service 实现类 |
| | | * |
| | | * @author 芋道源码 |
| | | * @author 超级管理员 |
| | | */ |
| | | @Service |
| | | @Validated |
| | |
| | | } |
| | | |
| | | @Override |
| | | public MesProProcessDO getProcessByName(String name) { |
| | | return processMapper.selectByName(name); |
| | | } |
| | | |
| | | @Override |
| | | public PageResult<MesProProcessDO> getProcessPage(MesProProcessPageReqVO pageReqVO) { |
| | | return processMapper.selectPage(pageReqVO); |
| | | } |
| | |
| | | return processMapper.selectListByStatus(status); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public MesProProcessImportRespVO importProcessList(List<MesProProcessImportExcelVO> importList, |
| | | boolean updateSupport) { |
| | | // 1. 校验非空 |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(PRO_PROCESS_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | |
| | | // 2. 逐行处理 |
| | | MesProProcessImportRespVO respVO = MesProProcessImportRespVO.builder() |
| | | .createCodes(new ArrayList<>()).updateCodes(new ArrayList<>()) |
| | | .failureCodes(new LinkedHashMap<>()).build(); |
| | | AtomicInteger index = new AtomicInteger(1); |
| | | importList.forEach(importItem -> { |
| | | int currentIndex = index.getAndIncrement(); |
| | | String key = StrUtil.blankToDefault(importItem.getCode(), "第 " + currentIndex + " 行"); |
| | | if (StrUtil.isBlank(importItem.getCode())) { |
| | | respVO.getFailureCodes().put(key, "工序编码不能为空"); |
| | | return; |
| | | } |
| | | if (StrUtil.isBlank(importItem.getName())) { |
| | | respVO.getFailureCodes().put(key, "工序名称不能为空"); |
| | | return; |
| | | } |
| | | // 2.1 判断:创建 or 更新 |
| | | MesProProcessDO existProcess = processMapper.selectByCode(importItem.getCode()); |
| | | if (existProcess == null) { |
| | | // 2.1.1 新增 |
| | | MesProProcessDO process = BeanUtils.toBean(importItem, MesProProcessDO.class); |
| | | process.setId(null); |
| | | process.setStatus(ObjUtil.defaultIfNull(importItem.getStatus(), CommonStatusEnum.ENABLE.getStatus())); |
| | | processMapper.insert(process); |
| | | respVO.getCreateCodes().add(importItem.getCode()); |
| | | } else if (updateSupport) { |
| | | // 2.1.2 更新 |
| | | MesProProcessDO updateObj = BeanUtils.toBean(importItem, MesProProcessDO.class); |
| | | updateObj.setId(existProcess.getId()); |
| | | updateObj.setCode(existProcess.getCode()); |
| | | processMapper.updateById(updateObj); |
| | | respVO.getUpdateCodes().add(importItem.getCode()); |
| | | } else { |
| | | respVO.getFailureCodes().put(key, "工序编码已存在"); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |