| | |
| | | package cn.iocoder.yudao.module.mes.service.pd.techconfirm; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.crm.api.customer.CrmCustomerApi; |
| | | import cn.iocoder.yudao.module.crm.api.customer.dto.CrmCustomerRespDTO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pd.techconfirm.vo.ProductTechConfirmImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pd.techconfirm.vo.ProductTechConfirmImportRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pd.techconfirm.vo.ProductTechConfirmPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pd.techconfirm.vo.ProductTechConfirmSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pd.techconfirm.ProductTechConfirmDO; |
| | |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| | |
| | | |
| | | @Resource |
| | | private ApprovalConfigApi approvalConfigApi; |
| | | |
| | | @Resource |
| | | private CrmCustomerApi customerApi; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | .build()); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ProductTechConfirmImportRespVO importTechConfirmList(List<ProductTechConfirmImportExcelVO> importList, boolean updateSupport) { |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(PD_TECH_CONFIRM_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | ProductTechConfirmImportRespVO respVO = ProductTechConfirmImportRespVO.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.getConfirmNo(), "第 " + currentIndex + " 行"); |
| | | if (StrUtil.isBlank(importItem.getConfirmNo())) { |
| | | respVO.getFailureCodes().put(key, "确认函编号不能为空"); |
| | | return; |
| | | } |
| | | // 1. 解析客户名称 |
| | | Long customerId = null; |
| | | if (StrUtil.isNotBlank(importItem.getCustomerName())) { |
| | | CrmCustomerRespDTO customer = customerApi.getCustomerByName(importItem.getCustomerName().trim()); |
| | | if (customer == null) { |
| | | respVO.getFailureCodes().put(key, "客户名称[" + importItem.getCustomerName() + "]不存在"); |
| | | return; |
| | | } |
| | | customerId = customer.getId(); |
| | | } |
| | | // 2. 构建请求并创建/更新(复用现有 create/update 服务,状态由 create 固定为草稿) |
| | | ProductTechConfirmSaveReqVO reqVO = BeanUtils.toBean(importItem, ProductTechConfirmSaveReqVO.class); |
| | | reqVO.setCustomerId(customerId); |
| | | try { |
| | | ProductTechConfirmDO exist = techConfirmMapper.selectByConfirmNo(importItem.getConfirmNo().trim()); |
| | | if (exist == null) { |
| | | reqVO.setId(null); |
| | | createTechConfirm(reqVO); |
| | | respVO.getCreateCodes().add(importItem.getConfirmNo()); |
| | | } else if (updateSupport) { |
| | | reqVO.setId(exist.getId()); |
| | | updateTechConfirm(reqVO); |
| | | respVO.getUpdateCodes().add(importItem.getConfirmNo()); |
| | | } else { |
| | | respVO.getFailureCodes().put(key, "确认函编号已存在"); |
| | | } |
| | | } catch (ServiceException e) { |
| | | respVO.getFailureCodes().put(key, e.getMessage()); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | /** |
| | | * 获取用户昵称 |
| | | * |
| | |
| | | } |
| | | |
| | | private void validateConfirmNoUnique(String confirmNo, Long excludeId) { |
| | | if (confirmNo == null) { |
| | | return; |
| | | // 确认函编号必填:VO 上的 @NotBlank 只覆盖接口入参,Service 内(含导入)仍需显式校验 |
| | | if (StrUtil.isBlank(confirmNo)) { |
| | | throw exception(PD_TECH_CONFIRM_NO_REQUIRED); |
| | | } |
| | | ProductTechConfirmDO techConfirm = techConfirmMapper.selectOne( |
| | | ProductTechConfirmDO::getConfirmNo, confirmNo); |