| | |
| | | package cn.iocoder.yudao.module.mes.service.wm.barcode; |
| | | |
| | | 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.wm.barcode.vo.config.MesWmBarcodeConfigImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.barcode.vo.config.MesWmBarcodeConfigImportRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.barcode.vo.config.MesWmBarcodeConfigPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.wm.barcode.vo.config.MesWmBarcodeConfigSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.barcode.MesWmBarcodeConfigDO; |
| | |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.util.ArrayList; |
| | | 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.*; |
| | |
| | | return config; |
| | | } |
| | | |
| | | @Override |
| | | public List<MesWmBarcodeConfigDO> getEnableBarcodeConfigList() { |
| | | return barcodeConfigMapper.selectEnableList(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public MesWmBarcodeConfigImportRespVO importBarcodeConfigList(List<MesWmBarcodeConfigImportExcelVO> importList, boolean updateSupport) { |
| | | // 校验导入数据不能为空 |
| | | if (cn.hutool.core.collection.CollUtil.isEmpty(importList)) { |
| | | throw exception(WM_BARCODE_CONFIG_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | MesWmBarcodeConfigImportRespVO respVO = MesWmBarcodeConfigImportRespVO.builder() |
| | | .createCodes(new ArrayList<>()).updateCodes(new ArrayList<>()) |
| | | .failureCodes(new LinkedHashMap<>()).build(); |
| | | // 索引,用于错误提示 |
| | | AtomicInteger index = new AtomicInteger(1); |
| | | importList.forEach(importItem -> { |
| | | int currentIndex = index.getAndIncrement(); |
| | | Integer bizType = importItem.getBizType(); |
| | | String key = bizType != null ? String.valueOf(bizType) : "第 " + currentIndex + " 行"; |
| | | // 校验业务类型必填 |
| | | if (bizType == null) { |
| | | respVO.getFailureCodes().put(key, "业务类型不能为空"); |
| | | return; |
| | | } |
| | | // 校验条码格式必填 |
| | | if (importItem.getFormat() == null) { |
| | | respVO.getFailureCodes().put(key, "条码格式不能为空"); |
| | | return; |
| | | } |
| | | // 校验内容格式模板必填 |
| | | if (StrUtil.isBlank(importItem.getContentFormat())) { |
| | | respVO.getFailureCodes().put(key, "内容格式模板不能为空"); |
| | | return; |
| | | } |
| | | MesWmBarcodeConfigDO existing = barcodeConfigMapper.selectByBizType(bizType); |
| | | if (existing != null && updateSupport) { |
| | | // 更新 |
| | | MesWmBarcodeConfigDO updateObj = new MesWmBarcodeConfigDO(); |
| | | updateObj.setId(existing.getId()); |
| | | updateObj.setFormat(importItem.getFormat()); |
| | | updateObj.setContentFormat(importItem.getContentFormat()); |
| | | updateObj.setContentExample(importItem.getContentExample()); |
| | | updateObj.setAutoGenerateFlag(importItem.getAutoGenerateFlag()); |
| | | updateObj.setDefaultTemplate(importItem.getDefaultTemplate()); |
| | | updateObj.setStatus(importItem.getStatus()); |
| | | updateObj.setRemark(importItem.getRemark()); |
| | | barcodeConfigMapper.updateById(updateObj); |
| | | respVO.getUpdateCodes().add(String.valueOf(bizType)); |
| | | } else if (existing != null) { |
| | | respVO.getFailureCodes().put(key, "该业务类型的条码配置已存在:" + bizType); |
| | | } else { |
| | | // 创建 |
| | | MesWmBarcodeConfigDO createObj = new MesWmBarcodeConfigDO(); |
| | | createObj.setId(null); |
| | | createObj.setBizType(bizType); |
| | | createObj.setFormat(importItem.getFormat()); |
| | | createObj.setContentFormat(importItem.getContentFormat()); |
| | | createObj.setContentExample(importItem.getContentExample()); |
| | | createObj.setAutoGenerateFlag(ObjUtil.defaultIfNull(importItem.getAutoGenerateFlag(), Boolean.TRUE)); |
| | | createObj.setDefaultTemplate(importItem.getDefaultTemplate()); |
| | | createObj.setStatus(ObjUtil.defaultIfNull(importItem.getStatus(), CommonStatusEnum.ENABLE.getStatus())); |
| | | createObj.setRemark(importItem.getRemark()); |
| | | barcodeConfigMapper.insert(createObj); |
| | | respVO.getCreateCodes().add(String.valueOf(bizType)); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |