feat: 导入License功能调整
This commit is contained in:
@@ -21,4 +21,9 @@ public class ImportRespVO {
|
|||||||
@Schema(description = "导入失败的集合,key 为导入关键字段,value 为失败原因", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "导入失败的集合,key 为导入关键字段,value 为失败原因", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
private Map<String, String> failures;
|
private Map<String, String> failures;
|
||||||
|
|
||||||
|
@Schema(description = "导入失败的集合,key 为失败原因,value 为sn", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
private Map<String, String> failureMap;
|
||||||
|
|
||||||
|
@Schema(description = "总条数", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
private Integer total;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,5 +69,9 @@ public class CustomerDO extends BaseDO {
|
|||||||
* 备注
|
* 备注
|
||||||
*/
|
*/
|
||||||
private String remark;
|
private String remark;
|
||||||
|
/**
|
||||||
|
* 数据类型
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Integer dataType;
|
||||||
}
|
}
|
||||||
@@ -84,5 +84,17 @@ public class LicenseDO extends BaseDO {
|
|||||||
* 备注
|
* 备注
|
||||||
*/
|
*/
|
||||||
private String remark;
|
private String remark;
|
||||||
|
/**
|
||||||
|
* 数据类型
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Integer dataType;
|
||||||
|
/**
|
||||||
|
* License管理员
|
||||||
|
*/
|
||||||
|
private Long licenseAdmin;
|
||||||
|
/**
|
||||||
|
* 审批时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime approveTime;
|
||||||
}
|
}
|
||||||
@@ -88,5 +88,17 @@ public class LicenseHistoryDO extends BaseDO {
|
|||||||
* 备注
|
* 备注
|
||||||
*/
|
*/
|
||||||
private String remark;
|
private String remark;
|
||||||
|
/**
|
||||||
|
* 数据类型
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Integer dataType;
|
||||||
|
/**
|
||||||
|
* License管理员
|
||||||
|
*/
|
||||||
|
private Long licenseAdmin;
|
||||||
|
/**
|
||||||
|
* 审批时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime approveTime;
|
||||||
}
|
}
|
||||||
@@ -105,5 +105,9 @@ public class ProjectDO extends BaseDO {
|
|||||||
* 备注
|
* 备注
|
||||||
*/
|
*/
|
||||||
private String remark;
|
private String remark;
|
||||||
|
/**
|
||||||
|
* 数据类型
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Integer dataType;
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.agt.module.license.dal.mysql.license;
|
package org.agt.module.license.dal.mysql.license;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import org.agt.framework.common.pojo.PageResult;
|
import org.agt.framework.common.pojo.PageResult;
|
||||||
import org.agt.framework.mybatis.core.mapper.BaseMapperX;
|
import org.agt.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
import org.agt.framework.mybatis.core.query.LambdaQueryWrapperX;
|
import org.agt.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
@@ -7,6 +8,7 @@ import org.agt.module.license.controller.admin.license.vo.LicensePageReqVO;
|
|||||||
import org.agt.module.license.dal.dataobject.license.LicenseDO;
|
import org.agt.module.license.dal.dataobject.license.LicenseDO;
|
||||||
import org.agt.module.license.enums.LicenseStatusEnum;
|
import org.agt.module.license.enums.LicenseStatusEnum;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -44,6 +46,8 @@ public interface LicenseMapper extends BaseMapperX<LicenseDO> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default LicenseDO selectBySn(String sn) {
|
default LicenseDO selectBySn(String sn) {
|
||||||
return selectOne(LicenseDO::getSerialNo, sn);
|
return selectOne(Wrappers.<LicenseDO>lambdaQuery().eq(LicenseDO::getSerialNo, sn), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LicenseDO getBySnAndProjectAndCustomer(@Param("serialNo") String serialNo, @Param("projectName") String projectName, @Param("customerName") String customerName);
|
||||||
}
|
}
|
||||||
@@ -85,4 +85,6 @@ public interface ProjectMapper extends BaseMapperX<ProjectDO> {
|
|||||||
IPage<ProjectRespVO> queryPage(IPage<?> page, @Param("query") ProjectPageReqVO reqVO);
|
IPage<ProjectRespVO> queryPage(IPage<?> page, @Param("query") ProjectPageReqVO reqVO);
|
||||||
|
|
||||||
List<ProjectRespVO> getLicenseProjects(@Param("query") ProjectListReqVO reqVO);
|
List<ProjectRespVO> getLicenseProjects(@Param("query") ProjectListReqVO reqVO);
|
||||||
|
|
||||||
|
ProjectDO getBySnAndProjectAndCustomer(@Param("serialNo") String serialNo, @Param("projectName") String projectName, @Param("customerName") String customerName);
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,6 @@ import java.time.LocalDateTime;
|
|||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -647,50 +646,63 @@ public class LicenseServiceImpl implements LicenseService {
|
|||||||
throw exception(LICENSE_IMPORT_LIST_IS_EMPTY);
|
throw exception(LICENSE_IMPORT_LIST_IS_EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
list = list.stream().filter(c -> StrUtil.isNotBlank(c.getSerialNo())).collect(Collectors.toList());
|
// list = list.stream().filter(c -> StrUtil.isNotBlank(c.getSerialNo())).collect(Collectors.toList());
|
||||||
for (LicenseImportExcelVO importExcelVO : list) {
|
// for (LicenseImportExcelVO importExcelVO : list) {
|
||||||
if (StrUtil.isBlank(importExcelVO.getProjectName())) {
|
// if (StrUtil.isBlank(importExcelVO.getProjectName())) {
|
||||||
importExcelVO.setProjectName(importExcelVO.getCustomerName() + "-" + importExcelVO.getSerialNo());
|
// importExcelVO.setProjectName(importExcelVO.getCustomerName() + "-" + importExcelVO.getSerialNo());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// 根据sn分组
|
// 根据sn分组
|
||||||
ImportRespVO respVO = ImportRespVO.builder().creates(new ArrayList<>())
|
ImportRespVO respVO = ImportRespVO.builder().creates(new ArrayList<>())
|
||||||
.updates(new ArrayList<>()).failures(new LinkedHashMap<>()).build();
|
.updates(new ArrayList<>()).failures(new LinkedHashMap<>()).build();
|
||||||
Map<String, List<LicenseImportExcelVO>> map = list.stream().collect(Collectors.groupingBy(LicenseImportExcelVO::getSerialNo));
|
// Map<String, List<LicenseImportExcelVO>> map = list.stream().collect(Collectors.groupingBy(LicenseImportExcelVO::getSerialNo));
|
||||||
|
//
|
||||||
List<LicenseImportExcelVO> imports = new ArrayList<>();
|
// List<LicenseImportExcelVO> imports = new ArrayList<>();
|
||||||
for (Map.Entry<String, List<LicenseImportExcelVO>> entry : map.entrySet()) {
|
// for (Map.Entry<String, List<LicenseImportExcelVO>> entry : map.entrySet()) {
|
||||||
String serialNo = entry.getKey();
|
// String serialNo = entry.getKey();
|
||||||
List<LicenseImportExcelVO> importList = entry.getValue();
|
// List<LicenseImportExcelVO> importList = entry.getValue();
|
||||||
|
//
|
||||||
if (importList.size() > 1) {
|
// if (importList.size() > 1) {
|
||||||
importList.sort(Comparator.comparing(LicenseImportExcelVO::getApplicationTime).reversed());
|
// importList.sort(Comparator.comparing(LicenseImportExcelVO::getApplicationTime).reversed());
|
||||||
imports.add(importList.get(0));
|
// imports.add(importList.get(0));
|
||||||
for (int i = 1; i < importList.size(); i++) {
|
// for (int i = 1; i < importList.size(); i++) {
|
||||||
respVO.getFailures().put(serialNo, "SN重复,以最新的为准");
|
// respVO.getFailures().put(serialNo, "SN重复,以最新的为准");
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// imports.addAll(importList);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
for (LicenseImportExcelVO importVO : list) {
|
||||||
|
if (StrUtil.isBlank(importVO.getProjectName())) {
|
||||||
|
importVO.setProjectName(importVO.getCustomerName() + "-" + importVO.getSerialNo());
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
imports.addAll(importList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (LicenseImportExcelVO importVO : imports) {
|
|
||||||
String serialNo = importVO.getSerialNo();
|
String serialNo = importVO.getSerialNo();
|
||||||
if (StrUtil.isBlank(importVO.getCustomerName())) {
|
if (StrUtil.isBlank(serialNo)) {
|
||||||
respVO.getFailures().put(importVO.getCustomerName(), "客户名称不能为空");
|
respVO.getFailures().put(importVO.getCustomerName(), "SN不能为空");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (StrUtil.isBlank(importVO.getCustomerName())) {
|
||||||
|
respVO.getFailures().put(serialNo, "客户名称不能为空");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
LocalDateTime createTime = getCreateTime(importVO);
|
||||||
CustomerDO customerDO = customerMapper.selectOne(Wrappers.<CustomerDO>lambdaQuery().eq(CustomerDO::getName, importVO.getCustomerName()), false);
|
CustomerDO customerDO = customerMapper.selectOne(Wrappers.<CustomerDO>lambdaQuery().eq(CustomerDO::getName, importVO.getCustomerName()), false);
|
||||||
if (customerDO == null) {
|
if (customerDO == null) {
|
||||||
Integer maxCustomerCode = customerMapper.selectOldMaxCode();
|
Integer maxCustomerCode = customerMapper.selectOldMaxCode();
|
||||||
customerDO = new CustomerDO();
|
customerDO = new CustomerDO();
|
||||||
customerDO.setName(importVO.getCustomerName());
|
customerDO.setName(importVO.getCustomerName());
|
||||||
customerDO.setCode(maxCustomerCode == null ? "1000" : maxCustomerCode + 1 + "");
|
customerDO.setCode(maxCustomerCode == null ? "1000" : maxCustomerCode + 1 + "");
|
||||||
|
customerDO.setDataType(1);
|
||||||
|
customerDO.setCreateTime(createTime);
|
||||||
customerMapper.insert(customerDO);
|
customerMapper.insert(customerDO);
|
||||||
|
} else if (updateSupport) {
|
||||||
|
customerDO.setCreateTime(createTime);
|
||||||
|
customerMapper.updateById(customerDO);
|
||||||
}
|
}
|
||||||
Long customerId = customerDO.getId();
|
Long customerId = customerDO.getId();
|
||||||
|
|
||||||
ProjectDO projectDO = projectMapper.selectOne(Wrappers.<ProjectDO>lambdaQuery().eq(ProjectDO::getName, importVO.getProjectName()), false);
|
ProjectDO projectDO = projectMapper.getBySnAndProjectAndCustomer(serialNo, importVO.getProjectName(), importVO.getCustomerName());
|
||||||
Long projectId = null;
|
Long projectId = null;
|
||||||
|
|
||||||
if (projectDO == null) {
|
if (projectDO == null) {
|
||||||
@@ -702,16 +714,21 @@ public class LicenseServiceImpl implements LicenseService {
|
|||||||
projectDO.setBusinessOwner(customerMapper.getUserByName(importVO.getBusinessOwnerName()));
|
projectDO.setBusinessOwner(customerMapper.getUserByName(importVO.getBusinessOwnerName()));
|
||||||
projectDO.setTechnicalOwnerA(customerMapper.getUserByName(importVO.getTechnicalOwnerAName()));
|
projectDO.setTechnicalOwnerA(customerMapper.getUserByName(importVO.getTechnicalOwnerAName()));
|
||||||
projectDO.setTechnicalOwnerB(customerMapper.getUserByName(importVO.getTechnicalOwnerBName()));
|
projectDO.setTechnicalOwnerB(customerMapper.getUserByName(importVO.getTechnicalOwnerBName()));
|
||||||
|
projectDO.setDataType(1);
|
||||||
|
projectDO.setCreateTime(createTime);
|
||||||
projectMapper.insert(projectDO);
|
projectMapper.insert(projectDO);
|
||||||
projectId = projectDO.getId();
|
projectId = projectDO.getId();
|
||||||
} else {
|
} else if (updateSupport) {
|
||||||
projectId = projectDO.getId();
|
projectId = projectDO.getId();
|
||||||
projectDO = BeanUtils.toBean(importVO, ProjectDO.class);
|
projectDO = BeanUtils.toBean(importVO, ProjectDO.class);
|
||||||
projectDO.setId(projectId);
|
projectDO.setId(projectId);
|
||||||
projectDO.setBusinessOwner(customerMapper.getUserByName(importVO.getBusinessOwnerName()));
|
projectDO.setBusinessOwner(customerMapper.getUserByName(importVO.getBusinessOwnerName()));
|
||||||
projectDO.setTechnicalOwnerA(customerMapper.getUserByName(importVO.getTechnicalOwnerAName()));
|
projectDO.setTechnicalOwnerA(customerMapper.getUserByName(importVO.getTechnicalOwnerAName()));
|
||||||
projectDO.setTechnicalOwnerB(customerMapper.getUserByName(importVO.getTechnicalOwnerBName()));
|
projectDO.setTechnicalOwnerB(customerMapper.getUserByName(importVO.getTechnicalOwnerBName()));
|
||||||
|
projectDO.setCreateTime(createTime);
|
||||||
projectMapper.updateById(projectDO);
|
projectMapper.updateById(projectDO);
|
||||||
|
} else {
|
||||||
|
projectId = projectDO.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
LicenseDO licenseDO = new LicenseDO();
|
LicenseDO licenseDO = new LicenseDO();
|
||||||
@@ -728,10 +745,10 @@ public class LicenseServiceImpl implements LicenseService {
|
|||||||
expiryDate = LocalDateTime.of(LocalDate.parse(expiryDateExt, DateTimeFormatter.ofPattern("yyyy/M/d")), LocalTime.of(23, 59, 59));
|
expiryDate = LocalDateTime.of(LocalDate.parse(expiryDateExt, DateTimeFormatter.ofPattern("yyyy/M/d")), LocalTime.of(23, 59, 59));
|
||||||
}
|
}
|
||||||
licenseDO.setExpiryDate(expiryDate);
|
licenseDO.setExpiryDate(expiryDate);
|
||||||
licenseDO.setApplicationTime(LocalDateTime.of(importVO.getApplicationTime(), LocalTime.of(0, 0, 0)));
|
licenseDO.setApplicationTime(createTime);
|
||||||
// licenseDO.setUserNumber(importVO.getUserNumber());
|
// licenseDO.setUserNumber(importVO.getUserNumber());
|
||||||
// licenseDO.setRanNumber(importVO.getRanNumber());
|
// licenseDO.setRanNumber(importVO.getRanNumber());
|
||||||
licenseDO.setApprover(161L);
|
// licenseDO.setApprover(161L);
|
||||||
|
|
||||||
String neListStr = importVO.getNeListStr();
|
String neListStr = importVO.getNeListStr();
|
||||||
List<Integer> neList = getNeList(neListStr);
|
List<Integer> neList = getNeList(neListStr);
|
||||||
@@ -740,8 +757,9 @@ public class LicenseServiceImpl implements LicenseService {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
LicenseDO license = licenseMapper.selectBySn(serialNo);
|
LicenseDO license = licenseMapper.getBySnAndProjectAndCustomer(serialNo, importVO.getProjectName(), importVO.getCustomerName());
|
||||||
if (license == null) {
|
if (license == null) {
|
||||||
|
licenseDO.setDataType(1);
|
||||||
licenseMapper.insert(licenseDO);
|
licenseMapper.insert(licenseDO);
|
||||||
LicenseDetailDO licenseDetailDO = new LicenseDetailDO();
|
LicenseDetailDO licenseDetailDO = new LicenseDetailDO();
|
||||||
licenseDetailDO.setLicenseId(licenseDO.getId());
|
licenseDetailDO.setLicenseId(licenseDO.getId());
|
||||||
@@ -751,7 +769,7 @@ public class LicenseServiceImpl implements LicenseService {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!updateSupport) {
|
if (!updateSupport) {
|
||||||
respVO.getFailures().put(serialNo, "已存在该SN的License");
|
respVO.getFailures().put(serialNo, "已存在相同的客户、项目和SN");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -773,9 +791,27 @@ public class LicenseServiceImpl implements LicenseService {
|
|||||||
respVO.getUpdates().add(serialNo);
|
respVO.getUpdates().add(serialNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, String> failures = respVO.getFailures();
|
||||||
|
Map<String, String> newMap = failures.entrySet().stream()
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
Map.Entry::getValue,
|
||||||
|
Map.Entry::getKey,
|
||||||
|
(existing, replacement) -> existing + "、" + replacement)); // 使用第一个遇到的key作为结果
|
||||||
|
respVO.setFailureMap(newMap);
|
||||||
|
respVO.setTotal(list.size());
|
||||||
return respVO;
|
return respVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static LocalDateTime getCreateTime(LicenseImportExcelVO importVO) {
|
||||||
|
LocalDateTime createTime = LocalDateTime.now();
|
||||||
|
try {
|
||||||
|
createTime = LocalDateTime.of(importVO.getApplicationTime(), LocalTime.of(0, 0, 0));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("导入excel时间错误:{}", e.getMessage());
|
||||||
|
}
|
||||||
|
return createTime;
|
||||||
|
}
|
||||||
|
|
||||||
private static List<Integer> getNeList(String neListStr) {
|
private static List<Integer> getNeList(String neListStr) {
|
||||||
|
|
||||||
List<Integer> neList = new ArrayList<>();
|
List<Integer> neList = new ArrayList<>();
|
||||||
|
|||||||
@@ -2,11 +2,27 @@
|
|||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="org.agt.module.license.dal.mysql.license.LicenseMapper">
|
<mapper namespace="org.agt.module.license.dal.mysql.license.LicenseMapper">
|
||||||
|
|
||||||
<!--
|
<select id="getBySnAndProjectAndCustomer" resultType="org.agt.module.license.dal.dataobject.license.LicenseDO">
|
||||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
SELECT
|
||||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
l.*
|
||||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
FROM
|
||||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
crm_license_server l
|
||||||
-->
|
LEFT JOIN crm_project p ON l.project_id = p.id
|
||||||
|
AND p.deleted = 0
|
||||||
|
LEFT JOIN crm_customer c ON l.customer_id = c.id
|
||||||
|
AND c.deleted = 0
|
||||||
|
WHERE
|
||||||
|
l.deleted = 0
|
||||||
|
<if test="serialNo != null and serialNo != ''">
|
||||||
|
AND l.serial_no = #{serialNo}
|
||||||
|
</if>
|
||||||
|
<if test="customerName != null and customerName != ''">
|
||||||
|
AND c.name = #{customerName}
|
||||||
|
</if>
|
||||||
|
<if test="projectName != null and projectName != ''">
|
||||||
|
AND p.name = #{projectName}
|
||||||
|
</if>
|
||||||
|
limit 1
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -83,4 +83,27 @@
|
|||||||
</if>
|
</if>
|
||||||
AND l.id IS NULL
|
AND l.id IS NULL
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="getBySnAndProjectAndCustomer" resultType="org.agt.module.license.dal.dataobject.project.ProjectDO">
|
||||||
|
SELECT
|
||||||
|
p.*
|
||||||
|
FROM
|
||||||
|
crm_project p
|
||||||
|
LEFT JOIN crm_customer c ON p.customer_id = c.id
|
||||||
|
AND c.deleted = 0
|
||||||
|
LEFT JOIN crm_license_server l ON l.project_id = p.id
|
||||||
|
AND l.deleted = 0
|
||||||
|
WHERE
|
||||||
|
p.deleted = 0
|
||||||
|
<if test="serialNo != null and serialNo != ''">
|
||||||
|
AND l.serial_no = #{serialNo}
|
||||||
|
</if>
|
||||||
|
<if test="customerName != null and customerName != ''">
|
||||||
|
AND c.name = #{customerName}
|
||||||
|
</if>
|
||||||
|
<if test="projectName != null and projectName != ''">
|
||||||
|
AND p.name = #{projectName}
|
||||||
|
</if>
|
||||||
|
limit 1
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user