|
@@ -8,12 +8,15 @@ import cn.hutool.core.lang.tree.TreeUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.core.text.CharSequenceUtil;
|
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.qunzhixinxi.hnqz.admin.api.constant.UpmsState;
|
|
|
import com.qunzhixinxi.hnqz.admin.api.constant.UpmsType;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.constant.enums.DelEnum;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.constant.enums.LockEnum;
|
|
|
import com.qunzhixinxi.hnqz.admin.api.dto.SysImplementPlanDTO;
|
|
|
import com.qunzhixinxi.hnqz.admin.api.dto.SysImplementPlanDetailsDTO;
|
|
|
import com.qunzhixinxi.hnqz.admin.api.entity.SysDept;
|
|
@@ -606,4 +609,179 @@ public class SysImplementPlanManager {
|
|
|
|
|
|
return copied;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量创建
|
|
|
+ *
|
|
|
+ * @param resource 批量信息
|
|
|
+ * @param user 创建人
|
|
|
+ * @return 创建结果
|
|
|
+ */
|
|
|
+ public Map<String, String> createBatch(List<SysImplementPlanDTO.OnBatchCreate> resource, HnqzUser user) {
|
|
|
+
|
|
|
+ // 获取商品列表
|
|
|
+ Integer deptId = user.getDeptId();
|
|
|
+ List<Map<String, String>> drugs = drugEntDrugtableService.listDrugs(Collections.singletonList(deptId));
|
|
|
+
|
|
|
+ // 获取代理商
|
|
|
+ Map<String, SysDept> deptMap = deptService.list(Wrappers.<SysDept>lambdaQuery().eq(SysDept::getLevel, 3)).stream().collect(Collectors.toMap(SysDept::getName, Function.identity()));
|
|
|
+
|
|
|
+ // 校验表单信息
|
|
|
+ Map<String, String> errorMap = checkDataOnBatchCreate(resource, drugs, deptMap, deptId);
|
|
|
+ if (CollUtil.isNotEmpty(errorMap)) {
|
|
|
+ return errorMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 拼装信息
|
|
|
+ String username = user.getUsername();
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ List<SysImplementPlan> collect = resource.stream().map(item -> {
|
|
|
+ SysImplementPlan plan = new SysImplementPlan();
|
|
|
+ plan.setPlanName(item.getPlanName());
|
|
|
+ UpmsType.ImplementPlanType pt = "年度".equals(item.getPlanType()) ? UpmsType.ImplementPlanType.ANN : UpmsType.ImplementPlanType.QRT;
|
|
|
+ plan.setPlanType(pt);
|
|
|
+ plan.setParentId(0);
|
|
|
+ plan.setPlanState(UpmsState.ImplementPlanState.INIT);
|
|
|
+ Long score = Long.valueOf(item.getPlanScore());
|
|
|
+ plan.setAvailScore(score);
|
|
|
+ plan.setPlanScore(score);
|
|
|
+ Optional<String> skuId = drugs.stream().filter(drug -> StrUtil.equals(item.getSkuName(), drug.get("drug_name"))).map(drug -> drug.get("drug_id")).findFirst();
|
|
|
+ plan.setSkuId(Integer.valueOf(skuId.get()));
|
|
|
+ plan.setConsignorId(deptId);
|
|
|
+ SysDept dept = deptMap.get(item.getConsignee());
|
|
|
+ plan.setConsigneeId(dept.getDeptId());
|
|
|
+
|
|
|
+ LocalDate issue;
|
|
|
+ LocalDate expiry;
|
|
|
+
|
|
|
+ if (UpmsType.ImplementPlanType.ANN.equals(pt)) {
|
|
|
+ issue = LocalDate.of(Integer.parseInt(item.getYear()), 1, 1);
|
|
|
+ expiry = issue.plusYears(1).minusDays(1);
|
|
|
+ } else {
|
|
|
+ int qtr = Integer.parseInt(item.getQuarter());
|
|
|
+ int month = qtr * 3 - 2;
|
|
|
+ issue = LocalDate.of(Integer.parseInt(item.getYear()), month, 1);
|
|
|
+ expiry = issue.plusMonths(3).minusDays(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ plan.setPlanIssue(issue);
|
|
|
+ plan.setPlanExpiry(expiry);
|
|
|
+
|
|
|
+ plan.setLocFlag(LockEnum.UN_LOCK);
|
|
|
+ plan.setDelFlag(DelEnum.NOT_DEL);
|
|
|
+ plan.setCreateBy(username);
|
|
|
+ plan.setUpdateBy(username);
|
|
|
+ plan.setCreateTime(now);
|
|
|
+ plan.setUpdateTime(now);
|
|
|
+
|
|
|
+ return plan;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ implementPlanService.saveBatch(collect);
|
|
|
+
|
|
|
+ return Collections.emptyMap();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量创建校验
|
|
|
+ *
|
|
|
+ * @param resource 校验信息
|
|
|
+ */
|
|
|
+ private Map<String, String> checkDataOnBatchCreate(List<SysImplementPlanDTO.OnBatchCreate> resource,
|
|
|
+ List<Map<String, String>> drugs,
|
|
|
+ Map<String, SysDept> deptMap,
|
|
|
+ Integer deptId) {
|
|
|
+
|
|
|
+ Map<String, String> errorMap = new HashMap<>(500);
|
|
|
+
|
|
|
+ int size = resource.size();
|
|
|
+
|
|
|
+ // 校验size
|
|
|
+ if (size == 0) {
|
|
|
+ errorMap.put("idx", "1");
|
|
|
+ errorMap.put("errorMsg", "不能上传空表");
|
|
|
+ return errorMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (size > 500) {
|
|
|
+ errorMap.put("idx", "500");
|
|
|
+ errorMap.put("errorMsg", "单次支持最大批量数为500条");
|
|
|
+ return errorMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验表单重复项
|
|
|
+ Map<String, List<SysImplementPlanDTO.OnBatchCreate>> collect = resource.stream().collect(Collectors.groupingBy(SysImplementPlanDTO.OnBatchCreate::getPlanName));
|
|
|
+
|
|
|
+
|
|
|
+ // 校验信息项
|
|
|
+ for (int i = 0; i < size; i++) {
|
|
|
+
|
|
|
+ StringBuilder errorMsg = new StringBuilder();
|
|
|
+ SysImplementPlanDTO.OnBatchCreate res = resource.get(i);
|
|
|
+
|
|
|
+ String skuName = res.getSkuName();
|
|
|
+ String planType = res.getPlanType();
|
|
|
+ String planScore = res.getPlanScore();
|
|
|
+ String year = res.getYear();
|
|
|
+ String planName = res.getPlanName();
|
|
|
+ String quarter = res.getQuarter();
|
|
|
+ String consignee = res.getConsignee();
|
|
|
+
|
|
|
+ // 校验空值
|
|
|
+ if (StrUtil.hasBlank(skuName, planType, planScore, year, quarter, planName, consignee)) {
|
|
|
+ errorMsg.append("服务计划信息不全,存在未填写的内容;");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验积分
|
|
|
+ if (!NumberUtil.isLong(planScore)) {
|
|
|
+ errorMsg.append("计划值不是整数;");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验年度和季度
|
|
|
+ if (!NumberUtil.isInteger(year) || !NumberUtil.isInteger(quarter)) {
|
|
|
+ errorMsg.append("年度或季度非数字;");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollUtil.isEmpty(drugs)) {
|
|
|
+ errorMsg.append("产品不存在;");
|
|
|
+ } else {
|
|
|
+ Optional<Map<String, String>> drug = drugs.stream().filter(d -> StrUtil.equals(skuName, d.get("drug_name"))).findFirst();
|
|
|
+ if (!drug.isPresent()) {
|
|
|
+ errorMsg.append("产品不存在;");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验名称
|
|
|
+ List<SysImplementPlanDTO.OnBatchCreate> onBatchCreates = collect.get(planName);
|
|
|
+ if (CollUtil.isNotEmpty(onBatchCreates)) {
|
|
|
+ errorMsg.append("表单内存在重名服务计划名称;");
|
|
|
+ } else {
|
|
|
+ boolean dupName = implementPlanService.dupName(planName, deptId);
|
|
|
+ if (dupName) {
|
|
|
+ errorMsg.append("服务计划名称已存在;");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验承接单位
|
|
|
+ if (CollUtil.isEmpty(deptMap)) {
|
|
|
+ errorMsg.append("承接人不存在;");
|
|
|
+ } else {
|
|
|
+ SysDept sysDept = deptMap.get(consignee);
|
|
|
+ if (sysDept == null) {
|
|
|
+ errorMsg.append("产品不存在;");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (StrUtil.isBlank(errorMsg)) {
|
|
|
+ errorMap.put("idx", String.valueOf(i + 1));
|
|
|
+ errorMap.put("errorMsg", errorMsg.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return errorMap;
|
|
|
+ }
|
|
|
}
|