|
@@ -82,1493 +82,1732 @@ import java.util.stream.Collectors;
|
|
|
@AllArgsConstructor
|
|
|
public class SysImplementPlanManager {
|
|
|
|
|
|
- private final SysImplementPlanService implementPlanService;
|
|
|
- private final SysImplPlanDetailsService implPlanDetailsService;
|
|
|
- private final SysDeptService deptService;
|
|
|
- private final SysRoleService roleService;
|
|
|
- private final SysImplPlanDetailsItemService implPlanDetailsItemService;
|
|
|
- private final WmDaDrugEntDrugtableService drugEntDrugtableService;
|
|
|
- private final SysPlanPkgService planPkgService;
|
|
|
- private final WmScorePackageService scorePackageService;
|
|
|
- private final WmTaskTypeService taskTypeService;
|
|
|
- private final RedisTemplate<String, Object> redisTemplate;
|
|
|
- private final SysUserAreaService userAreaService;
|
|
|
- private final SysEnterpriseAreaService enterpriseAreaService;
|
|
|
-
|
|
|
- /**
|
|
|
- * 创建计划
|
|
|
- *
|
|
|
- * @param resource 计划信息
|
|
|
- * @param operator 操作人
|
|
|
- * @return 创建结果
|
|
|
- */
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public Boolean createPlan(SysImplementPlanDTO.OnCreate resource, HnqzUser operator) {
|
|
|
-
|
|
|
- boolean dupName = implementPlanService.dupName(resource.getPlanName(), operator.getDeptId(), Collections.emptyList());
|
|
|
-
|
|
|
- if (dupName) {
|
|
|
- throw new BizException(String.format("计划名称【%s】已存在,请更正", resource.getPlanName()));
|
|
|
- }
|
|
|
-
|
|
|
- String username = operator.getUsername();
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
- SysImplementPlan plan = BeanUtil.copyProperties(resource, SysImplementPlan.class);
|
|
|
- UpmsType.ImplementPlanType planType = resource.getPlanType();
|
|
|
-
|
|
|
- UpmsState.ImplementPlanState state;
|
|
|
- if (UpmsType.ImplementPlanType.QRT.equals(planType) && (resource.getParentId() == 0)) {
|
|
|
- state = UpmsState.ImplementPlanState.PASSED;
|
|
|
- plan.setCheckResult(true);
|
|
|
- plan.setCheckMessage("通过(审批流程,季度计划自动通过,不需要上级审批)");
|
|
|
- plan.setCheckTime(now);
|
|
|
- plan.setChecker(username);
|
|
|
- } else {
|
|
|
- state = UpmsState.ImplementPlanState.INIT;
|
|
|
- }
|
|
|
-
|
|
|
- plan.setPlanState(state);
|
|
|
- plan.setConsignorId(operator.getDeptId());
|
|
|
- plan.setCreateBy(username);
|
|
|
- plan.setUpdateBy(username);
|
|
|
- plan.setCreateTime(now);
|
|
|
- plan.setUpdateTime(now);
|
|
|
-
|
|
|
- if (resource.getParentId() != 0) {
|
|
|
-
|
|
|
- Long availScore = implementPlanService.calcAvailScore(resource.getParentId(), resource.getPlanScore());
|
|
|
- SysImplementPlan parentPlan = new SysImplementPlan();
|
|
|
- parentPlan.setPlanId(resource.getParentId());
|
|
|
- parentPlan.setAvailScore(availScore);
|
|
|
- parentPlan.setUpdateBy(username);
|
|
|
- parentPlan.setUpdateTime(now);
|
|
|
- implementPlanService.updatePlan(parentPlan);
|
|
|
- }
|
|
|
-
|
|
|
- plan.setAvailScore(resource.getPlanScore());
|
|
|
-
|
|
|
- implementPlanService.createPlan(plan);
|
|
|
-
|
|
|
- return Boolean.TRUE;
|
|
|
+ private final SysImplementPlanService implementPlanService;
|
|
|
+ private final SysImplPlanDetailsService implPlanDetailsService;
|
|
|
+ private final SysDeptService deptService;
|
|
|
+ private final SysRoleService roleService;
|
|
|
+ private final SysImplPlanDetailsItemService implPlanDetailsItemService;
|
|
|
+ private final WmDaDrugEntDrugtableService drugEntDrugtableService;
|
|
|
+ private final SysPlanPkgService planPkgService;
|
|
|
+ private final WmScorePackageService scorePackageService;
|
|
|
+ private final WmTaskTypeService taskTypeService;
|
|
|
+ private final RedisTemplate<String, Object> redisTemplate;
|
|
|
+ private final SysUserAreaService userAreaService;
|
|
|
+ private final SysEnterpriseAreaService enterpriseAreaService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建计划
|
|
|
+ *
|
|
|
+ * @param resource 计划信息
|
|
|
+ * @param operator 操作人
|
|
|
+ * @return 创建结果
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean createPlan(SysImplementPlanDTO.OnCreate resource, HnqzUser operator) {
|
|
|
+
|
|
|
+ boolean dupName =
|
|
|
+ implementPlanService.dupName(
|
|
|
+ resource.getPlanName(), operator.getDeptId(), Collections.emptyList());
|
|
|
+
|
|
|
+ if (dupName) {
|
|
|
+ throw new BizException(String.format("计划名称【%s】已存在,请更正", resource.getPlanName()));
|
|
|
}
|
|
|
|
|
|
+ String username = operator.getUsername();
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ SysImplementPlan plan = BeanUtil.copyProperties(resource, SysImplementPlan.class);
|
|
|
+ UpmsType.ImplementPlanType planType = resource.getPlanType();
|
|
|
+
|
|
|
+ UpmsState.ImplementPlanState state;
|
|
|
+ if (UpmsType.ImplementPlanType.QRT.equals(planType) && (resource.getParentId() == 0)) {
|
|
|
+ state = UpmsState.ImplementPlanState.PASSED;
|
|
|
+ plan.setCheckResult(true);
|
|
|
+ plan.setCheckMessage("通过(审批流程,季度计划自动通过,不需要上级审批)");
|
|
|
+ plan.setCheckTime(now);
|
|
|
+ plan.setChecker(username);
|
|
|
+ } else {
|
|
|
+ state = UpmsState.ImplementPlanState.INIT;
|
|
|
+ }
|
|
|
|
|
|
- private Page<SysImplementPlan> toBasePage(int entLevel, SysImplementPlanDTO.OnPage query, HnqzUser operator) {
|
|
|
-
|
|
|
+ plan.setPlanState(state);
|
|
|
+ plan.setConsignorId(operator.getDeptId());
|
|
|
+ plan.setCreateBy(username);
|
|
|
+ plan.setUpdateBy(username);
|
|
|
+ plan.setCreateTime(now);
|
|
|
+ plan.setUpdateTime(now);
|
|
|
+
|
|
|
+ if (resource.getParentId() != 0) {
|
|
|
+
|
|
|
+ Long availScore =
|
|
|
+ implementPlanService.calcAvailScore(resource.getParentId(), resource.getPlanScore());
|
|
|
+ SysImplementPlan parentPlan = new SysImplementPlan();
|
|
|
+ parentPlan.setPlanId(resource.getParentId());
|
|
|
+ parentPlan.setAvailScore(availScore);
|
|
|
+ parentPlan.setUpdateBy(username);
|
|
|
+ parentPlan.setUpdateTime(now);
|
|
|
+ implementPlanService.updatePlan(parentPlan);
|
|
|
+ }
|
|
|
|
|
|
- // 获取根目录分页
|
|
|
- Page<SysImplementPlan> page = this.getPage(operator, entLevel, query.getCurrent(), query.getSize(), query.getPlanName(),
|
|
|
- query.getConsigneeId(), operator.getDeptId(), query.getActionState(), query.getPlanType(), query.getPeriod(), query.getCreateTime());
|
|
|
+ plan.setAvailScore(resource.getPlanScore());
|
|
|
|
|
|
- List<SysImplementPlan> records = page.getRecords();
|
|
|
+ implementPlanService.createPlan(plan);
|
|
|
|
|
|
- if (CollUtil.isEmpty(records)) {
|
|
|
- return page;
|
|
|
- }
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
|
|
|
- // 查询出子数据
|
|
|
- Set<Integer> pIds = records.stream().map(SysImplementPlan::getPlanId).collect(Collectors.toSet());
|
|
|
+ private Page<SysImplementPlan> toBasePage(
|
|
|
+ int entLevel, SysImplementPlanDTO.OnPage query, HnqzUser operator) {
|
|
|
|
|
|
- // 区域的预算
|
|
|
- if (CollUtil.isNotEmpty(pIds)) {
|
|
|
- List<SysImplementPlan> subPlans = implementPlanService.list(Wrappers.<SysImplementPlan>lambdaQuery().in(SysImplementPlan::getParentId, pIds));
|
|
|
+ // 获取根目录分页
|
|
|
+ Page<SysImplementPlan> page =
|
|
|
+ this.getPage(
|
|
|
+ operator,
|
|
|
+ entLevel,
|
|
|
+ query.getCurrent(),
|
|
|
+ query.getSize(),
|
|
|
+ query.getPlanName(),
|
|
|
+ query.getConsigneeId(),
|
|
|
+ operator.getDeptId(),
|
|
|
+ query.getActionState(),
|
|
|
+ query.getPlanType(),
|
|
|
+ query.getPeriod(),
|
|
|
+ query.getCreateTime());
|
|
|
|
|
|
- if (CollUtil.isNotEmpty(subPlans)) {
|
|
|
- records.addAll(subPlans);
|
|
|
+ List<SysImplementPlan> records = page.getRecords();
|
|
|
|
|
|
- // 服务商的预算
|
|
|
- Set<Integer> finalSubPlanIds = subPlans.stream().mapToInt(SysImplementPlan::getParentId).boxed().collect(Collectors.toSet());
|
|
|
+ if (CollUtil.isEmpty(records)) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
|
|
|
- if (CollUtil.isNotEmpty(finalSubPlanIds)) {
|
|
|
- List<SysImplementPlan> finalSubPlans = implementPlanService.list(Wrappers.<SysImplementPlan>lambdaQuery().in(SysImplementPlan::getParentId, finalSubPlanIds));
|
|
|
- records.addAll(finalSubPlans);
|
|
|
- }
|
|
|
- }
|
|
|
+ // 查询出子数据
|
|
|
+ Set<Integer> pIds =
|
|
|
+ records.stream().map(SysImplementPlan::getPlanId).collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 区域的预算
|
|
|
+ if (CollUtil.isNotEmpty(pIds)) {
|
|
|
+ List<SysImplementPlan> subPlans =
|
|
|
+ implementPlanService.list(
|
|
|
+ Wrappers.<SysImplementPlan>lambdaQuery().in(SysImplementPlan::getParentId, pIds));
|
|
|
+
|
|
|
+ if (CollUtil.isNotEmpty(subPlans)) {
|
|
|
+ records.addAll(subPlans);
|
|
|
+
|
|
|
+ // 服务商的预算
|
|
|
+ Set<Integer> finalSubPlanIds =
|
|
|
+ subPlans.stream()
|
|
|
+ .mapToInt(SysImplementPlan::getParentId)
|
|
|
+ .boxed()
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ if (CollUtil.isNotEmpty(finalSubPlanIds)) {
|
|
|
+ List<SysImplementPlan> finalSubPlans =
|
|
|
+ implementPlanService.list(
|
|
|
+ Wrappers.<SysImplementPlan>lambdaQuery()
|
|
|
+ .in(SysImplementPlan::getParentId, finalSubPlanIds));
|
|
|
+ records.addAll(finalSubPlans);
|
|
|
}
|
|
|
-
|
|
|
- return page;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private List<TreeNode<Integer>> toTreeNode(List<SysImplementPlan> records) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
|
|
|
- // 获取承接人ID
|
|
|
- Set<Integer> consigneeIds = records.stream().mapToInt(SysImplementPlan::getConsigneeId).boxed().collect(Collectors.toSet());
|
|
|
+ private List<TreeNode<Integer>> toTreeNode(List<SysImplementPlan> records) {
|
|
|
|
|
|
- // 获取承接人
|
|
|
- Map<Integer, SysDept> consigneeMap = deptService.mapConsignee(consigneeIds, true);
|
|
|
+ // 获取承接人ID
|
|
|
+ Set<Integer> consigneeIds =
|
|
|
+ records.stream()
|
|
|
+ .mapToInt(SysImplementPlan::getConsigneeId)
|
|
|
+ .boxed()
|
|
|
+ .collect(Collectors.toSet());
|
|
|
|
|
|
- // 获取商品信息
|
|
|
+ // 获取承接人
|
|
|
+ Map<Integer, SysDept> consigneeMap = deptService.mapConsignee(consigneeIds, true);
|
|
|
|
|
|
- Set<Integer> skuIds = records.stream().map(SysImplementPlan::getSkuId).collect(Collectors.toSet());
|
|
|
- List<Map<String, String>> skuList = drugEntDrugtableService.listDrugs(skuIds);
|
|
|
- Map<Integer, Map<String, String>> skuMap = skuList.stream().collect(Collectors.toMap(sku -> Integer.valueOf(sku.get("drug_id")), Function.identity()));
|
|
|
+ // 获取商品信息
|
|
|
|
|
|
+ Set<Integer> skuIds =
|
|
|
+ records.stream().map(SysImplementPlan::getSkuId).collect(Collectors.toSet());
|
|
|
+ List<Map<String, String>> skuList = drugEntDrugtableService.listDrugs(skuIds);
|
|
|
+ Map<Integer, Map<String, String>> skuMap =
|
|
|
+ skuList.stream()
|
|
|
+ .collect(
|
|
|
+ Collectors.toMap(sku -> Integer.valueOf(sku.get("drug_id")), Function.identity()));
|
|
|
|
|
|
- // 封装返回结果
|
|
|
- return getToPages(records, consigneeMap, skuMap);
|
|
|
- }
|
|
|
+ // 封装返回结果
|
|
|
+ return getToPages(records, consigneeMap, skuMap);
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取计划分页
|
|
|
+ *
|
|
|
+ * @param query 查询条件
|
|
|
+ * @param operator 操作人
|
|
|
+ * @return 分页结果
|
|
|
+ */
|
|
|
+ public Page<?> pagePlans(SysImplementPlanDTO.OnPage query, HnqzUser operator) {
|
|
|
|
|
|
- /**
|
|
|
- * 获取计划分页
|
|
|
- *
|
|
|
- * @param query 查询条件
|
|
|
- * @param operator 操作人
|
|
|
- * @return 分页结果
|
|
|
- */
|
|
|
- public Page<?> pagePlans(SysImplementPlanDTO.OnPage query, HnqzUser operator) {
|
|
|
+ int entLevel = roleService.getEntLevel();
|
|
|
|
|
|
- int entLevel = roleService.getEntLevel();
|
|
|
+ Page<SysImplementPlan> page = toBasePage(entLevel, query, operator);
|
|
|
|
|
|
- Page<SysImplementPlan> page = toBasePage(entLevel, query, operator);
|
|
|
-
|
|
|
- List<SysImplementPlan> records = page.getRecords();
|
|
|
- if (CollUtil.isEmpty(records)) {
|
|
|
- return page;
|
|
|
- }
|
|
|
- List<TreeNode<Integer>> toPages = toTreeNode(records);
|
|
|
-
|
|
|
- // 封装返回结果
|
|
|
- Page<Tree<Integer>> newPage = new Page<>(page.getCurrent(), page.getSize(), page.getTotal());
|
|
|
- List<Tree<Integer>> builds = new ArrayList<>();
|
|
|
- // 事业部 || 区域 || 平台
|
|
|
- if (entLevel == 0 || entLevel == 1 || entLevel == -1) {
|
|
|
-
|
|
|
- if (UpmsState.ImplementPlanActionState.AWAIT_2_OM.equals(query.getActionState())) {
|
|
|
- for (TreeNode<Integer> node : toPages) {
|
|
|
- List<Tree<Integer>> build = TreeUtil.build(Collections.singletonList(node), node.getParentId());
|
|
|
- builds.addAll(build);
|
|
|
- }
|
|
|
- } else {
|
|
|
- List<Tree<Integer>> build = TreeUtil.build(toPages, 0);
|
|
|
- builds.addAll(build);
|
|
|
- }
|
|
|
- }
|
|
|
- // 服务商
|
|
|
- else {
|
|
|
-
|
|
|
- for (TreeNode<Integer> node : toPages) {
|
|
|
- List<Tree<Integer>> build = TreeUtil.build(Collections.singletonList(node), node.getParentId());
|
|
|
- builds.addAll(build);
|
|
|
- }
|
|
|
+ List<SysImplementPlan> records = page.getRecords();
|
|
|
+ if (CollUtil.isEmpty(records)) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+ List<TreeNode<Integer>> toPages = toTreeNode(records);
|
|
|
+
|
|
|
+ // 封装返回结果
|
|
|
+ Page<Tree<Integer>> newPage = new Page<>(page.getCurrent(), page.getSize(), page.getTotal());
|
|
|
+ List<Tree<Integer>> builds = new ArrayList<>();
|
|
|
+ // 事业部 || 区域 || 平台
|
|
|
+ if (entLevel == 0 || entLevel == 1 || entLevel == -1) {
|
|
|
+
|
|
|
+ if (UpmsState.ImplementPlanActionState.AWAIT_2_OM.equals(query.getActionState())) {
|
|
|
+ for (TreeNode<Integer> node : toPages) {
|
|
|
+ List<Tree<Integer>> build =
|
|
|
+ TreeUtil.build(Collections.singletonList(node), node.getParentId());
|
|
|
+ builds.addAll(build);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- newPage.setRecords(builds);
|
|
|
-
|
|
|
- return newPage;
|
|
|
+ } else {
|
|
|
+ List<Tree<Integer>> build = TreeUtil.build(toPages, 0);
|
|
|
+ builds.addAll(build);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 服务商
|
|
|
+ else {
|
|
|
+
|
|
|
+ for (TreeNode<Integer> node : toPages) {
|
|
|
+ List<Tree<Integer>> build =
|
|
|
+ TreeUtil.build(Collections.singletonList(node), node.getParentId());
|
|
|
+ builds.addAll(build);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private List<TreeNode<Integer>> getToPages(List<SysImplementPlan> records, Map<Integer, SysDept> consigneeMap, Map<Integer, Map<String, String>> skuMap) {
|
|
|
-
|
|
|
- Map<Integer, SysImplementPlan> planId2PlanMap = records.stream().collect(Collectors.toMap(SysImplementPlan::getPlanId, Function.identity(), (v1, v2) -> v1));
|
|
|
-
|
|
|
- return records.stream().map(record -> {
|
|
|
- SysImplementPlanVO.ToPage p = BeanUtil.copyProperties(record, SysImplementPlanVO.ToPage.class);
|
|
|
-
|
|
|
- // 设置承接人信息
|
|
|
- Map<String, Object> consigneeInfo = new HashMap<>(3);
|
|
|
- consigneeInfo.put("consigneeId", record.getConsigneeId());
|
|
|
- SysDept sysDept = consigneeMap.get(record.getConsigneeId());
|
|
|
- consigneeInfo.put("consigneeName", sysDept == null ? "" : sysDept.getName());
|
|
|
- p.setConsigneeInfo(consigneeInfo);
|
|
|
-
|
|
|
- // 执行包总值
|
|
|
- Set<String> pkgIds = planPkgService.list(Wrappers.<SysPlanPkg>lambdaQuery().eq(SysPlanPkg::getPlanId, record.getPlanId())).stream().map(rel -> rel.getPkgId().toString()).collect(Collectors.toSet());
|
|
|
- long execScoreVal = 0L;
|
|
|
- if (CollUtil.isNotEmpty(pkgIds)) {
|
|
|
- List<WmScorePackage> packages = scorePackageService.list(Wrappers.<WmScorePackage>lambdaQuery().in(WmScorePackage::getId, pkgIds));
|
|
|
+ newPage.setRecords(builds);
|
|
|
+
|
|
|
+ return newPage;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<TreeNode<Integer>> getToPages(
|
|
|
+ List<SysImplementPlan> records,
|
|
|
+ Map<Integer, SysDept> consigneeMap,
|
|
|
+ Map<Integer, Map<String, String>> skuMap) {
|
|
|
+
|
|
|
+ Map<Integer, SysImplementPlan> planId2PlanMap =
|
|
|
+ records.stream()
|
|
|
+ .collect(
|
|
|
+ Collectors.toMap(SysImplementPlan::getPlanId, Function.identity(), (v1, v2) -> v1));
|
|
|
+
|
|
|
+ return records.stream()
|
|
|
+ .map(
|
|
|
+ record -> {
|
|
|
+ SysImplementPlanVO.ToPage p =
|
|
|
+ BeanUtil.copyProperties(record, SysImplementPlanVO.ToPage.class);
|
|
|
+
|
|
|
+ // 设置承接人信息
|
|
|
+ Map<String, Object> consigneeInfo = new HashMap<>(3);
|
|
|
+ consigneeInfo.put("consigneeId", record.getConsigneeId());
|
|
|
+ SysDept sysDept = consigneeMap.get(record.getConsigneeId());
|
|
|
+ consigneeInfo.put("consigneeName", sysDept == null ? "" : sysDept.getName());
|
|
|
+ p.setConsigneeInfo(consigneeInfo);
|
|
|
+
|
|
|
+ // 执行包总值
|
|
|
+ Set<String> pkgIds =
|
|
|
+ planPkgService
|
|
|
+ .list(
|
|
|
+ Wrappers.<SysPlanPkg>lambdaQuery()
|
|
|
+ .eq(SysPlanPkg::getPlanId, record.getPlanId()))
|
|
|
+ .stream()
|
|
|
+ .map(rel -> rel.getPkgId().toString())
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ long execScoreVal = 0L;
|
|
|
+ if (CollUtil.isNotEmpty(pkgIds)) {
|
|
|
+ List<WmScorePackage> packages =
|
|
|
+ scorePackageService.list(
|
|
|
+ Wrappers.<WmScorePackage>lambdaQuery().in(WmScorePackage::getId, pkgIds));
|
|
|
if (CollUtil.isNotEmpty(packages)) {
|
|
|
- execScoreVal = packages.stream().mapToLong(WmScorePackage::getScore).sum();
|
|
|
+ execScoreVal = packages.stream().mapToLong(WmScorePackage::getScore).sum();
|
|
|
}
|
|
|
-
|
|
|
- }
|
|
|
- p.setExecScoreValue(execScoreVal);
|
|
|
-
|
|
|
- // 产品信息
|
|
|
- Map<String, String> sku = skuMap.get(record.getSkuId());
|
|
|
- Map<String, Object> skuInfo = new HashMap<>(3);
|
|
|
- skuInfo.put("skuId", record.getSkuId());
|
|
|
- skuInfo.put("skuName", MapUtil.isEmpty(sku) ? "" : sku.get("drug_name"));
|
|
|
- skuInfo.put("manufacturer", MapUtil.isEmpty(sku) ? "" : sku.get("ent_name"));
|
|
|
- p.setSkuInfo(skuInfo);
|
|
|
-
|
|
|
- // 获取计划详情
|
|
|
- List<SysImplPlanDetails> details = implPlanDetailsService.list(Wrappers.<SysImplPlanDetails>lambdaQuery()
|
|
|
- .eq(SysImplPlanDetails::getPlanId, record.getPlanId())
|
|
|
- .orderByDesc(SysImplPlanDetails::getUpdateTime)
|
|
|
- );
|
|
|
- p.setPlanDetails(CollUtil.isEmpty(details) ? null : details.get(0));
|
|
|
-
|
|
|
- TreeNode<Integer> treeNode = new TreeNode<>();
|
|
|
- treeNode.setId(p.getPlanId());
|
|
|
- treeNode.setParentId(p.getParentId());
|
|
|
- treeNode.setName(p.getPlanName());
|
|
|
- treeNode.setWeight(p.getPlanId());
|
|
|
- Map<String, Object> extra = BeanUtil.beanToMap(p);
|
|
|
- // 获取当前包的父级包
|
|
|
- Integer parentId = record.getParentId();
|
|
|
-
|
|
|
- long parentPlanScore;
|
|
|
- long parentPlanAvailScore;
|
|
|
- if (parentId == 0) {
|
|
|
+ }
|
|
|
+ p.setExecScoreValue(execScoreVal);
|
|
|
+
|
|
|
+ // 产品信息
|
|
|
+ Map<String, String> sku = skuMap.get(record.getSkuId());
|
|
|
+ Map<String, Object> skuInfo = new HashMap<>(3);
|
|
|
+ skuInfo.put("skuId", record.getSkuId());
|
|
|
+ skuInfo.put("skuName", MapUtil.isEmpty(sku) ? "" : sku.get("drug_name"));
|
|
|
+ skuInfo.put("manufacturer", MapUtil.isEmpty(sku) ? "" : sku.get("ent_name"));
|
|
|
+ p.setSkuInfo(skuInfo);
|
|
|
+
|
|
|
+ // 获取计划详情
|
|
|
+ List<SysImplPlanDetails> details =
|
|
|
+ implPlanDetailsService.list(
|
|
|
+ Wrappers.<SysImplPlanDetails>lambdaQuery()
|
|
|
+ .eq(SysImplPlanDetails::getPlanId, record.getPlanId())
|
|
|
+ .orderByDesc(SysImplPlanDetails::getUpdateTime));
|
|
|
+ p.setPlanDetails(CollUtil.isEmpty(details) ? null : details.get(0));
|
|
|
+
|
|
|
+ TreeNode<Integer> treeNode = new TreeNode<>();
|
|
|
+ treeNode.setId(p.getPlanId());
|
|
|
+ treeNode.setParentId(p.getParentId());
|
|
|
+ treeNode.setName(p.getPlanName());
|
|
|
+ treeNode.setWeight(p.getPlanId());
|
|
|
+ Map<String, Object> extra = BeanUtil.beanToMap(p);
|
|
|
+ // 获取当前包的父级包
|
|
|
+ Integer parentId = record.getParentId();
|
|
|
+
|
|
|
+ long parentPlanScore;
|
|
|
+ long parentPlanAvailScore;
|
|
|
+ if (parentId == 0) {
|
|
|
parentPlanScore = record.getPlanScore();
|
|
|
parentPlanAvailScore = record.getAvailScore();
|
|
|
- } else {
|
|
|
+ } else {
|
|
|
SysImplementPlan plan = planId2PlanMap.get(record.getParentId());
|
|
|
if (plan == null) {
|
|
|
- parentPlanScore = 0L;
|
|
|
- parentPlanAvailScore = 0L;
|
|
|
+ parentPlanScore = 0L;
|
|
|
+ parentPlanAvailScore = 0L;
|
|
|
} else {
|
|
|
- parentPlanScore = plan.getPlanScore();
|
|
|
- parentPlanAvailScore = plan.getAvailScore();
|
|
|
+ parentPlanScore = plan.getPlanScore();
|
|
|
+ parentPlanAvailScore = plan.getAvailScore();
|
|
|
}
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- extra.put("parentPlanScore", parentPlanScore);
|
|
|
- extra.put("parentPlanAvailScore", parentPlanAvailScore);
|
|
|
- treeNode.setExtra(extra);
|
|
|
-
|
|
|
- return treeNode;
|
|
|
- }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ extra.put("parentPlanScore", parentPlanScore);
|
|
|
+ extra.put("parentPlanAvailScore", parentPlanAvailScore);
|
|
|
+ treeNode.setExtra(extra);
|
|
|
+
|
|
|
+ return treeNode;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ private Page<SysImplementPlan> getPage(
|
|
|
+ HnqzUser user,
|
|
|
+ int entLevel,
|
|
|
+ Integer current,
|
|
|
+ Integer size,
|
|
|
+ String planName,
|
|
|
+ Integer consigneeId,
|
|
|
+ Integer consignorId,
|
|
|
+ UpmsState.ImplementPlanActionState actionState,
|
|
|
+ UpmsType.ImplementPlanType planType,
|
|
|
+ LocalDate[] period,
|
|
|
+ LocalDateTime[] createTime) {
|
|
|
+
|
|
|
+ LambdaQueryWrapper<SysImplementPlan> wrapper =
|
|
|
+ Wrappers.<SysImplementPlan>lambdaQuery()
|
|
|
+ // .eq(Objects.nonNull(consigneeId), SysImplementPlan::getConsigneeId,
|
|
|
+ // consigneeId)
|
|
|
+ // .eq(Objects.nonNull(consignorId), SysImplementPlan::getConsignorId,
|
|
|
+ // consignorId)
|
|
|
+ .eq(Objects.nonNull(planType), SysImplementPlan::getPlanType, planType)
|
|
|
+ // .eq(Objects.nonNull(planState), SysImplementPlan::getPlanState, planState)
|
|
|
+ .like(StrUtil.isNotBlank(planName), SysImplementPlan::getPlanName, planName);
|
|
|
+
|
|
|
+ // 服务商管理员(只查询发给我的)
|
|
|
+ if (entLevel == 2) {
|
|
|
+ wrapper
|
|
|
+ .eq(SysImplementPlan::getPlanState, UpmsState.ImplementPlanState.PASSED)
|
|
|
+ .eq(SysImplementPlan::getConsigneeId, user.getDeptId());
|
|
|
}
|
|
|
-
|
|
|
- private Page<SysImplementPlan> getPage(HnqzUser user,
|
|
|
- int entLevel,
|
|
|
- Integer current,
|
|
|
- Integer size,
|
|
|
- String planName,
|
|
|
- Integer consigneeId,
|
|
|
- Integer consignorId,
|
|
|
- UpmsState.ImplementPlanActionState actionState,
|
|
|
- UpmsType.ImplementPlanType planType,
|
|
|
- LocalDate[] period,
|
|
|
- LocalDateTime[] createTime) {
|
|
|
-
|
|
|
-
|
|
|
- LambdaQueryWrapper<SysImplementPlan> wrapper = Wrappers.<SysImplementPlan>lambdaQuery()
|
|
|
-// .eq(Objects.nonNull(consigneeId), SysImplementPlan::getConsigneeId, consigneeId)
|
|
|
-// .eq(Objects.nonNull(consignorId), SysImplementPlan::getConsignorId, consignorId)
|
|
|
- .eq(Objects.nonNull(planType), SysImplementPlan::getPlanType, planType)
|
|
|
- // .eq(Objects.nonNull(planState), SysImplementPlan::getPlanState, planState)
|
|
|
- .like(StrUtil.isNotBlank(planName), SysImplementPlan::getPlanName, planName);
|
|
|
-
|
|
|
- // 服务商管理员(只查询发给我的)
|
|
|
- if (entLevel == 2) {
|
|
|
- wrapper.eq(SysImplementPlan::getPlanState, UpmsState.ImplementPlanState.PASSED)
|
|
|
- .eq(SysImplementPlan::getConsigneeId, user.getDeptId());
|
|
|
- }
|
|
|
- // 区域 (查询发给我的和我下发的)
|
|
|
- else if (entLevel == 1) {
|
|
|
- // 查询发给我的
|
|
|
- wrapper.eq(Objects.nonNull(consignorId), SysImplementPlan::getConsigneeId, consignorId);
|
|
|
- wrapper.eq(SysImplementPlan::getPlanState, UpmsState.ImplementPlanState.PASSED)
|
|
|
- .and(wrp -> wrp.eq(SysImplementPlan::getConsigneeId, user.getDeptId()).or().eq(SysImplementPlan::getConsignorId, user.getDeptId()));
|
|
|
- }
|
|
|
- // 事业部管理员||药企(只查询我下发的)
|
|
|
- else if (entLevel == -1) {
|
|
|
-
|
|
|
- Set<Long> visibleEntIds = new HashSet<>();
|
|
|
- // 订单查询
|
|
|
- if (Objects.nonNull(consigneeId)) {
|
|
|
- visibleEntIds.add(Long.valueOf(consigneeId));
|
|
|
- }
|
|
|
- // 先定区域内的信息
|
|
|
- else {
|
|
|
- List<Long> entIds = listVisibleEntIds(user);
|
|
|
- visibleEntIds.addAll(entIds);
|
|
|
- }
|
|
|
-
|
|
|
- // wrapper.eq(SysImplementPlan::getConsignorId, user.getDeptId())
|
|
|
- // .in(CollUtil.isNotEmpty(visibleEntIds), SysImplementPlan::getConsigneeId, visibleEntIds)
|
|
|
- // // .eq(Objects.nonNull(consigneeId), SysImplementPlan::getConsigneeId, consigneeId)
|
|
|
- // .eq(SysImplementPlan::getParentId, 0);
|
|
|
-
|
|
|
-
|
|
|
- // 拼装状态
|
|
|
- if (Objects.nonNull(actionState)) {
|
|
|
- switch (actionState) {
|
|
|
- case AWAIT_2_LEADER:
|
|
|
- wrapper.eq(SysImplementPlan::getConsignorId, user.getDeptId())
|
|
|
- .in(CollUtil.isNotEmpty(visibleEntIds), SysImplementPlan::getConsigneeId, visibleEntIds)
|
|
|
- .eq(SysImplementPlan::getParentId, 0)
|
|
|
- .eq(SysImplementPlan::getPlanState, UpmsState.ImplementPlanState.INIT);
|
|
|
- break;
|
|
|
- case AWAIT_2_OM:
|
|
|
- wrapper.in(SysImplementPlan::getConsignorId, visibleEntIds)
|
|
|
- .eq(SysImplementPlan::getPlanState, UpmsState.ImplementPlanState.INIT)
|
|
|
- .ne(SysImplementPlan::getParentId, 0);
|
|
|
- break;
|
|
|
- case PASSED_AND_GO:
|
|
|
- wrapper.eq(SysImplementPlan::getConsignorId, user.getDeptId())
|
|
|
- .in(CollUtil.isNotEmpty(visibleEntIds), SysImplementPlan::getConsigneeId, visibleEntIds)
|
|
|
- .eq(SysImplementPlan::getParentId, 0)
|
|
|
- .eq(SysImplementPlan::getPlanState, UpmsState.ImplementPlanState.PASSED)
|
|
|
- .apply("plan_score != avail_score");
|
|
|
- break;
|
|
|
- case PASSED_TO_GO:
|
|
|
- wrapper.eq(SysImplementPlan::getConsignorId, user.getDeptId())
|
|
|
- .in(CollUtil.isNotEmpty(visibleEntIds), SysImplementPlan::getConsigneeId, visibleEntIds)
|
|
|
- .eq(SysImplementPlan::getParentId, 0)
|
|
|
- .eq(SysImplementPlan::getPlanState, UpmsState.ImplementPlanState.PASSED)
|
|
|
- .apply("plan_score = avail_score");
|
|
|
- break;
|
|
|
- case REJECTED:
|
|
|
- wrapper.eq(SysImplementPlan::getConsignorId, user.getDeptId())
|
|
|
- .in(CollUtil.isNotEmpty(visibleEntIds), SysImplementPlan::getConsigneeId, visibleEntIds)
|
|
|
- .eq(SysImplementPlan::getParentId, 0)
|
|
|
- .eq(SysImplementPlan::getPlanState, UpmsState.ImplementPlanState.REJECTED);
|
|
|
- break;
|
|
|
- case IN_PROGRESS:
|
|
|
- wrapper.eq(SysImplementPlan::getConsignorId, user.getDeptId())
|
|
|
- .in(CollUtil.isNotEmpty(visibleEntIds), SysImplementPlan::getConsigneeId, visibleEntIds)
|
|
|
- .eq(SysImplementPlan::getParentId, 0)
|
|
|
- .eq(SysImplementPlan::getPlanState, UpmsState.ImplementPlanState.IN_PROGRESS);
|
|
|
- break;
|
|
|
- }
|
|
|
- } else {
|
|
|
- wrapper.eq(SysImplementPlan::getConsignorId, user.getDeptId())
|
|
|
- .in(CollUtil.isNotEmpty(visibleEntIds), SysImplementPlan::getConsigneeId, visibleEntIds)
|
|
|
- // .eq(Objects.nonNull(consigneeId), SysImplementPlan::getConsigneeId, consigneeId)
|
|
|
- .eq(SysImplementPlan::getParentId, 0);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- // 平台||营销中心(查询全部)
|
|
|
- else {
|
|
|
-
|
|
|
- List<Long> ignored = new LinkedList<>();
|
|
|
- ignored.add(-1019330L);
|
|
|
- ignored.add(-1019986L);
|
|
|
- ignored.add(1716964676L);
|
|
|
- ignored.add(1716953432L);
|
|
|
- ignored.add(-1020826L);
|
|
|
- ignored.add(-1026289L);
|
|
|
- ignored.add(-1026537L);
|
|
|
-
|
|
|
- Integer userId = user.getId();
|
|
|
- boolean ignoredFlag = (userId == 7959 || userId == 7602 || userId == 7414 || userId == 7415);
|
|
|
- wrapper.eq(SysImplementPlan::getParentId, 0)
|
|
|
- .notIn(ignoredFlag, SysImplementPlan::getConsignorId, ignored);
|
|
|
- // .notIn(ignoredFlag, SysImplementPlan::getConsigneeId, ignored);
|
|
|
- }
|
|
|
-
|
|
|
- if (ArrayUtil.isNotEmpty(period) && period.length == 2) {
|
|
|
- wrapper.ge(SysImplementPlan::getPlanIssue, period[0]);
|
|
|
- wrapper.le(SysImplementPlan::getPlanExpiry, period[1].plusMonths(1).minusDays(1));
|
|
|
- }
|
|
|
-
|
|
|
- if (ArrayUtil.isNotEmpty(createTime) && createTime.length == 2) {
|
|
|
- wrapper.between(SysImplementPlan::getCreateTime, createTime[0], createTime[1].plusMonths(1).minusSeconds(1));
|
|
|
+ // 区域 (查询发给我的和我下发的)
|
|
|
+ else if (entLevel == 1) {
|
|
|
+ // 查询发给我的
|
|
|
+ wrapper.eq(Objects.nonNull(consignorId), SysImplementPlan::getConsigneeId, consignorId);
|
|
|
+ wrapper
|
|
|
+ .eq(SysImplementPlan::getPlanState, UpmsState.ImplementPlanState.PASSED)
|
|
|
+ .and(
|
|
|
+ wrp ->
|
|
|
+ wrp.eq(SysImplementPlan::getConsigneeId, user.getDeptId())
|
|
|
+ .or()
|
|
|
+ .eq(SysImplementPlan::getConsignorId, user.getDeptId()));
|
|
|
+ }
|
|
|
+ // 事业部管理员||药企(只查询我下发的)
|
|
|
+ else if (entLevel == -1) {
|
|
|
+
|
|
|
+ Set<Long> visibleEntIds = new HashSet<>();
|
|
|
+ // 订单查询
|
|
|
+ if (Objects.nonNull(consigneeId)) {
|
|
|
+ visibleEntIds.add(Long.valueOf(consigneeId));
|
|
|
+ }
|
|
|
+ // 先定区域内的信息
|
|
|
+ else {
|
|
|
+ List<Long> entIds = listVisibleEntIds(user);
|
|
|
+ visibleEntIds.addAll(entIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ // wrapper.eq(SysImplementPlan::getConsignorId, user.getDeptId())
|
|
|
+ // .in(CollUtil.isNotEmpty(visibleEntIds), SysImplementPlan::getConsigneeId,
|
|
|
+ // visibleEntIds)
|
|
|
+ // // .eq(Objects.nonNull(consigneeId), SysImplementPlan::getConsigneeId, consigneeId)
|
|
|
+ // .eq(SysImplementPlan::getParentId, 0);
|
|
|
+
|
|
|
+ // 拼装状态
|
|
|
+ if (Objects.nonNull(actionState)) {
|
|
|
+ switch (actionState) {
|
|
|
+ case AWAIT_2_LEADER:
|
|
|
+ wrapper
|
|
|
+ .eq(SysImplementPlan::getConsignorId, user.getDeptId())
|
|
|
+ .in(
|
|
|
+ CollUtil.isNotEmpty(visibleEntIds),
|
|
|
+ SysImplementPlan::getConsigneeId,
|
|
|
+ visibleEntIds)
|
|
|
+ .eq(SysImplementPlan::getParentId, 0)
|
|
|
+ .eq(SysImplementPlan::getPlanState, UpmsState.ImplementPlanState.INIT);
|
|
|
+ break;
|
|
|
+ case AWAIT_2_OM:
|
|
|
+ wrapper
|
|
|
+ .in(SysImplementPlan::getConsignorId, visibleEntIds)
|
|
|
+ .eq(SysImplementPlan::getPlanState, UpmsState.ImplementPlanState.INIT)
|
|
|
+ .ne(SysImplementPlan::getParentId, 0);
|
|
|
+ break;
|
|
|
+ case PASSED_AND_GO:
|
|
|
+ wrapper
|
|
|
+ .eq(SysImplementPlan::getConsignorId, user.getDeptId())
|
|
|
+ .in(
|
|
|
+ CollUtil.isNotEmpty(visibleEntIds),
|
|
|
+ SysImplementPlan::getConsigneeId,
|
|
|
+ visibleEntIds)
|
|
|
+ .eq(SysImplementPlan::getParentId, 0)
|
|
|
+ .eq(SysImplementPlan::getPlanState, UpmsState.ImplementPlanState.PASSED)
|
|
|
+ .apply("plan_score != avail_score");
|
|
|
+ break;
|
|
|
+ case PASSED_TO_GO:
|
|
|
+ wrapper
|
|
|
+ .eq(SysImplementPlan::getConsignorId, user.getDeptId())
|
|
|
+ .in(
|
|
|
+ CollUtil.isNotEmpty(visibleEntIds),
|
|
|
+ SysImplementPlan::getConsigneeId,
|
|
|
+ visibleEntIds)
|
|
|
+ .eq(SysImplementPlan::getParentId, 0)
|
|
|
+ .eq(SysImplementPlan::getPlanState, UpmsState.ImplementPlanState.PASSED)
|
|
|
+ .apply("plan_score = avail_score");
|
|
|
+ break;
|
|
|
+ case REJECTED:
|
|
|
+ wrapper
|
|
|
+ .eq(SysImplementPlan::getConsignorId, user.getDeptId())
|
|
|
+ .in(
|
|
|
+ CollUtil.isNotEmpty(visibleEntIds),
|
|
|
+ SysImplementPlan::getConsigneeId,
|
|
|
+ visibleEntIds)
|
|
|
+ .eq(SysImplementPlan::getParentId, 0)
|
|
|
+ .eq(SysImplementPlan::getPlanState, UpmsState.ImplementPlanState.REJECTED);
|
|
|
+ break;
|
|
|
+ case IN_PROGRESS:
|
|
|
+ wrapper
|
|
|
+ .eq(SysImplementPlan::getConsignorId, user.getDeptId())
|
|
|
+ .in(
|
|
|
+ CollUtil.isNotEmpty(visibleEntIds),
|
|
|
+ SysImplementPlan::getConsigneeId,
|
|
|
+ visibleEntIds)
|
|
|
+ .eq(SysImplementPlan::getParentId, 0)
|
|
|
+ .eq(SysImplementPlan::getPlanState, UpmsState.ImplementPlanState.IN_PROGRESS);
|
|
|
+ break;
|
|
|
}
|
|
|
+ } else {
|
|
|
+ wrapper
|
|
|
+ .eq(SysImplementPlan::getConsignorId, user.getDeptId())
|
|
|
+ .in(CollUtil.isNotEmpty(visibleEntIds), SysImplementPlan::getConsigneeId, visibleEntIds)
|
|
|
+ // .eq(Objects.nonNull(consigneeId), SysImplementPlan::getConsigneeId, consigneeId)
|
|
|
+ .eq(SysImplementPlan::getParentId, 0);
|
|
|
+ }
|
|
|
|
|
|
- return implementPlanService.page(new Page<>(current, size), wrapper);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- private List<Long> listVisibleEntIds(HnqzUser user) {
|
|
|
-
|
|
|
- Integer userId = user.getId();
|
|
|
-
|
|
|
- // 获取当前操作人能看到区域范围
|
|
|
- List<Long> areaIds = userAreaService.listUserAreas(Long.valueOf(userId));
|
|
|
-
|
|
|
- // 获取可见范围中所有企业的信息
|
|
|
- return enterpriseAreaService.listAreaEnts(areaIds);
|
|
|
+ // 平台||营销中心(查询全部)
|
|
|
+ else {
|
|
|
+
|
|
|
+ List<Long> ignored = new LinkedList<>();
|
|
|
+ ignored.add(-1019330L);
|
|
|
+ ignored.add(-1019986L);
|
|
|
+ ignored.add(1716964676L);
|
|
|
+ ignored.add(1716953432L);
|
|
|
+ ignored.add(-1020826L);
|
|
|
+ ignored.add(-1026289L);
|
|
|
+ ignored.add(-1026537L);
|
|
|
+
|
|
|
+ Integer userId = user.getId();
|
|
|
+ boolean ignoredFlag = (userId == 7959 || userId == 7602 || userId == 7414 || userId == 7415);
|
|
|
+ wrapper
|
|
|
+ .eq(SysImplementPlan::getParentId, 0)
|
|
|
+ .notIn(ignoredFlag, SysImplementPlan::getConsignorId, ignored);
|
|
|
+ // .notIn(ignoredFlag, SysImplementPlan::getConsigneeId, ignored);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 审核计划
|
|
|
- *
|
|
|
- * @param resource 审核信息
|
|
|
- * @param user 操作人
|
|
|
- * @return 审核结果
|
|
|
- */
|
|
|
- public Boolean checkPlan(SysImplementPlanDTO.OnCheck resource, HnqzUser user) {
|
|
|
-
|
|
|
-
|
|
|
- implementPlanService.checkState(resource.getPlanId(), Boolean.TRUE, Collections.singletonList(UpmsState.ImplementPlanState.INIT));
|
|
|
-
|
|
|
- Boolean result = resource.getResult();
|
|
|
- String username = user.getUsername();
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
- SysImplementPlan plan = new SysImplementPlan();
|
|
|
- plan.setPlanId(resource.getPlanId());
|
|
|
- plan.setPlanState(result ? UpmsState.ImplementPlanState.PASSED : UpmsState.ImplementPlanState.REJECTED);
|
|
|
- plan.setCheckResult(result);
|
|
|
- plan.setCheckMessage(resource.getMsg());
|
|
|
- plan.setCheckTime(now);
|
|
|
- plan.setChecker(username);
|
|
|
- plan.setUpdateBy(username);
|
|
|
- plan.setUpdateTime(now);
|
|
|
-
|
|
|
- // 归还父计划的分值
|
|
|
- if (!result) {
|
|
|
- SysImplementPlan p = implementPlanService.getById(resource.getPlanId());
|
|
|
- if (p.getParentId() != 0) {
|
|
|
- SysImplementPlan parentPlan = implementPlanService.getById(p.getParentId());
|
|
|
- parentPlan.setAvailScore(parentPlan.getAvailScore() + p.getPlanScore());
|
|
|
- implementPlanService.updatePlan(parentPlan);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- return implementPlanService.updatePlan(plan);
|
|
|
+ if (ArrayUtil.isNotEmpty(period) && period.length == 2) {
|
|
|
+ wrapper.ge(SysImplementPlan::getPlanIssue, period[0]);
|
|
|
+ wrapper.le(SysImplementPlan::getPlanExpiry, period[1].plusMonths(1).minusDays(1));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 创建计划详情
|
|
|
- *
|
|
|
- * @param resource 计划详情
|
|
|
- * @param user 操作人
|
|
|
- * @return 创建结果
|
|
|
- */
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public Boolean createPlanDetails(SysImplementPlanDetailsDTO.OnCreate resource, HnqzUser user) {
|
|
|
-
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
- String username = user.getUsername();
|
|
|
- List<SysImplementPlanDetailsDTO.OnItemCreate> items = resource.getItems();
|
|
|
-
|
|
|
-
|
|
|
- SysImplPlanDetails details = new SysImplPlanDetails();
|
|
|
- details.setPlanId(resource.getPlanId());
|
|
|
- details.setQty(resource.getQty());
|
|
|
- details.setTotal(resource.getTotal());
|
|
|
- details.setDetailsState(UpmsState.ImplPlanDetailsState.INIT);
|
|
|
- details.setCreateBy(username);
|
|
|
- details.setUpdateBy(username);
|
|
|
- details.setCreateTime(now);
|
|
|
- details.setUpdateTime(now);
|
|
|
- implPlanDetailsService.createDetails(details);
|
|
|
-
|
|
|
- Integer dId = details.getDetailsId();
|
|
|
- List<SysImplPlanDetailsItem> detailsItems = items.stream().map(item -> {
|
|
|
- SysImplPlanDetailsItem i = new SysImplPlanDetailsItem();
|
|
|
- i.setDetailsId(dId);
|
|
|
- i.setTaskTypeId(item.getTaskTypeId());
|
|
|
- i.setQty(item.getQty());
|
|
|
- i.setTaskTypeName(item.getTaskTypeName());
|
|
|
- i.setScore(item.getScore());
|
|
|
- i.setSubtotal(item.getSubtotal());
|
|
|
- return i;
|
|
|
- }).collect(Collectors.toList());
|
|
|
-
|
|
|
- implPlanDetailsItemService.saveItems(detailsItems);
|
|
|
-
|
|
|
- return Boolean.TRUE;
|
|
|
+ if (ArrayUtil.isNotEmpty(createTime) && createTime.length == 2) {
|
|
|
+ wrapper.between(
|
|
|
+ SysImplementPlan::getCreateTime,
|
|
|
+ createTime[0],
|
|
|
+ createTime[1].plusMonths(1).minusSeconds(1));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 审核计划详情
|
|
|
- *
|
|
|
- * @param resource 计划详情内容
|
|
|
- * @param user 操作人
|
|
|
- * @return 审核结果
|
|
|
- */
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public Boolean checkPlanDetails(SysImplementPlanDetailsDTO.OnCheck resource, HnqzUser user) {
|
|
|
-
|
|
|
- Boolean result = resource.getResult();
|
|
|
- String username = user.getUsername();
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
- SysImplPlanDetails details = new SysImplPlanDetails();
|
|
|
- details.setDetailsId(resource.getDetailsId());
|
|
|
-
|
|
|
- switch (resource.getCurrentState()) {
|
|
|
- case INIT:
|
|
|
- details.setDetailsState(result ? UpmsState.ImplPlanDetailsState.CKT1 : UpmsState.ImplPlanDetailsState.REJECTED);
|
|
|
- details.setCktRes1(result);
|
|
|
- details.setCktMsg1(resource.getMsg());
|
|
|
- details.setCktTime1(now);
|
|
|
- details.setCktName1(username);
|
|
|
- break;
|
|
|
-
|
|
|
- case CKT1:
|
|
|
- details.setDetailsState(result ? UpmsState.ImplPlanDetailsState.CKT2 : UpmsState.ImplPlanDetailsState.REJECTED);
|
|
|
- details.setCktRes2(result);
|
|
|
- details.setCktMsg2(resource.getMsg());
|
|
|
- details.setCktTime2(now);
|
|
|
- details.setCktName2(username);
|
|
|
- break;
|
|
|
- case CKT2:
|
|
|
- details.setDetailsState(result ? UpmsState.ImplPlanDetailsState.PASSED : UpmsState.ImplPlanDetailsState.REJECTED);
|
|
|
- details.setCktRes3(result);
|
|
|
- details.setCktMsg3(resource.getMsg());
|
|
|
- details.setCktTime3(now);
|
|
|
- details.setCktName3(username);
|
|
|
- break;
|
|
|
- default:
|
|
|
- throw new BizException("当前状态不支持审核");
|
|
|
-
|
|
|
- }
|
|
|
- details.setUpdateBy(username);
|
|
|
- details.setUpdateTime(now);
|
|
|
-
|
|
|
- return implPlanDetailsService.updateDetails(details);
|
|
|
+ return implementPlanService.page(new Page<>(current, size), wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Long> listVisibleEntIds(HnqzUser user) {
|
|
|
+
|
|
|
+ Integer userId = user.getId();
|
|
|
+
|
|
|
+ // 获取当前操作人能看到区域范围
|
|
|
+ List<Long> areaIds = userAreaService.listUserAreas(Long.valueOf(userId));
|
|
|
+
|
|
|
+ // 获取可见范围中所有企业的信息
|
|
|
+ return enterpriseAreaService.listAreaEnts(areaIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 审核计划
|
|
|
+ *
|
|
|
+ * @param resource 审核信息
|
|
|
+ * @param user 操作人
|
|
|
+ * @return 审核结果
|
|
|
+ */
|
|
|
+ public Boolean checkPlan(SysImplementPlanDTO.OnCheck resource, HnqzUser user) {
|
|
|
+
|
|
|
+ implementPlanService.checkState(
|
|
|
+ resource.getPlanId(),
|
|
|
+ Boolean.TRUE,
|
|
|
+ Collections.singletonList(UpmsState.ImplementPlanState.INIT));
|
|
|
+
|
|
|
+ Boolean result = resource.getResult();
|
|
|
+ String username = user.getUsername();
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ SysImplementPlan plan = new SysImplementPlan();
|
|
|
+ plan.setPlanId(resource.getPlanId());
|
|
|
+ plan.setPlanState(
|
|
|
+ result ? UpmsState.ImplementPlanState.PASSED : UpmsState.ImplementPlanState.REJECTED);
|
|
|
+ plan.setCheckResult(result);
|
|
|
+ plan.setCheckMessage(resource.getMsg());
|
|
|
+ plan.setCheckTime(now);
|
|
|
+ plan.setChecker(username);
|
|
|
+ plan.setUpdateBy(username);
|
|
|
+ plan.setUpdateTime(now);
|
|
|
+
|
|
|
+ // 归还父计划的分值
|
|
|
+ if (!result) {
|
|
|
+ SysImplementPlan p = implementPlanService.getById(resource.getPlanId());
|
|
|
+ if (p.getParentId() != 0) {
|
|
|
+ SysImplementPlan parentPlan = implementPlanService.getById(p.getParentId());
|
|
|
+ parentPlan.setAvailScore(parentPlan.getAvailScore() + p.getPlanScore());
|
|
|
+ implementPlanService.updatePlan(parentPlan);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public Map<String, Object> getPlanDetails(Integer detailsId) {
|
|
|
- SysImplPlanDetails details = implPlanDetailsService.getById(detailsId);
|
|
|
- Map<String, Object> detailsMap;
|
|
|
- if (details != null) {
|
|
|
-
|
|
|
- // 获取任务类型
|
|
|
- Map<String, WmTaskType> collect = taskTypeService.list(Wrappers.<WmTaskType>lambdaQuery().le(WmTaskType::getId, "100")
|
|
|
- .eq(WmTaskType::getDelFlag, CommonConstants.STATUS_NORMAL)
|
|
|
- .eq(WmTaskType::getEnableFlag, CommonConstants.STATUS_NORMAL)).stream()
|
|
|
- .collect(Collectors.toMap(WmTaskType::getTaskTypeName, Function.identity()));
|
|
|
- detailsMap = BeanUtil.beanToMap(details);
|
|
|
-
|
|
|
- List<SysImplPlanDetailsItem> items = implPlanDetailsItemService.listDetailItems(details.getDetailsId());
|
|
|
-
|
|
|
- List<Map<String, Object>> itemResult = items.stream().filter(item -> CharSequenceUtil.isNotBlank(item.getTaskTypeName())).map(item -> {
|
|
|
- Map<String, Object> itemMap = BeanUtil.beanToMap(item);
|
|
|
- String taskTypeName = item.getTaskTypeName();
|
|
|
- WmTaskType taskType = collect.get(taskTypeName);
|
|
|
- if (taskType != null) {
|
|
|
- itemMap.put("baseId", taskType.getBaseId());
|
|
|
- itemMap.put("parentId", taskType.getParentId());
|
|
|
- }
|
|
|
- return itemMap;
|
|
|
- }).filter(i -> Objects.nonNull(i.get("parentId"))).sorted(Comparator.comparing(i -> (String) i.get("parentId"))).collect(Collectors.toList());
|
|
|
-
|
|
|
-
|
|
|
- detailsMap.put("items", CollUtil.isNotEmpty(itemResult) ? itemResult : Collections.emptyList());
|
|
|
-
|
|
|
-
|
|
|
- } else {
|
|
|
- detailsMap = Collections.emptyMap();
|
|
|
- }
|
|
|
-
|
|
|
- return detailsMap;
|
|
|
+ return implementPlanService.updatePlan(plan);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建计划详情
|
|
|
+ *
|
|
|
+ * @param resource 计划详情
|
|
|
+ * @param user 操作人
|
|
|
+ * @return 创建结果
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean createPlanDetails(SysImplementPlanDetailsDTO.OnCreate resource, HnqzUser user) {
|
|
|
+
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ String username = user.getUsername();
|
|
|
+ List<SysImplementPlanDetailsDTO.OnItemCreate> items = resource.getItems();
|
|
|
+
|
|
|
+ SysImplPlanDetails details = new SysImplPlanDetails();
|
|
|
+ details.setPlanId(resource.getPlanId());
|
|
|
+ details.setQty(resource.getQty());
|
|
|
+ details.setTotal(resource.getTotal());
|
|
|
+ details.setDetailsState(UpmsState.ImplPlanDetailsState.INIT);
|
|
|
+ details.setCreateBy(username);
|
|
|
+ details.setUpdateBy(username);
|
|
|
+ details.setCreateTime(now);
|
|
|
+ details.setUpdateTime(now);
|
|
|
+ implPlanDetailsService.createDetails(details);
|
|
|
+
|
|
|
+ Integer dId = details.getDetailsId();
|
|
|
+ List<SysImplPlanDetailsItem> detailsItems =
|
|
|
+ items.stream()
|
|
|
+ .map(
|
|
|
+ item -> {
|
|
|
+ SysImplPlanDetailsItem i = new SysImplPlanDetailsItem();
|
|
|
+ i.setDetailsId(dId);
|
|
|
+ i.setTaskTypeId(item.getTaskTypeId());
|
|
|
+ i.setQty(item.getQty());
|
|
|
+ i.setTaskTypeName(item.getTaskTypeName());
|
|
|
+ i.setScore(item.getScore());
|
|
|
+ i.setSubtotal(item.getSubtotal());
|
|
|
+ return i;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ implPlanDetailsItemService.saveItems(detailsItems);
|
|
|
+
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 审核计划详情
|
|
|
+ *
|
|
|
+ * @param resource 计划详情内容
|
|
|
+ * @param user 操作人
|
|
|
+ * @return 审核结果
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean checkPlanDetails(SysImplementPlanDetailsDTO.OnCheck resource, HnqzUser user) {
|
|
|
+
|
|
|
+ Boolean result = resource.getResult();
|
|
|
+ String username = user.getUsername();
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ SysImplPlanDetails details = new SysImplPlanDetails();
|
|
|
+ details.setDetailsId(resource.getDetailsId());
|
|
|
+
|
|
|
+ switch (resource.getCurrentState()) {
|
|
|
+ case INIT:
|
|
|
+ details.setDetailsState(
|
|
|
+ result ? UpmsState.ImplPlanDetailsState.CKT1 : UpmsState.ImplPlanDetailsState.REJECTED);
|
|
|
+ details.setCktRes1(result);
|
|
|
+ details.setCktMsg1(resource.getMsg());
|
|
|
+ details.setCktTime1(now);
|
|
|
+ details.setCktName1(username);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case CKT1:
|
|
|
+ details.setDetailsState(
|
|
|
+ result ? UpmsState.ImplPlanDetailsState.CKT2 : UpmsState.ImplPlanDetailsState.REJECTED);
|
|
|
+ details.setCktRes2(result);
|
|
|
+ details.setCktMsg2(resource.getMsg());
|
|
|
+ details.setCktTime2(now);
|
|
|
+ details.setCktName2(username);
|
|
|
+ break;
|
|
|
+ case CKT2:
|
|
|
+ details.setDetailsState(
|
|
|
+ result
|
|
|
+ ? UpmsState.ImplPlanDetailsState.PASSED
|
|
|
+ : UpmsState.ImplPlanDetailsState.REJECTED);
|
|
|
+ details.setCktRes3(result);
|
|
|
+ details.setCktMsg3(resource.getMsg());
|
|
|
+ details.setCktTime3(now);
|
|
|
+ details.setCktName3(username);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new BizException("当前状态不支持审核");
|
|
|
+ }
|
|
|
+ details.setUpdateBy(username);
|
|
|
+ details.setUpdateTime(now);
|
|
|
+
|
|
|
+ return implPlanDetailsService.updateDetails(details);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, Object> getPlanDetails(Integer detailsId) {
|
|
|
+ SysImplPlanDetails details = implPlanDetailsService.getById(detailsId);
|
|
|
+ Map<String, Object> detailsMap;
|
|
|
+ if (details != null) {
|
|
|
+
|
|
|
+ // 获取任务类型
|
|
|
+ Map<String, WmTaskType> collect =
|
|
|
+ taskTypeService
|
|
|
+ .list(
|
|
|
+ Wrappers.<WmTaskType>lambdaQuery()
|
|
|
+ .le(WmTaskType::getId, "100")
|
|
|
+ .eq(WmTaskType::getDelFlag, CommonConstants.STATUS_NORMAL)
|
|
|
+ .eq(WmTaskType::getEnableFlag, CommonConstants.STATUS_NORMAL))
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(WmTaskType::getTaskTypeName, Function.identity()));
|
|
|
+ detailsMap = BeanUtil.beanToMap(details);
|
|
|
+
|
|
|
+ List<SysImplPlanDetailsItem> items =
|
|
|
+ implPlanDetailsItemService.listDetailItems(details.getDetailsId());
|
|
|
+
|
|
|
+ List<Map<String, Object>> itemResult =
|
|
|
+ items.stream()
|
|
|
+ .filter(item -> CharSequenceUtil.isNotBlank(item.getTaskTypeName()))
|
|
|
+ .map(
|
|
|
+ item -> {
|
|
|
+ Map<String, Object> itemMap = BeanUtil.beanToMap(item);
|
|
|
+ String taskTypeName = item.getTaskTypeName();
|
|
|
+ WmTaskType taskType = collect.get(taskTypeName);
|
|
|
+ if (taskType != null) {
|
|
|
+ itemMap.put("baseId", taskType.getBaseId());
|
|
|
+ itemMap.put("parentId", taskType.getParentId());
|
|
|
+ }
|
|
|
+ return itemMap;
|
|
|
+ })
|
|
|
+ .filter(i -> Objects.nonNull(i.get("parentId")))
|
|
|
+ .sorted(Comparator.comparing(i -> (String) i.get("parentId")))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ detailsMap.put(
|
|
|
+ "items", CollUtil.isNotEmpty(itemResult) ? itemResult : Collections.emptyList());
|
|
|
+
|
|
|
+ } else {
|
|
|
+ detailsMap = Collections.emptyMap();
|
|
|
}
|
|
|
|
|
|
- public List<SysImplementPlanVO.ToList> listPlans(UpmsState.ImplementPlanState planState, UpmsType.ImplementPlanType planType, String pkgId, HnqzUser user) {
|
|
|
-
|
|
|
- LambdaQueryWrapper<SysImplementPlan> queryWrapper = Wrappers.<SysImplementPlan>lambdaQuery()
|
|
|
- .gt(SysImplementPlan::getAvailScore, 0L)
|
|
|
- .eq(Objects.nonNull(planType), SysImplementPlan::getPlanType, planType)
|
|
|
- .eq(SysImplementPlan::getPlanState, planState);
|
|
|
-
|
|
|
- // 药企
|
|
|
- if ("-1".equals(pkgId)){
|
|
|
- Integer entId = user.getDeptId();
|
|
|
- queryWrapper.eq(SysImplementPlan::getConsignorId, entId);
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- SysPlanPkg one = planPkgService.getOne(Wrappers.<SysPlanPkg>lambdaQuery().eq(SysPlanPkg::getPkgId, Integer.valueOf(pkgId)));
|
|
|
- if (one == null) {
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
-
|
|
|
- queryWrapper.eq(SysImplementPlan::getParentId, one.getPlanId());
|
|
|
- }
|
|
|
-
|
|
|
+ return detailsMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<SysImplementPlanVO.ToList> listPlans(
|
|
|
+ UpmsState.ImplementPlanState planState,
|
|
|
+ UpmsType.ImplementPlanType planType,
|
|
|
+ String pkgId,
|
|
|
+ HnqzUser user) {
|
|
|
+
|
|
|
+ LambdaQueryWrapper<SysImplementPlan> queryWrapper =
|
|
|
+ Wrappers.<SysImplementPlan>lambdaQuery()
|
|
|
+ // .gt(SysImplementPlan::getAvailScore, 0L)
|
|
|
+ .eq(Objects.nonNull(planType), SysImplementPlan::getPlanType, planType)
|
|
|
+ .eq(SysImplementPlan::getPlanState, planState);
|
|
|
+
|
|
|
+ // 药企
|
|
|
+ if ("-1".equals(pkgId)) {
|
|
|
+ Integer entId = user.getDeptId();
|
|
|
+ queryWrapper.eq(SysImplementPlan::getConsignorId, entId);
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ SysPlanPkg one =
|
|
|
+ planPkgService.getOne(
|
|
|
+ Wrappers.<SysPlanPkg>lambdaQuery().eq(SysPlanPkg::getPkgId, Integer.valueOf(pkgId)));
|
|
|
+ if (one == null) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ queryWrapper.eq(SysImplementPlan::getParentId, one.getPlanId());
|
|
|
+ queryWrapper.gt(SysImplementPlan::getAvailScore, 0L);
|
|
|
+ }
|
|
|
|
|
|
- List<SysImplementPlan> plans = implementPlanService.list(queryWrapper);
|
|
|
+ List<SysImplementPlan> plans = implementPlanService.list(queryWrapper);
|
|
|
|
|
|
+ if (CollUtil.isEmpty(plans)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
|
|
|
- if (CollUtil.isEmpty(plans)) {
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
+ // 判断是否关联了
|
|
|
+ List<Integer> planIds =
|
|
|
+ plans.stream()
|
|
|
+ .mapToInt(SysImplementPlan::getPlanId)
|
|
|
+ .boxed()
|
|
|
+ .distinct()
|
|
|
+ .sorted()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ Set<Integer> relation =
|
|
|
+ planPkgService
|
|
|
+ .list(Wrappers.<SysPlanPkg>lambdaQuery().in(SysPlanPkg::getPlanId, planIds))
|
|
|
+ .stream()
|
|
|
+ .mapToInt(SysPlanPkg::getPlanId)
|
|
|
+ .boxed()
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ if (CollUtil.isNotEmpty(relation)) {
|
|
|
+ plans =
|
|
|
+ plans.stream()
|
|
|
+ .filter(plan -> !relation.contains(plan.getPlanId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
|
|
|
+ if (CollUtil.isEmpty(plans)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
|
|
|
- // 获取承接人ID
|
|
|
- Set<Integer> consigneeIds = plans.stream().mapToInt(SysImplementPlan::getConsigneeId).boxed().collect(Collectors.toSet());
|
|
|
- // 获取承接人
|
|
|
- Map<Integer, SysDept> consigneeMap = deptService.mapConsignee(consigneeIds, true);
|
|
|
- // 获取商品信息
|
|
|
- Set<Integer> skuIds = plans.stream().map(SysImplementPlan::getSkuId).collect(Collectors.toSet());
|
|
|
- List<Map<String, String>> skuList = drugEntDrugtableService.listDrugs(skuIds);
|
|
|
- Map<Integer, Map<String, String>> skuMap = skuList.stream().collect(Collectors.toMap(sku -> Integer.valueOf(sku.get("drug_id")), Function.identity()));
|
|
|
-
|
|
|
- Map<String, WmTaskType> collect = taskTypeService.list(Wrappers.<WmTaskType>lambdaQuery().lt(WmTaskType::getId, "100")).stream().collect(Collectors.toMap(WmTaskType::getTaskTypeName, Function.identity()));
|
|
|
- return plans.stream().map(p -> {
|
|
|
- SysImplementPlanVO.ToList copied = BeanUtil.copyProperties(p, SysImplementPlanVO.ToList.class);
|
|
|
-
|
|
|
- // 设置承接人信息
|
|
|
- Map<String, Object> consigneeInfo = new HashMap<>(2);
|
|
|
- consigneeInfo.put("consigneeId", p.getConsigneeId());
|
|
|
- SysDept sysDept = consigneeMap.get(p.getConsigneeId());
|
|
|
- consigneeInfo.put("consigneeName", sysDept == null ? "" : sysDept.getName());
|
|
|
- copied.setConsigneeInfo(consigneeInfo);
|
|
|
-
|
|
|
- // 产品信息
|
|
|
- Map<String, String> sku = skuMap.get(p.getSkuId());
|
|
|
- Map<String, Object> skuInfo = new HashMap<>(3);
|
|
|
- skuInfo.put("skuId", p.getSkuId());
|
|
|
- skuInfo.put("skuName", MapUtil.isEmpty(sku) ? "" : sku.get("drug_name"));
|
|
|
- skuInfo.put("manufacturer", MapUtil.isEmpty(sku) ? "" : sku.get("ent_name"));
|
|
|
- copied.setSkuInfo(skuInfo);
|
|
|
-
|
|
|
- // 拆解详情
|
|
|
- SysImplPlanDetails details = implPlanDetailsService.getDetailsByPlanId(p.getPlanId(), UpmsState.ImplPlanDetailsState.PASSED);
|
|
|
- copied.setPlanDetails(details);
|
|
|
- if (details != null) {
|
|
|
+ // 获取承接人ID
|
|
|
+ Set<Integer> consigneeIds =
|
|
|
+ plans.stream()
|
|
|
+ .mapToInt(SysImplementPlan::getConsigneeId)
|
|
|
+ .boxed()
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ // 获取承接人
|
|
|
+ Map<Integer, SysDept> consigneeMap = deptService.mapConsignee(consigneeIds, true);
|
|
|
+ // 获取商品信息
|
|
|
+ Set<Integer> skuIds =
|
|
|
+ plans.stream().map(SysImplementPlan::getSkuId).collect(Collectors.toSet());
|
|
|
+ List<Map<String, String>> skuList = drugEntDrugtableService.listDrugs(skuIds);
|
|
|
+ Map<Integer, Map<String, String>> skuMap =
|
|
|
+ skuList.stream()
|
|
|
+ .collect(
|
|
|
+ Collectors.toMap(sku -> Integer.valueOf(sku.get("drug_id")), Function.identity()));
|
|
|
+
|
|
|
+ Map<String, WmTaskType> collect =
|
|
|
+ taskTypeService
|
|
|
+ .list(Wrappers.<WmTaskType>lambdaQuery().lt(WmTaskType::getId, "100"))
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(WmTaskType::getTaskTypeName, Function.identity()));
|
|
|
+ return plans.stream()
|
|
|
+ .map(
|
|
|
+ p -> {
|
|
|
+ SysImplementPlanVO.ToList copied =
|
|
|
+ BeanUtil.copyProperties(p, SysImplementPlanVO.ToList.class);
|
|
|
+
|
|
|
+ // 设置承接人信息
|
|
|
+ Map<String, Object> consigneeInfo = new HashMap<>(2);
|
|
|
+ consigneeInfo.put("consigneeId", p.getConsigneeId());
|
|
|
+ SysDept sysDept = consigneeMap.get(p.getConsigneeId());
|
|
|
+ consigneeInfo.put("consigneeName", sysDept == null ? "" : sysDept.getName());
|
|
|
+ copied.setConsigneeInfo(consigneeInfo);
|
|
|
+
|
|
|
+ // 产品信息
|
|
|
+ Map<String, String> sku = skuMap.get(p.getSkuId());
|
|
|
+ Map<String, Object> skuInfo = new HashMap<>(3);
|
|
|
+ skuInfo.put("skuId", p.getSkuId());
|
|
|
+ skuInfo.put("skuName", MapUtil.isEmpty(sku) ? "" : sku.get("drug_name"));
|
|
|
+ skuInfo.put("manufacturer", MapUtil.isEmpty(sku) ? "" : sku.get("ent_name"));
|
|
|
+ copied.setSkuInfo(skuInfo);
|
|
|
+
|
|
|
+ // 拆解详情
|
|
|
+ SysImplPlanDetails details =
|
|
|
+ implPlanDetailsService.getDetailsByPlanId(
|
|
|
+ p.getPlanId(), UpmsState.ImplPlanDetailsState.PASSED);
|
|
|
+ copied.setPlanDetails(details);
|
|
|
+ if (details != null) {
|
|
|
|
|
|
// 拆解子项
|
|
|
- List<SysImplPlanDetailsItem> detailsItems = implPlanDetailsItemService.listDetailItems(details.getDetailsId()).stream().filter(item -> item.getQty() > 0).collect(Collectors.toList());
|
|
|
+ List<SysImplPlanDetailsItem> detailsItems =
|
|
|
+ implPlanDetailsItemService.listDetailItems(details.getDetailsId()).stream()
|
|
|
+ .filter(item -> item.getQty() > 0)
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
List<Map<String, Object>> coll = null;
|
|
|
if (CollUtil.isNotEmpty(detailsItems)) {
|
|
|
|
|
|
- coll = detailsItems.stream().map(item -> {
|
|
|
- Map<String, Object> map = BeanUtil.copyProperties(item, Map.class);
|
|
|
- WmTaskType taskType = collect.get(item.getTaskTypeName());
|
|
|
- map.put("orgTaskTypeId", Objects.nonNull(taskType) ? taskType.getId() : null);
|
|
|
- map.put("baseId", Objects.nonNull(taskType) ? taskType.getBaseId() : null);
|
|
|
- map.put("parent_id", Objects.nonNull(taskType) ? taskType.getParentId() : null);
|
|
|
- return map;
|
|
|
- }).filter(m -> Objects.nonNull(m.get("parent_id"))).sorted(Comparator.comparing(m -> (String) m.get("parent_id"))).collect(Collectors.toList());
|
|
|
+ coll =
|
|
|
+ detailsItems.stream()
|
|
|
+ .map(
|
|
|
+ item -> {
|
|
|
+ Map<String, Object> map = BeanUtil.copyProperties(item, Map.class);
|
|
|
+ WmTaskType taskType = collect.get(item.getTaskTypeName());
|
|
|
+ map.put(
|
|
|
+ "orgTaskTypeId",
|
|
|
+ Objects.nonNull(taskType) ? taskType.getId() : null);
|
|
|
+ map.put(
|
|
|
+ "baseId",
|
|
|
+ Objects.nonNull(taskType) ? taskType.getBaseId() : null);
|
|
|
+ map.put(
|
|
|
+ "parent_id",
|
|
|
+ Objects.nonNull(taskType) ? taskType.getParentId() : null);
|
|
|
+ return map;
|
|
|
+ })
|
|
|
+ .filter(m -> Objects.nonNull(m.get("parent_id")))
|
|
|
+ .sorted(Comparator.comparing(m -> (String) m.get("parent_id")))
|
|
|
+ .collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
copied.setPlanItems(CollUtil.isNotEmpty(coll) ? coll : Collections.emptyList());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- return copied;
|
|
|
-
|
|
|
- }).collect(Collectors.toList());
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public SysImplementPlanVO.ToList findById(Long planId) {
|
|
|
- SysImplementPlan p = implementPlanService.getById(planId);
|
|
|
- SysImplementPlanVO.ToList copied = BeanUtil.copyProperties(p, SysImplementPlanVO.ToList.class);
|
|
|
-
|
|
|
- // 设置承接人信息
|
|
|
- // 获取承接人
|
|
|
- Map<Integer, SysDept> consigneeMap = deptService.mapConsignee(new HashSet<>(Collections.singletonList(p.getConsigneeId())), true);
|
|
|
- Map<String, Object> consigneeInfo = new HashMap<>(2);
|
|
|
- consigneeInfo.put("consigneeId", p.getConsigneeId());
|
|
|
- SysDept sysDept = consigneeMap.get(p.getConsigneeId());
|
|
|
- consigneeInfo.put("consigneeName", sysDept == null ? "" : sysDept.getName());
|
|
|
- copied.setConsigneeInfo(consigneeInfo);
|
|
|
-
|
|
|
- // 产品信息
|
|
|
- List<Map<String, String>> skuList = drugEntDrugtableService.listDrugs(Collections.singletonList(p.getSkuId()));
|
|
|
- Map<Integer, Map<String, String>> skuMap = skuList.stream().collect(Collectors.toMap(sku -> Integer.valueOf(sku.get("drug_id")), Function.identity()));
|
|
|
- Map<String, String> sku = skuMap.get(p.getSkuId());
|
|
|
- Map<String, Object> skuInfo = new HashMap<>(3);
|
|
|
- skuInfo.put("skuId", p.getSkuId());
|
|
|
- skuInfo.put("skuName", MapUtil.isEmpty(sku) ? "" : sku.get("drug_name"));
|
|
|
- skuInfo.put("manufacturer", MapUtil.isEmpty(sku) ? "" : sku.get("ent_name"));
|
|
|
- copied.setSkuInfo(skuInfo);
|
|
|
-
|
|
|
- // planDtl
|
|
|
-
|
|
|
- // 获取计划详情
|
|
|
- List<SysImplPlanDetails> details = implPlanDetailsService.list(Wrappers.<SysImplPlanDetails>lambdaQuery()
|
|
|
+ }
|
|
|
+
|
|
|
+ return copied;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ public SysImplementPlanVO.ToList findById(Long planId) {
|
|
|
+ SysImplementPlan p = implementPlanService.getById(planId);
|
|
|
+ SysImplementPlanVO.ToList copied = BeanUtil.copyProperties(p, SysImplementPlanVO.ToList.class);
|
|
|
+
|
|
|
+ // 设置承接人信息
|
|
|
+ // 获取承接人
|
|
|
+ Map<Integer, SysDept> consigneeMap =
|
|
|
+ deptService.mapConsignee(
|
|
|
+ new HashSet<>(Collections.singletonList(p.getConsigneeId())), true);
|
|
|
+ Map<String, Object> consigneeInfo = new HashMap<>(2);
|
|
|
+ consigneeInfo.put("consigneeId", p.getConsigneeId());
|
|
|
+ SysDept sysDept = consigneeMap.get(p.getConsigneeId());
|
|
|
+ consigneeInfo.put("consigneeName", sysDept == null ? "" : sysDept.getName());
|
|
|
+ copied.setConsigneeInfo(consigneeInfo);
|
|
|
+
|
|
|
+ // 产品信息
|
|
|
+ List<Map<String, String>> skuList =
|
|
|
+ drugEntDrugtableService.listDrugs(Collections.singletonList(p.getSkuId()));
|
|
|
+ Map<Integer, Map<String, String>> skuMap =
|
|
|
+ skuList.stream()
|
|
|
+ .collect(
|
|
|
+ Collectors.toMap(sku -> Integer.valueOf(sku.get("drug_id")), Function.identity()));
|
|
|
+ Map<String, String> sku = skuMap.get(p.getSkuId());
|
|
|
+ Map<String, Object> skuInfo = new HashMap<>(3);
|
|
|
+ skuInfo.put("skuId", p.getSkuId());
|
|
|
+ skuInfo.put("skuName", MapUtil.isEmpty(sku) ? "" : sku.get("drug_name"));
|
|
|
+ skuInfo.put("manufacturer", MapUtil.isEmpty(sku) ? "" : sku.get("ent_name"));
|
|
|
+ copied.setSkuInfo(skuInfo);
|
|
|
+
|
|
|
+ // planDtl
|
|
|
+
|
|
|
+ // 获取计划详情
|
|
|
+ List<SysImplPlanDetails> details =
|
|
|
+ implPlanDetailsService.list(
|
|
|
+ Wrappers.<SysImplPlanDetails>lambdaQuery()
|
|
|
.eq(SysImplPlanDetails::getPlanId, planId)
|
|
|
- .orderByDesc(SysImplPlanDetails::getUpdateTime)
|
|
|
- );
|
|
|
- copied.setPlanDetails(CollUtil.isEmpty(details) ? null : details.get(0));
|
|
|
-
|
|
|
- // 获取父级
|
|
|
- Integer parentId = p.getParentId();
|
|
|
-
|
|
|
- if (parentId == 0) {
|
|
|
- copied.setParentPlanAvailScore(0L);
|
|
|
- copied.setParentPlanScore(0L);
|
|
|
- } else {
|
|
|
- SysImplementPlan pp = implementPlanService.getById(p.getParentId());
|
|
|
- if (pp == null) {
|
|
|
- copied.setParentPlanAvailScore(0L);
|
|
|
- copied.setParentPlanScore(0L);
|
|
|
- } else {
|
|
|
- copied.setParentPlanAvailScore(pp.getAvailScore());
|
|
|
- copied.setParentPlanScore(pp.getPlanScore());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- return copied;
|
|
|
+ .orderByDesc(SysImplPlanDetails::getUpdateTime));
|
|
|
+ copied.setPlanDetails(CollUtil.isEmpty(details) ? null : details.get(0));
|
|
|
+
|
|
|
+ // 获取父级
|
|
|
+ Integer parentId = p.getParentId();
|
|
|
+
|
|
|
+ if (parentId == 0) {
|
|
|
+ copied.setParentPlanAvailScore(0L);
|
|
|
+ copied.setParentPlanScore(0L);
|
|
|
+ } else {
|
|
|
+ SysImplementPlan pp = implementPlanService.getById(p.getParentId());
|
|
|
+ if (pp == null) {
|
|
|
+ copied.setParentPlanAvailScore(0L);
|
|
|
+ copied.setParentPlanScore(0L);
|
|
|
+ } else {
|
|
|
+ copied.setParentPlanAvailScore(pp.getAvailScore());
|
|
|
+ copied.setParentPlanScore(pp.getPlanScore());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 批量创建
|
|
|
- *
|
|
|
- * @param resource 批量信息
|
|
|
- * @param user 创建人
|
|
|
- * @return 创建结果
|
|
|
- */
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public List<Map<String, String>> createBatch(List<SysImplementPlanDTO.OnBatchCreate> resource, HnqzUser user) {
|
|
|
-
|
|
|
-
|
|
|
- // 加锁防止多处理
|
|
|
- Integer deptId = user.getDeptId();
|
|
|
- String lock = "lock:plan:batch:" + deptId;
|
|
|
- boolean locked = false;
|
|
|
-
|
|
|
- try {
|
|
|
-
|
|
|
- locked = Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(lock, IdUtil.fastUUID(), 10, TimeUnit.MINUTES));
|
|
|
-
|
|
|
- if (!locked) {
|
|
|
- throw new BizException("有在途的操作,请稍后");
|
|
|
- }
|
|
|
-
|
|
|
- log.info("批量操作加锁:{} =====================================", lock);
|
|
|
-
|
|
|
- // 获取商品列表
|
|
|
- List<Map<String, String>> drugs = drugEntDrugtableService.listDrugByDeptId(Collections.singletonList(deptId));
|
|
|
-
|
|
|
- // 获取代理商
|
|
|
- Map<String, SysDept> deptMap = deptService.list(Wrappers.<SysDept>lambdaQuery()
|
|
|
- .eq(SysDept::getDelFlag, CommonConstants.STATUS_NORMAL)
|
|
|
- .eq(SysDept::getLevel, 3)).stream()
|
|
|
- .collect(Collectors.toMap(SysDept::getName, Function.identity(), (v1, v2) -> v1));
|
|
|
-
|
|
|
- // 校验表单信息
|
|
|
- List<Map<String, String>> errorMap = checkDataOnBatchCreate(resource, drugs, deptMap, deptId);
|
|
|
- if (CollUtil.isNotEmpty(errorMap)) {
|
|
|
- log.info("错误信息:{}", 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);
|
|
|
- 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;
|
|
|
-
|
|
|
- UpmsState.ImplementPlanState state;
|
|
|
- if (UpmsType.ImplementPlanType.ANN.equals(pt)) {
|
|
|
- issue = LocalDate.of(Integer.parseInt(item.getYear()), 1, 1);
|
|
|
- expiry = issue.plusYears(1).minusDays(1);
|
|
|
- state = UpmsState.ImplementPlanState.INIT;
|
|
|
- } 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);
|
|
|
- state = UpmsState.ImplementPlanState.PASSED;
|
|
|
- plan.setCheckResult(true);
|
|
|
- plan.setCheckMessage("通过(审批流程,季度计划自动通过,不需要上级审批)");
|
|
|
- plan.setCheckTime(now);
|
|
|
- plan.setChecker(username);
|
|
|
- }
|
|
|
-
|
|
|
- plan.setPlanState(state);
|
|
|
- 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.emptyList();
|
|
|
-
|
|
|
- } finally {
|
|
|
- if (locked) {
|
|
|
- log.info("批量操作解锁:{} =====================================", lock);
|
|
|
- redisTemplate.delete(lock);
|
|
|
- }
|
|
|
- }
|
|
|
+ return copied;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量创建
|
|
|
+ *
|
|
|
+ * @param resource 批量信息
|
|
|
+ * @param user 创建人
|
|
|
+ * @return 创建结果
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public List<Map<String, String>> createBatch(
|
|
|
+ List<SysImplementPlanDTO.OnBatchCreate> resource, HnqzUser user) {
|
|
|
+
|
|
|
+ // 加锁防止多处理
|
|
|
+ Integer deptId = user.getDeptId();
|
|
|
+ String lock = "lock:plan:batch:" + deptId;
|
|
|
+ boolean locked = false;
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ locked =
|
|
|
+ Boolean.TRUE.equals(
|
|
|
+ redisTemplate
|
|
|
+ .opsForValue()
|
|
|
+ .setIfAbsent(lock, IdUtil.fastUUID(), 10, TimeUnit.MINUTES));
|
|
|
+
|
|
|
+ if (!locked) {
|
|
|
+ throw new BizException("有在途的操作,请稍后");
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("批量操作加锁:{} =====================================", lock);
|
|
|
+
|
|
|
+ // 获取商品列表
|
|
|
+ List<Map<String, String>> drugs =
|
|
|
+ drugEntDrugtableService.listDrugByDeptId(Collections.singletonList(deptId));
|
|
|
+
|
|
|
+ // 获取代理商
|
|
|
+ Map<String, SysDept> deptMap =
|
|
|
+ deptService
|
|
|
+ .list(
|
|
|
+ Wrappers.<SysDept>lambdaQuery()
|
|
|
+ .eq(SysDept::getDelFlag, CommonConstants.STATUS_NORMAL)
|
|
|
+ .eq(SysDept::getLevel, 3))
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(SysDept::getName, Function.identity(), (v1, v2) -> v1));
|
|
|
+
|
|
|
+ // 校验表单信息
|
|
|
+ List<Map<String, String>> errorMap = checkDataOnBatchCreate(resource, drugs, deptMap, deptId);
|
|
|
+ if (CollUtil.isNotEmpty(errorMap)) {
|
|
|
+ log.info("错误信息:{}", 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);
|
|
|
+ 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;
|
|
|
+
|
|
|
+ UpmsState.ImplementPlanState state;
|
|
|
+ if (UpmsType.ImplementPlanType.ANN.equals(pt)) {
|
|
|
+ issue = LocalDate.of(Integer.parseInt(item.getYear()), 1, 1);
|
|
|
+ expiry = issue.plusYears(1).minusDays(1);
|
|
|
+ state = UpmsState.ImplementPlanState.INIT;
|
|
|
+ } 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);
|
|
|
+ state = UpmsState.ImplementPlanState.PASSED;
|
|
|
+ plan.setCheckResult(true);
|
|
|
+ plan.setCheckMessage("通过(审批流程,季度计划自动通过,不需要上级审批)");
|
|
|
+ plan.setCheckTime(now);
|
|
|
+ plan.setChecker(username);
|
|
|
+ }
|
|
|
+
|
|
|
+ plan.setPlanState(state);
|
|
|
+ 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.emptyList();
|
|
|
+
|
|
|
+ } finally {
|
|
|
+ if (locked) {
|
|
|
+ log.info("批量操作解锁:{} =====================================", lock);
|
|
|
+ redisTemplate.delete(lock);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量创建校验
|
|
|
+ *
|
|
|
+ * @param resource 校验信息
|
|
|
+ */
|
|
|
+ private List<Map<String, String>> checkDataOnBatchCreate(
|
|
|
+ List<SysImplementPlanDTO.OnBatchCreate> resource,
|
|
|
+ List<Map<String, String>> drugs,
|
|
|
+ Map<String, SysDept> deptMap,
|
|
|
+ Integer deptId) {
|
|
|
+
|
|
|
+ List<Map<String, String>> errorlist = new LinkedList<>();
|
|
|
+
|
|
|
+ int size = resource.size();
|
|
|
+
|
|
|
+ // 校验size
|
|
|
+ if (size == 0) {
|
|
|
+ Map<String, String> errorMap = new HashMap<>(2);
|
|
|
+ errorMap.put("idx", "1");
|
|
|
+ errorMap.put("errorMsg", "不能上传空表");
|
|
|
+ errorlist.add(errorMap);
|
|
|
+ return errorlist;
|
|
|
+ }
|
|
|
|
|
|
+ if (size > 500) {
|
|
|
+ Map<String, String> errorMap = new HashMap<>(2);
|
|
|
+ errorMap.put("idx", "500");
|
|
|
+ errorMap.put("errorMsg", "单次支持最大批量数为500条");
|
|
|
+ errorlist.add(errorMap);
|
|
|
+ return errorlist;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 批量创建校验
|
|
|
- *
|
|
|
- * @param resource 校验信息
|
|
|
- */
|
|
|
- private List<Map<String, String>> checkDataOnBatchCreate(List<SysImplementPlanDTO.OnBatchCreate> resource,
|
|
|
- List<Map<String, String>> drugs,
|
|
|
- Map<String, SysDept> deptMap,
|
|
|
- Integer deptId) {
|
|
|
-
|
|
|
- List<Map<String, String>> errorlist = new LinkedList<>();
|
|
|
-
|
|
|
- int size = resource.size();
|
|
|
-
|
|
|
- // 校验size
|
|
|
- if (size == 0) {
|
|
|
- Map<String, String> errorMap = new HashMap<>(2);
|
|
|
- errorMap.put("idx", "1");
|
|
|
- errorMap.put("errorMsg", "不能上传空表");
|
|
|
- errorlist.add(errorMap);
|
|
|
- return errorlist;
|
|
|
+ // 校验表单重复项
|
|
|
+ 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, planName, consignee)) {
|
|
|
+ errorMsg.append("服务计划信息不全,存在未填写的内容;");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验类型
|
|
|
+ if (!StrUtil.equalsAny(planType, "年度", "季度")) {
|
|
|
+ errorMsg.append("计划类型不正确;");
|
|
|
+ }
|
|
|
+
|
|
|
+ if ("季度".equals(planType) && StrUtil.isBlank(quarter)) {
|
|
|
+ errorMsg.append("季度服务计划所属季度缺失;");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验积分
|
|
|
+ try {
|
|
|
+ if (Long.parseLong(planScore) <= 0) {
|
|
|
+ errorMsg.append("计划值小于0;");
|
|
|
}
|
|
|
-
|
|
|
- if (size > 500) {
|
|
|
- Map<String, String> errorMap = new HashMap<>(2);
|
|
|
- errorMap.put("idx", "500");
|
|
|
- errorMap.put("errorMsg", "单次支持最大批量数为500条");
|
|
|
- errorlist.add(errorMap);
|
|
|
- return errorlist;
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ errorMsg.append("计划值不是整数;");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验年度和季度
|
|
|
+ try {
|
|
|
+ if (Integer.parseInt(year) <= 0) {
|
|
|
+ errorMsg.append("年度小于0;");
|
|
|
}
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ errorMsg.append("年度非数字;");
|
|
|
+ }
|
|
|
|
|
|
- // 校验表单重复项
|
|
|
- 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, planName, consignee)) {
|
|
|
- errorMsg.append("服务计划信息不全,存在未填写的内容;");
|
|
|
- }
|
|
|
-
|
|
|
- // 校验类型
|
|
|
- if (!StrUtil.equalsAny(planType, "年度", "季度")) {
|
|
|
- errorMsg.append("计划类型不正确;");
|
|
|
- }
|
|
|
-
|
|
|
- if ("季度".equals(planType) && StrUtil.isBlank(quarter)) {
|
|
|
- errorMsg.append("季度服务计划所属季度缺失;");
|
|
|
- }
|
|
|
-
|
|
|
- // 校验积分
|
|
|
- try {
|
|
|
- if (Long.parseLong(planScore) <= 0) {
|
|
|
- errorMsg.append("计划值小于0;");
|
|
|
- }
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- errorMsg.append("计划值不是整数;");
|
|
|
- }
|
|
|
-
|
|
|
- // 校验年度和季度
|
|
|
- try {
|
|
|
- if (Integer.parseInt(year) <= 0) {
|
|
|
- errorMsg.append("年度小于0;");
|
|
|
- }
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- errorMsg.append("年度非数字;");
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- if (Integer.parseInt(quarter) <= 0) {
|
|
|
- errorMsg.append("季度小于0;");
|
|
|
- }
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- 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) && onBatchCreates.size() > 1) {
|
|
|
- errorMsg.append("表单内存在重名服务计划名称;");
|
|
|
- } else {
|
|
|
- boolean dupName = implementPlanService.dupName(planName, deptId, Collections.emptyList());
|
|
|
- if (dupName) {
|
|
|
- errorMsg.append("服务计划名称已存在;");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 校验承接单位
|
|
|
- if (CollUtil.isEmpty(deptMap)) {
|
|
|
- errorMsg.append("承接对象不存在;");
|
|
|
- } else {
|
|
|
- SysDept sysDept = deptMap.get(consignee);
|
|
|
- if (sysDept == null) {
|
|
|
- errorMsg.append("承接对象不存在;");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StrUtil.isNotBlank(errorMsg)) {
|
|
|
- Map<String, String> errorMap = new HashMap<>(2);
|
|
|
- errorMap.put("idx", String.valueOf(i + 1));
|
|
|
- errorMap.put("errorMsg", errorMsg.toString());
|
|
|
- errorlist.add(errorMap);
|
|
|
- }
|
|
|
-
|
|
|
+ try {
|
|
|
+ if (Integer.parseInt(quarter) <= 0) {
|
|
|
+ errorMsg.append("季度小于0;");
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- return errorlist;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public List<PlanInfoExportModel> exportPlan(SysImplementPlanDTO.OnPage query, HnqzUser operator) {
|
|
|
-
|
|
|
-
|
|
|
- int entLevel = roleService.getEntLevel();
|
|
|
-
|
|
|
- Page<SysImplementPlan> page = toBasePage(entLevel, query, operator);
|
|
|
-
|
|
|
- List<SysImplementPlan> records = page.getRecords();
|
|
|
-
|
|
|
- if (CollUtil.isEmpty(records)) {
|
|
|
- throw new BizException("未查询到数据");
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ 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) && onBatchCreates.size() > 1) {
|
|
|
+ errorMsg.append("表单内存在重名服务计划名称;");
|
|
|
+ } else {
|
|
|
+ boolean dupName = implementPlanService.dupName(planName, deptId, Collections.emptyList());
|
|
|
+ if (dupName) {
|
|
|
+ errorMsg.append("服务计划名称已存在;");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验承接单位
|
|
|
+ if (CollUtil.isEmpty(deptMap)) {
|
|
|
+ errorMsg.append("承接对象不存在;");
|
|
|
+ } else {
|
|
|
+ SysDept sysDept = deptMap.get(consignee);
|
|
|
+ if (sysDept == null) {
|
|
|
+ errorMsg.append("承接对象不存在;");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StrUtil.isNotBlank(errorMsg)) {
|
|
|
+ Map<String, String> errorMap = new HashMap<>(2);
|
|
|
+ errorMap.put("idx", String.valueOf(i + 1));
|
|
|
+ errorMap.put("errorMsg", errorMsg.toString());
|
|
|
+ errorlist.add(errorMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- List<TreeNode<Integer>> toPages = toTreeNode(records);
|
|
|
-
|
|
|
-
|
|
|
- List<PlanInfoExportModel> collect = toPages.stream().map(item -> {
|
|
|
-
|
|
|
- PlanInfoExportModel model = new PlanInfoExportModel();
|
|
|
- model.setPlanName((String) item.getName());
|
|
|
-
|
|
|
- Map<String, Object> extra = item.getExtra();
|
|
|
-
|
|
|
- SysImplementPlanVO.ToPage toPage = BeanUtil.mapToBean(extra, SysImplementPlanVO.ToPage.class, true, CopyOptions.create());
|
|
|
-
|
|
|
- Map<String, Object> skuInfo = toPage.getSkuInfo();
|
|
|
- model.setSkuName(skuInfo.get("skuName").toString());
|
|
|
- Map<String, Object> consignee = toPage.getConsigneeInfo();
|
|
|
- model.setConsignee(consignee.get("consigneeName").toString());
|
|
|
-
|
|
|
- UpmsType.ImplementPlanType planType = toPage.getPlanType();
|
|
|
- model.setPlanType(planType.getDesc());
|
|
|
- model.setPlanScore(toPage.getPlanScore().toString());
|
|
|
-
|
|
|
- LocalDate planIssue = toPage.getPlanIssue();
|
|
|
+ return errorlist;
|
|
|
+ }
|
|
|
|
|
|
- model.setYear(String.valueOf(planIssue.getYear()));
|
|
|
+ public List<PlanInfoExportModel> exportPlan(SysImplementPlanDTO.OnPage query, HnqzUser operator) {
|
|
|
|
|
|
- String qtr;
|
|
|
- if (UpmsType.ImplementPlanType.QRT.equals(planType)) {
|
|
|
- int monthValue = planIssue.getMonthValue();
|
|
|
- qtr = String.valueOf((monthValue + 2) / 3);
|
|
|
- } else {
|
|
|
- qtr = "";
|
|
|
- }
|
|
|
- model.setQuarter(qtr);
|
|
|
- model.setPlanId(item.getId().toString());
|
|
|
- // model.setCheckResult(toPage.getCheckResult() == null ? "" : toPage.getCheckResult() ? "通过" : "拒绝");
|
|
|
- // model.setCheckMarks(StrUtil.isNotBlank(toPage.getCheckMessage()) ? toPage.getCheckMessage() : "");
|
|
|
+ int entLevel = roleService.getEntLevel();
|
|
|
|
|
|
- return model;
|
|
|
+ Page<SysImplementPlan> page = toBasePage(entLevel, query, operator);
|
|
|
|
|
|
- }).collect(Collectors.toList());
|
|
|
+ List<SysImplementPlan> records = page.getRecords();
|
|
|
|
|
|
- return collect;
|
|
|
+ if (CollUtil.isEmpty(records)) {
|
|
|
+ throw new BizException("未查询到数据");
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 导出计划详情
|
|
|
- *
|
|
|
- * @param query 查询条件
|
|
|
- * @param user 操作人
|
|
|
- * @return 详情信息
|
|
|
- */
|
|
|
- public List<PlanDetailsExportModel> exportPlanDetails(SysImplementPlanDetailsDTO.OnExport query, HnqzUser user) {
|
|
|
-
|
|
|
-
|
|
|
- List<Integer> roles = SecurityUtils.getRoles();
|
|
|
-
|
|
|
+ List<TreeNode<Integer>> toPages = toTreeNode(records);
|
|
|
+
|
|
|
+ List<PlanInfoExportModel> collect =
|
|
|
+ toPages.stream()
|
|
|
+ .map(
|
|
|
+ item -> {
|
|
|
+ PlanInfoExportModel model = new PlanInfoExportModel();
|
|
|
+ model.setPlanName((String) item.getName());
|
|
|
+
|
|
|
+ Map<String, Object> extra = item.getExtra();
|
|
|
+
|
|
|
+ SysImplementPlanVO.ToPage toPage =
|
|
|
+ BeanUtil.mapToBean(
|
|
|
+ extra, SysImplementPlanVO.ToPage.class, true, CopyOptions.create());
|
|
|
+
|
|
|
+ Map<String, Object> skuInfo = toPage.getSkuInfo();
|
|
|
+ model.setSkuName(skuInfo.get("skuName").toString());
|
|
|
+ Map<String, Object> consignee = toPage.getConsigneeInfo();
|
|
|
+ model.setConsignee(consignee.get("consigneeName").toString());
|
|
|
+
|
|
|
+ UpmsType.ImplementPlanType planType = toPage.getPlanType();
|
|
|
+ model.setPlanType(planType.getDesc());
|
|
|
+ model.setPlanScore(toPage.getPlanScore().toString());
|
|
|
+
|
|
|
+ LocalDate planIssue = toPage.getPlanIssue();
|
|
|
+
|
|
|
+ model.setYear(String.valueOf(planIssue.getYear()));
|
|
|
+
|
|
|
+ String qtr;
|
|
|
+ if (UpmsType.ImplementPlanType.QRT.equals(planType)) {
|
|
|
+ int monthValue = planIssue.getMonthValue();
|
|
|
+ qtr = String.valueOf((monthValue + 2) / 3);
|
|
|
+ } else {
|
|
|
+ qtr = "";
|
|
|
+ }
|
|
|
+ model.setQuarter(qtr);
|
|
|
+ model.setPlanId(item.getId().toString());
|
|
|
+ // model.setCheckResult(toPage.getCheckResult() == null ? "" :
|
|
|
+ // toPage.getCheckResult() ? "通过" : "拒绝");
|
|
|
+ // model.setCheckMarks(StrUtil.isNotBlank(toPage.getCheckMessage()) ?
|
|
|
+ // toPage.getCheckMessage() : "");
|
|
|
+
|
|
|
+ return model;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ return collect;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出计划详情
|
|
|
+ *
|
|
|
+ * @param query 查询条件
|
|
|
+ * @param user 操作人
|
|
|
+ * @return 详情信息
|
|
|
+ */
|
|
|
+ public List<PlanDetailsExportModel> exportPlanDetails(
|
|
|
+ SysImplementPlanDetailsDTO.OnExport query, HnqzUser user) {
|
|
|
+
|
|
|
+ List<Integer> roles = SecurityUtils.getRoles();
|
|
|
+
|
|
|
+ UpmsState.ImplPlanDetailsState detailsState;
|
|
|
+ // 区域管理员
|
|
|
+ if (roles.contains(4)) {
|
|
|
+ detailsState = UpmsState.ImplPlanDetailsState.INIT;
|
|
|
+ }
|
|
|
+ // 商务管理员
|
|
|
+ else if (roles.contains(40)) {
|
|
|
+ detailsState = UpmsState.ImplPlanDetailsState.CKT1;
|
|
|
+ }
|
|
|
+ // 事业部分管领导
|
|
|
+ else if (roles.contains(41)) {
|
|
|
+ detailsState = UpmsState.ImplPlanDetailsState.CKT2;
|
|
|
+ } else {
|
|
|
+ throw new BizException("当前角色没有导出权限");
|
|
|
+ }
|
|
|
|
|
|
- UpmsState.ImplPlanDetailsState detailsState;
|
|
|
- // 区域管理员
|
|
|
- if (roles.contains(4)) {
|
|
|
- detailsState = UpmsState.ImplPlanDetailsState.INIT;
|
|
|
- }
|
|
|
- // 商务管理员
|
|
|
- else if (roles.contains(40)) {
|
|
|
- detailsState = UpmsState.ImplPlanDetailsState.CKT1;
|
|
|
- }
|
|
|
- // 事业部分管领导
|
|
|
- else if (roles.contains(41)) {
|
|
|
- detailsState = UpmsState.ImplPlanDetailsState.CKT2;
|
|
|
- } else {
|
|
|
- throw new BizException("当前角色没有导出权限");
|
|
|
- }
|
|
|
+ // 获取当前人操作的所有可见企业
|
|
|
+ List<Long> entIds = listVisibleEntIds(user);
|
|
|
|
|
|
- // 获取当前人操作的所有可见企业
|
|
|
- List<Long> entIds = listVisibleEntIds(user);
|
|
|
-
|
|
|
- if (CollUtil.isEmpty(entIds)) {
|
|
|
- throw new BizException("操作人未分配管理区域");
|
|
|
- }
|
|
|
+ if (CollUtil.isEmpty(entIds)) {
|
|
|
+ throw new BizException("操作人未分配管理区域");
|
|
|
+ }
|
|
|
|
|
|
- // 获取所见区域下的所有服务上
|
|
|
- List<SysDept> depts = deptService.listByIds(entIds);
|
|
|
- // 过滤出服务
|
|
|
- Set<Integer> serviceIds = depts.stream().filter(d -> d.getLevel() == 4).mapToInt(SysDept::getDeptId).boxed().collect(Collectors.toSet());
|
|
|
- if (CollUtil.isEmpty(serviceIds)) {
|
|
|
- throw new BizException("操作人所在区域不存在服务商");
|
|
|
- }
|
|
|
+ // 获取所见区域下的所有服务上
|
|
|
+ List<SysDept> depts = deptService.listByIds(entIds);
|
|
|
+ // 过滤出服务
|
|
|
+ Set<Integer> serviceIds =
|
|
|
+ depts.stream()
|
|
|
+ .filter(d -> d.getLevel() == 4)
|
|
|
+ .mapToInt(SysDept::getDeptId)
|
|
|
+ .boxed()
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ if (CollUtil.isEmpty(serviceIds)) {
|
|
|
+ throw new BizException("操作人所在区域不存在服务商");
|
|
|
+ }
|
|
|
|
|
|
- List<SysImplementPlan> plans = implementPlanService.list(Wrappers.<SysImplementPlan>lambdaQuery()
|
|
|
+ List<SysImplementPlan> plans =
|
|
|
+ implementPlanService.list(
|
|
|
+ Wrappers.<SysImplementPlan>lambdaQuery()
|
|
|
.eq(SysImplementPlan::getPlanState, UpmsState.ImplementPlanState.PASSED)
|
|
|
.in(SysImplementPlan::getConsigneeId, serviceIds));
|
|
|
|
|
|
- if (CollUtil.isEmpty(plans)) {
|
|
|
- throw new BizException("没有查询到服务计划");
|
|
|
- }
|
|
|
-
|
|
|
- Set<Integer> planIds = plans.stream().mapToInt(SysImplementPlan::getPlanId).boxed().collect(Collectors.toSet());
|
|
|
+ if (CollUtil.isEmpty(plans)) {
|
|
|
+ throw new BizException("没有查询到服务计划");
|
|
|
+ }
|
|
|
|
|
|
+ Set<Integer> planIds =
|
|
|
+ plans.stream().mapToInt(SysImplementPlan::getPlanId).boxed().collect(Collectors.toSet());
|
|
|
|
|
|
- List<SysImplPlanDetails> details = implPlanDetailsService.list(Wrappers.<SysImplPlanDetails>lambdaQuery()
|
|
|
+ List<SysImplPlanDetails> details =
|
|
|
+ implPlanDetailsService.list(
|
|
|
+ Wrappers.<SysImplPlanDetails>lambdaQuery()
|
|
|
.eq(SysImplPlanDetails::getDetailsState, detailsState)
|
|
|
.in(SysImplPlanDetails::getPlanId, planIds));
|
|
|
|
|
|
- if (CollUtil.isEmpty(details)) {
|
|
|
- throw new BizException("计划尚未拆解");
|
|
|
- }
|
|
|
-
|
|
|
- Set<Integer> detailsIds = details.stream().mapToInt(SysImplPlanDetails::getDetailsId).boxed().collect(Collectors.toSet());
|
|
|
-
|
|
|
- List<SysImplPlanDetailsItem> detailsItems = implPlanDetailsItemService.list(Wrappers.<SysImplPlanDetailsItem>lambdaQuery().in(SysImplPlanDetailsItem::getDetailsId, detailsIds));
|
|
|
-
|
|
|
- if (CollUtil.isEmpty(detailsItems)) {
|
|
|
- throw new BizException("计划详情拆解信息不存在");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- Map<Integer, SysImplementPlan> planId2PlanMap = plans.stream().collect(Collectors.toMap(SysImplementPlan::getPlanId, Function.identity()));
|
|
|
-
|
|
|
- List<PlanDetailsExportModel> collect = details.stream().map(d -> {
|
|
|
- PlanDetailsExportModel model = new PlanDetailsExportModel();
|
|
|
- model.setDetailsId(d.getDetailsId().toString());
|
|
|
- // model.setConsignee();
|
|
|
- SysImplementPlan plan = planId2PlanMap.get(d.getPlanId());
|
|
|
-
|
|
|
- SysDept dept = deptService.getById(plan.getConsignorId());
|
|
|
- model.setConsignor(dept == null ? "" : dept.getName());
|
|
|
- model.setPlanName(plan.getPlanName());
|
|
|
-
|
|
|
- SysDept dept1 = deptService.getById(plan.getConsigneeId());
|
|
|
- model.setConsignee(dept1 == null ? "" : dept1.getName());
|
|
|
-
|
|
|
- String issue = DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_PATTERN).format(plan.getPlanIssue());
|
|
|
- String expiry = DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_PATTERN).format(plan.getPlanExpiry());
|
|
|
- model.setPeriod(issue + "~" + expiry);
|
|
|
-
|
|
|
-
|
|
|
- List<SysImplPlanDetailsItem> items = implPlanDetailsItemService.list(Wrappers.<SysImplPlanDetailsItem>lambdaQuery().eq(SysImplPlanDetailsItem::getDetailsId, d.getDetailsId()));
|
|
|
-
|
|
|
- StringBuilder summary = new StringBuilder();
|
|
|
-
|
|
|
- items.forEach(i -> {
|
|
|
- summary.append("[");
|
|
|
- summary.append("服务名称:【").append(i.getTaskTypeName()).append("】");
|
|
|
- summary.append("服务次数:【").append(i.getQty()).append("】");
|
|
|
- summary.append("单项积分:【").append(i.getScore()).append("】");
|
|
|
- summary.append("服务小记:【").append(i.getSubtotal()).append("】");
|
|
|
- summary.append("]\n");
|
|
|
- });
|
|
|
-
|
|
|
- model.setSummary(summary.toString());
|
|
|
- model.setCurrentState(d.getDetailsState().getState());
|
|
|
- model.setTotal(plan.getPlanScore().toString());
|
|
|
-
|
|
|
- return model;
|
|
|
-
|
|
|
-
|
|
|
- }).collect(Collectors.toList());
|
|
|
-
|
|
|
-
|
|
|
- return collect;
|
|
|
-
|
|
|
+ if (CollUtil.isEmpty(details)) {
|
|
|
+ throw new BizException("计划尚未拆解");
|
|
|
}
|
|
|
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public List<Map<String, String>> batchCheckPlanDetails(List<SysImplementPlanDetailsDTO.OnBatchCheck> resource, HnqzUser user) {
|
|
|
-
|
|
|
-
|
|
|
- // 上锁
|
|
|
- Set<String> cacheKeySet = resource.stream().map(res -> "lock:plan:details:check:batch:" + res.getDetailsId()).collect(Collectors.toSet());
|
|
|
-
|
|
|
- List<String> lockKey = new ArrayList<>(resource.size());
|
|
|
-
|
|
|
- try {
|
|
|
+ Set<Integer> detailsIds =
|
|
|
+ details.stream()
|
|
|
+ .mapToInt(SysImplPlanDetails::getDetailsId)
|
|
|
+ .boxed()
|
|
|
+ .collect(Collectors.toSet());
|
|
|
|
|
|
- cacheKeySet.forEach(key -> {
|
|
|
- boolean locked = Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(key, IdUtil.fastUUID(), 10, TimeUnit.MINUTES));
|
|
|
+ List<SysImplPlanDetailsItem> detailsItems =
|
|
|
+ implPlanDetailsItemService.list(
|
|
|
+ Wrappers.<SysImplPlanDetailsItem>lambdaQuery()
|
|
|
+ .in(SysImplPlanDetailsItem::getDetailsId, detailsIds));
|
|
|
|
|
|
- if (!locked) {
|
|
|
- throw new BizException("有在途的操作,请稍后");
|
|
|
- }
|
|
|
- log.info("批量操作加锁:{} =====================================", key);
|
|
|
- lockKey.add(key);
|
|
|
-
|
|
|
- });
|
|
|
+ if (CollUtil.isEmpty(detailsItems)) {
|
|
|
+ throw new BizException("计划详情拆解信息不存在");
|
|
|
+ }
|
|
|
|
|
|
- // 校验
|
|
|
- List<Map<String, String>> errorList = this.checkDataOnBatchCheckDetails(resource);
|
|
|
+ Map<Integer, SysImplementPlan> planId2PlanMap =
|
|
|
+ plans.stream().collect(Collectors.toMap(SysImplementPlan::getPlanId, Function.identity()));
|
|
|
+
|
|
|
+ List<PlanDetailsExportModel> collect =
|
|
|
+ details.stream()
|
|
|
+ .map(
|
|
|
+ d -> {
|
|
|
+ PlanDetailsExportModel model = new PlanDetailsExportModel();
|
|
|
+ model.setDetailsId(d.getDetailsId().toString());
|
|
|
+ // model.setConsignee();
|
|
|
+ SysImplementPlan plan = planId2PlanMap.get(d.getPlanId());
|
|
|
+
|
|
|
+ SysDept dept = deptService.getById(plan.getConsignorId());
|
|
|
+ model.setConsignor(dept == null ? "" : dept.getName());
|
|
|
+ model.setPlanName(plan.getPlanName());
|
|
|
+
|
|
|
+ SysDept dept1 = deptService.getById(plan.getConsigneeId());
|
|
|
+ model.setConsignee(dept1 == null ? "" : dept1.getName());
|
|
|
+
|
|
|
+ String issue =
|
|
|
+ DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_PATTERN)
|
|
|
+ .format(plan.getPlanIssue());
|
|
|
+ String expiry =
|
|
|
+ DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_PATTERN)
|
|
|
+ .format(plan.getPlanExpiry());
|
|
|
+ model.setPeriod(issue + "~" + expiry);
|
|
|
+
|
|
|
+ List<SysImplPlanDetailsItem> items =
|
|
|
+ implPlanDetailsItemService.list(
|
|
|
+ Wrappers.<SysImplPlanDetailsItem>lambdaQuery()
|
|
|
+ .eq(SysImplPlanDetailsItem::getDetailsId, d.getDetailsId()));
|
|
|
+
|
|
|
+ StringBuilder summary = new StringBuilder();
|
|
|
+
|
|
|
+ items.forEach(
|
|
|
+ i -> {
|
|
|
+ summary.append("[");
|
|
|
+ summary.append("服务名称:【").append(i.getTaskTypeName()).append("】");
|
|
|
+ summary.append("服务次数:【").append(i.getQty()).append("】");
|
|
|
+ summary.append("单项积分:【").append(i.getScore()).append("】");
|
|
|
+ summary.append("服务小记:【").append(i.getSubtotal()).append("】");
|
|
|
+ summary.append("]\n");
|
|
|
+ });
|
|
|
+
|
|
|
+ model.setSummary(summary.toString());
|
|
|
+ model.setCurrentState(d.getDetailsState().getState());
|
|
|
+ model.setTotal(plan.getPlanScore().toString());
|
|
|
+
|
|
|
+ return model;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ return collect;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public List<Map<String, String>> batchCheckPlanDetails(
|
|
|
+ List<SysImplementPlanDetailsDTO.OnBatchCheck> resource, HnqzUser user) {
|
|
|
+
|
|
|
+ // 上锁
|
|
|
+ Set<String> cacheKeySet =
|
|
|
+ resource.stream()
|
|
|
+ .map(res -> "lock:plan:details:check:batch:" + res.getDetailsId())
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ List<String> lockKey = new ArrayList<>(resource.size());
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ cacheKeySet.forEach(
|
|
|
+ key -> {
|
|
|
+ boolean locked =
|
|
|
+ Boolean.TRUE.equals(
|
|
|
+ redisTemplate
|
|
|
+ .opsForValue()
|
|
|
+ .setIfAbsent(key, IdUtil.fastUUID(), 10, TimeUnit.MINUTES));
|
|
|
|
|
|
- if (CollUtil.isNotEmpty(errorList)) {
|
|
|
- return errorList;
|
|
|
+ if (!locked) {
|
|
|
+ throw new BizException("有在途的操作,请稍后");
|
|
|
}
|
|
|
+ log.info("批量操作加锁:{} =====================================", key);
|
|
|
+ lockKey.add(key);
|
|
|
+ });
|
|
|
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
- String username = user.getUsername();
|
|
|
- List<SysImplPlanDetails> det = resource.stream().map(res -> {
|
|
|
+ // 校验
|
|
|
+ List<Map<String, String>> errorList = this.checkDataOnBatchCheckDetails(resource);
|
|
|
|
|
|
-
|
|
|
- boolean result = "通过".equals(res.getResult());
|
|
|
- String msg = res.getMsg();
|
|
|
- Integer detailsId = res.getDetailsId();
|
|
|
-
|
|
|
- SysImplPlanDetails details = new SysImplPlanDetails();
|
|
|
- details.setDetailsId(detailsId);
|
|
|
-
|
|
|
- UpmsState.ImplPlanDetailsState implPlanDetailsState = Enum.valueOf(UpmsState.ImplPlanDetailsState.class, res.getCurrentState());
|
|
|
- switch (implPlanDetailsState) {
|
|
|
- case INIT:
|
|
|
- details.setDetailsState(result ? UpmsState.ImplPlanDetailsState.CKT1 : UpmsState.ImplPlanDetailsState.REJECTED);
|
|
|
+ if (CollUtil.isNotEmpty(errorList)) {
|
|
|
+ return errorList;
|
|
|
+ }
|
|
|
+
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ String username = user.getUsername();
|
|
|
+ List<SysImplPlanDetails> det =
|
|
|
+ resource.stream()
|
|
|
+ .map(
|
|
|
+ res -> {
|
|
|
+ boolean result = "通过".equals(res.getResult());
|
|
|
+ String msg = res.getMsg();
|
|
|
+ Integer detailsId = res.getDetailsId();
|
|
|
+
|
|
|
+ SysImplPlanDetails details = new SysImplPlanDetails();
|
|
|
+ details.setDetailsId(detailsId);
|
|
|
+
|
|
|
+ UpmsState.ImplPlanDetailsState implPlanDetailsState =
|
|
|
+ Enum.valueOf(UpmsState.ImplPlanDetailsState.class, res.getCurrentState());
|
|
|
+ switch (implPlanDetailsState) {
|
|
|
+ case INIT:
|
|
|
+ details.setDetailsState(
|
|
|
+ result
|
|
|
+ ? UpmsState.ImplPlanDetailsState.CKT1
|
|
|
+ : UpmsState.ImplPlanDetailsState.REJECTED);
|
|
|
details.setCktRes1(result);
|
|
|
details.setCktMsg1(msg);
|
|
|
details.setCktTime1(now);
|
|
|
details.setCktName1(username);
|
|
|
break;
|
|
|
|
|
|
- case CKT1:
|
|
|
- details.setDetailsState(result ? UpmsState.ImplPlanDetailsState.CKT2 : UpmsState.ImplPlanDetailsState.REJECTED);
|
|
|
+ case CKT1:
|
|
|
+ details.setDetailsState(
|
|
|
+ result
|
|
|
+ ? UpmsState.ImplPlanDetailsState.CKT2
|
|
|
+ : UpmsState.ImplPlanDetailsState.REJECTED);
|
|
|
details.setCktRes2(result);
|
|
|
details.setCktMsg2(msg);
|
|
|
details.setCktTime2(now);
|
|
|
details.setCktName2(username);
|
|
|
break;
|
|
|
- case CKT2:
|
|
|
- details.setDetailsState(result ? UpmsState.ImplPlanDetailsState.PASSED : UpmsState.ImplPlanDetailsState.REJECTED);
|
|
|
+ case CKT2:
|
|
|
+ details.setDetailsState(
|
|
|
+ result
|
|
|
+ ? UpmsState.ImplPlanDetailsState.PASSED
|
|
|
+ : UpmsState.ImplPlanDetailsState.REJECTED);
|
|
|
details.setCktRes3(result);
|
|
|
details.setCktMsg3(msg);
|
|
|
details.setCktTime3(now);
|
|
|
details.setCktName3(username);
|
|
|
break;
|
|
|
- default:
|
|
|
+ default:
|
|
|
throw new BizException("当前状态不支持审核");
|
|
|
+ }
|
|
|
+ details.setUpdateBy(username);
|
|
|
+ details.setUpdateTime(now);
|
|
|
|
|
|
- }
|
|
|
- details.setUpdateBy(username);
|
|
|
- details.setUpdateTime(now);
|
|
|
-
|
|
|
- return details;
|
|
|
+ return details;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
+ implPlanDetailsService.updateBatchById(det);
|
|
|
|
|
|
- }).collect(Collectors.toList());
|
|
|
+ return Collections.emptyList();
|
|
|
|
|
|
- implPlanDetailsService.updateBatchById(det);
|
|
|
-
|
|
|
-
|
|
|
- return Collections.emptyList();
|
|
|
-
|
|
|
-
|
|
|
- } finally {
|
|
|
- if (CollUtil.isNotEmpty(lockKey)) {
|
|
|
- redisTemplate.delete(lockKey);
|
|
|
- }
|
|
|
- }
|
|
|
+ } finally {
|
|
|
+ if (CollUtil.isNotEmpty(lockKey)) {
|
|
|
+ redisTemplate.delete(lockKey);
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- private List<Map<String, String>> checkDataOnBatchCheckDetails(List<SysImplementPlanDetailsDTO.OnBatchCheck> resource) {
|
|
|
-
|
|
|
- List<Map<String, String>> errorList = new LinkedList<>();
|
|
|
+ private List<Map<String, String>> checkDataOnBatchCheckDetails(
|
|
|
+ List<SysImplementPlanDetailsDTO.OnBatchCheck> resource) {
|
|
|
|
|
|
- int size = resource.size();
|
|
|
+ List<Map<String, String>> errorList = new LinkedList<>();
|
|
|
|
|
|
- if (size == 0) {
|
|
|
- Map<String, String> errorMap = new HashMap<>(2);
|
|
|
- errorMap.put("idx", "1");
|
|
|
- errorMap.put("errorMsg", "空表单不支持审核");
|
|
|
- errorList.add(errorMap);
|
|
|
- return errorList;
|
|
|
- }
|
|
|
+ int size = resource.size();
|
|
|
|
|
|
+ if (size == 0) {
|
|
|
+ Map<String, String> errorMap = new HashMap<>(2);
|
|
|
+ errorMap.put("idx", "1");
|
|
|
+ errorMap.put("errorMsg", "空表单不支持审核");
|
|
|
+ errorList.add(errorMap);
|
|
|
+ return errorList;
|
|
|
+ }
|
|
|
|
|
|
- Map<Integer, List<SysImplementPlanDetailsDTO.OnBatchCheck>> detailsId2batchCheck = resource.stream().collect(Collectors.groupingBy(SysImplementPlanDetailsDTO.OnBatchCheck::getDetailsId));
|
|
|
-
|
|
|
+ Map<Integer, List<SysImplementPlanDetailsDTO.OnBatchCheck>> detailsId2batchCheck =
|
|
|
+ resource.stream()
|
|
|
+ .collect(Collectors.groupingBy(SysImplementPlanDetailsDTO.OnBatchCheck::getDetailsId));
|
|
|
|
|
|
- for (int i = 0; i < size; i++) {
|
|
|
+ for (int i = 0; i < size; i++) {
|
|
|
|
|
|
+ StringBuilder errorMsg = new StringBuilder();
|
|
|
|
|
|
- StringBuilder errorMsg = new StringBuilder();
|
|
|
+ SysImplementPlanDetailsDTO.OnBatchCheck onBatchCheck = resource.get(i);
|
|
|
|
|
|
- SysImplementPlanDetailsDTO.OnBatchCheck onBatchCheck = resource.get(i);
|
|
|
+ String result = onBatchCheck.getResult();
|
|
|
+ String msg = onBatchCheck.getMsg();
|
|
|
+ String currentState = onBatchCheck.getCurrentState();
|
|
|
+ Integer detailsId = onBatchCheck.getDetailsId();
|
|
|
|
|
|
- String result = onBatchCheck.getResult();
|
|
|
- String msg = onBatchCheck.getMsg();
|
|
|
- String currentState = onBatchCheck.getCurrentState();
|
|
|
- Integer detailsId = onBatchCheck.getDetailsId();
|
|
|
+ // 校验空值
|
|
|
+ if (StrUtil.hasBlank(result, currentState) || detailsId == null) {
|
|
|
+ errorMsg.append("存在未填写的内容;");
|
|
|
+ }
|
|
|
|
|
|
- // 校验空值
|
|
|
- if (StrUtil.hasBlank(result, currentState) || detailsId == null) {
|
|
|
- errorMsg.append("存在未填写的内容;");
|
|
|
- }
|
|
|
+ if (!StrUtil.equalsAny(currentState, "CKT2", "CKT1", "INIT")) {
|
|
|
+ errorMsg.append("当前审核节点(系统用)值错误,只能是INIT/CKT1/CKT2;");
|
|
|
+ }
|
|
|
|
|
|
- if (!StrUtil.equalsAny(currentState, "CKT2", "CKT1", "INIT")) {
|
|
|
- errorMsg.append("当前审核节点(系统用)值错误,只能是INIT/CKT1/CKT2;");
|
|
|
- }
|
|
|
+ List<SysImplementPlanDetailsDTO.OnBatchCheck> onBatchChecks =
|
|
|
+ detailsId2batchCheck.get(onBatchCheck.getDetailsId());
|
|
|
+ if (CollUtil.isNotEmpty(onBatchChecks) && onBatchChecks.size() > 1) {
|
|
|
+ errorMsg.append("表单中存在重复的详情ID;");
|
|
|
+ }
|
|
|
|
|
|
- List<SysImplementPlanDetailsDTO.OnBatchCheck> onBatchChecks = detailsId2batchCheck.get(onBatchCheck.getDetailsId());
|
|
|
- if (CollUtil.isNotEmpty(onBatchChecks) && onBatchChecks.size() > 1) {
|
|
|
- errorMsg.append("表单中存在重复的详情ID;");
|
|
|
- }
|
|
|
+ if (!StrUtil.equalsAny(result, "通过", "拒绝")) {
|
|
|
+ errorMsg.append("审核结果只能是通过/拒绝;");
|
|
|
+ }
|
|
|
|
|
|
- if (!StrUtil.equalsAny(result, "通过", "拒绝")) {
|
|
|
- errorMsg.append("审核结果只能是通过/拒绝;");
|
|
|
- }
|
|
|
+ if ("拒绝".equals(result) && StrUtil.isBlank(msg)) {
|
|
|
+ errorMsg.append("审核信息必填;");
|
|
|
+ }
|
|
|
|
|
|
- if ("拒绝".equals(result) && StrUtil.isBlank(msg)) {
|
|
|
- errorMsg.append("审核信息必填;");
|
|
|
- }
|
|
|
-
|
|
|
- if (StrUtil.isNotBlank(errorMsg)) {
|
|
|
- Map<String, String> errorMap = new HashMap<>(2);
|
|
|
- String idx = String.valueOf(i + 1);
|
|
|
- errorMap.put("idx", idx);
|
|
|
- errorMap.put("errorMsg", errorMsg.toString());
|
|
|
- errorList.add(errorMap);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- return errorList;
|
|
|
+ if (StrUtil.isNotBlank(errorMsg)) {
|
|
|
+ Map<String, String> errorMap = new HashMap<>(2);
|
|
|
+ String idx = String.valueOf(i + 1);
|
|
|
+ errorMap.put("idx", idx);
|
|
|
+ errorMap.put("errorMsg", errorMsg.toString());
|
|
|
+ errorList.add(errorMap);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public Boolean batchCheckPlans(SysImplementPlanDTO.OnBatchCheck resource, HnqzUser user) {
|
|
|
-
|
|
|
- Boolean result = resource.getResult();
|
|
|
-
|
|
|
- if (!result && StrUtil.isBlank(resource.getMsg())) {
|
|
|
- throw new BizException("审核拒绝时,审核意见必填");
|
|
|
- }
|
|
|
-
|
|
|
- Boolean res = resource.getResult();
|
|
|
- String msg = resource.getMsg();
|
|
|
- resource.getPlanIds().forEach(id -> {
|
|
|
+ return errorList;
|
|
|
+ }
|
|
|
|
|
|
- SysImplementPlanDTO.OnCheck check = new SysImplementPlanDTO.OnCheck();
|
|
|
- check.setPlanId(id);
|
|
|
- check.setResult(res);
|
|
|
- check.setMsg(msg);
|
|
|
- this.checkPlan(check, user);
|
|
|
- });
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean batchCheckPlans(SysImplementPlanDTO.OnBatchCheck resource, HnqzUser user) {
|
|
|
|
|
|
+ Boolean result = resource.getResult();
|
|
|
|
|
|
- return true;
|
|
|
+ if (!result && StrUtil.isBlank(resource.getMsg())) {
|
|
|
+ throw new BizException("审核拒绝时,审核意见必填");
|
|
|
}
|
|
|
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public Boolean updatePlan(SysImplementPlanDTO.OnUpdate resource, HnqzUser user) {
|
|
|
-
|
|
|
- SysImplementPlan plan = implementPlanService.getById(resource.getPlanId());
|
|
|
-
|
|
|
- // 年度计划,只要是状态不为通过,就可以编辑
|
|
|
- if (UpmsType.ImplementPlanType.ANN.equals(plan.getPlanType())) {
|
|
|
- if (UpmsState.ImplementPlanState.PASSED.equals(plan.getPlanState())) {
|
|
|
- throw new BizException("当前执行计划已经审核通过了,不能修改");
|
|
|
- }
|
|
|
- }
|
|
|
- // 季度计划
|
|
|
- else {
|
|
|
-
|
|
|
- // 其他下发的包 非通过才能编辑
|
|
|
- if (plan.getParentId() != 0 && UpmsState.ImplementPlanState.PASSED.equals(plan.getPlanState())) {
|
|
|
- throw new BizException("当前执行计划已经审核通过了,不能修改");
|
|
|
- }
|
|
|
- // 运营发放的,只要没有分解的就可以
|
|
|
- else {
|
|
|
- int count = implementPlanService.count(Wrappers.<SysImplementPlan>lambdaQuery().eq(SysImplementPlan::getParentId, resource.getPlanId()));
|
|
|
-
|
|
|
- if (count > 0) {
|
|
|
- throw new BizException("当前执行计划已经分发通过了,不能修改");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ Boolean res = resource.getResult();
|
|
|
+ String msg = resource.getMsg();
|
|
|
+ resource
|
|
|
+ .getPlanIds()
|
|
|
+ .forEach(
|
|
|
+ id -> {
|
|
|
+ SysImplementPlanDTO.OnCheck check = new SysImplementPlanDTO.OnCheck();
|
|
|
+ check.setPlanId(id);
|
|
|
+ check.setResult(res);
|
|
|
+ check.setMsg(msg);
|
|
|
+ this.checkPlan(check, user);
|
|
|
+ });
|
|
|
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- boolean dump = implementPlanService.dupName(resource.getPlanName(), user.getDeptId(), Collections.singletonList(resource.getPlanId()));
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean updatePlan(SysImplementPlanDTO.OnUpdate resource, HnqzUser user) {
|
|
|
|
|
|
- if (dump) {
|
|
|
- throw new BizException(String.format("计划名称【%s】已存在,请更正", resource.getPlanName()));
|
|
|
- }
|
|
|
+ SysImplementPlan plan = implementPlanService.getById(resource.getPlanId());
|
|
|
|
|
|
- SysImplementPlan updated = BeanUtil.copyProperties(resource, SysImplementPlan.class);
|
|
|
- // 当前状态
|
|
|
- UpmsState.ImplementPlanState currentState = plan.getPlanState();
|
|
|
-
|
|
|
- UpmsState.ImplementPlanState targetState;
|
|
|
- if (UpmsState.ImplementPlanState.REJECTED.equals(currentState)) {
|
|
|
- targetState = UpmsState.ImplementPlanState.INIT;
|
|
|
- } else {
|
|
|
- targetState = currentState;
|
|
|
+ // 年度计划,只要是状态不为通过,就可以编辑
|
|
|
+ if (UpmsType.ImplementPlanType.ANN.equals(plan.getPlanType())) {
|
|
|
+ if (UpmsState.ImplementPlanState.PASSED.equals(plan.getPlanState())) {
|
|
|
+ throw new BizException("当前执行计划已经审核通过了,不能修改");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 季度计划
|
|
|
+ else {
|
|
|
+
|
|
|
+ // 其他下发的包 非通过才能编辑
|
|
|
+ if (plan.getParentId() != 0
|
|
|
+ && UpmsState.ImplementPlanState.PASSED.equals(plan.getPlanState())) {
|
|
|
+ throw new BizException("当前执行计划已经审核通过了,不能修改");
|
|
|
+ }
|
|
|
+ // 运营发放的,只要没有分解的就可以
|
|
|
+ else {
|
|
|
+ int count =
|
|
|
+ implementPlanService.count(
|
|
|
+ Wrappers.<SysImplementPlan>lambdaQuery()
|
|
|
+ .eq(SysImplementPlan::getParentId, resource.getPlanId()));
|
|
|
+
|
|
|
+ if (count > 0) {
|
|
|
+ throw new BizException("当前执行计划已经分发通过了,不能修改");
|
|
|
}
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- updated.setAvailScore(resource.getPlanScore());
|
|
|
- updated.setPlanState(targetState);
|
|
|
- updated.setUpdateBy(user.getUsername());
|
|
|
- updated.setUpdateTime(LocalDateTime.now());
|
|
|
- implementPlanService.updatePlan(updated);
|
|
|
-
|
|
|
- // 更新父级包信息
|
|
|
- if (plan.getParentId() != 0) {
|
|
|
-
|
|
|
- String sql = "avail_score = avail_score +" + plan.getPlanScore() + "-" + resource.getPlanScore();
|
|
|
- String sql1 = "avail_score = avail_score -" + resource.getPlanScore();
|
|
|
+ boolean dump =
|
|
|
+ implementPlanService.dupName(
|
|
|
+ resource.getPlanName(),
|
|
|
+ user.getDeptId(),
|
|
|
+ Collections.singletonList(resource.getPlanId()));
|
|
|
|
|
|
- implementPlanService.update(Wrappers.<SysImplementPlan>lambdaUpdate()
|
|
|
- .eq(SysImplementPlan::getPlanId, plan.getParentId())
|
|
|
- .setSql(UpmsState.ImplementPlanState.REJECTED.equals(plan.getPlanState()) ? sql1 : sql)
|
|
|
- .set(SysImplementPlan::getUpdateTime, LocalDateTime.now())
|
|
|
- .set(SysImplementPlan::getUpdateBy, user.getUsername()));
|
|
|
+ if (dump) {
|
|
|
+ throw new BizException(String.format("计划名称【%s】已存在,请更正", resource.getPlanName()));
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ SysImplementPlan updated = BeanUtil.copyProperties(resource, SysImplementPlan.class);
|
|
|
+ // 当前状态
|
|
|
+ UpmsState.ImplementPlanState currentState = plan.getPlanState();
|
|
|
|
|
|
- return true;
|
|
|
+ UpmsState.ImplementPlanState targetState;
|
|
|
+ if (UpmsState.ImplementPlanState.REJECTED.equals(currentState)) {
|
|
|
+ targetState = UpmsState.ImplementPlanState.INIT;
|
|
|
+ } else {
|
|
|
+ targetState = currentState;
|
|
|
}
|
|
|
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public List<Map<String, String>> batchCheckPlansInfo(List<SysImplementPlanDTO.OnBatchCheckInfo> resource, HnqzUser user) {
|
|
|
+ updated.setAvailScore(resource.getPlanScore());
|
|
|
+ updated.setPlanState(targetState);
|
|
|
+ updated.setUpdateBy(user.getUsername());
|
|
|
+ updated.setUpdateTime(LocalDateTime.now());
|
|
|
+ implementPlanService.updatePlan(updated);
|
|
|
+
|
|
|
+ // 更新父级包信息
|
|
|
+ if (plan.getParentId() != 0) {
|
|
|
+
|
|
|
+ String sql =
|
|
|
+ "avail_score = avail_score +" + plan.getPlanScore() + "-" + resource.getPlanScore();
|
|
|
+ String sql1 = "avail_score = avail_score -" + resource.getPlanScore();
|
|
|
+
|
|
|
+ implementPlanService.update(
|
|
|
+ Wrappers.<SysImplementPlan>lambdaUpdate()
|
|
|
+ .eq(SysImplementPlan::getPlanId, plan.getParentId())
|
|
|
+ .setSql(
|
|
|
+ UpmsState.ImplementPlanState.REJECTED.equals(plan.getPlanState()) ? sql1 : sql)
|
|
|
+ .set(SysImplementPlan::getUpdateTime, LocalDateTime.now())
|
|
|
+ .set(SysImplementPlan::getUpdateBy, user.getUsername()));
|
|
|
+ }
|
|
|
|
|
|
- // 上锁
|
|
|
- Set<String> cacheKeySet = resource.stream().map(res -> "lock:plan:info:check:batch:" + res.getPlanId()).collect(Collectors.toSet());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- List<String> lockKey = new ArrayList<>(resource.size());
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public List<Map<String, String>> batchCheckPlansInfo(
|
|
|
+ List<SysImplementPlanDTO.OnBatchCheckInfo> resource, HnqzUser user) {
|
|
|
|
|
|
- try {
|
|
|
+ // 上锁
|
|
|
+ Set<String> cacheKeySet =
|
|
|
+ resource.stream()
|
|
|
+ .map(res -> "lock:plan:info:check:batch:" + res.getPlanId())
|
|
|
+ .collect(Collectors.toSet());
|
|
|
|
|
|
- cacheKeySet.forEach(key -> {
|
|
|
- boolean locked = Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(key, IdUtil.fastUUID(), 10, TimeUnit.MINUTES));
|
|
|
+ List<String> lockKey = new ArrayList<>(resource.size());
|
|
|
|
|
|
- if (!locked) {
|
|
|
- throw new BizException("有在途的操作,请稍后");
|
|
|
- }
|
|
|
- log.info("批量操作加锁:{} =====================================", key);
|
|
|
- lockKey.add(key);
|
|
|
+ try {
|
|
|
|
|
|
- });
|
|
|
+ cacheKeySet.forEach(
|
|
|
+ key -> {
|
|
|
+ boolean locked =
|
|
|
+ Boolean.TRUE.equals(
|
|
|
+ redisTemplate
|
|
|
+ .opsForValue()
|
|
|
+ .setIfAbsent(key, IdUtil.fastUUID(), 10, TimeUnit.MINUTES));
|
|
|
|
|
|
- // 校验
|
|
|
- List<Map<String, String>> errorList = this.checkDataOnBatchCheckPlanInfo(resource);
|
|
|
-
|
|
|
- if (CollUtil.isNotEmpty(errorList)) {
|
|
|
- return errorList;
|
|
|
+ if (!locked) {
|
|
|
+ throw new BizException("有在途的操作,请稍后");
|
|
|
}
|
|
|
+ log.info("批量操作加锁:{} =====================================", key);
|
|
|
+ lockKey.add(key);
|
|
|
+ });
|
|
|
|
|
|
- resource.forEach(res -> {
|
|
|
+ // 校验
|
|
|
+ List<Map<String, String>> errorList = this.checkDataOnBatchCheckPlanInfo(resource);
|
|
|
|
|
|
- boolean result = "通过".equals(res.getResult());
|
|
|
- String msg = res.getMsg();
|
|
|
-
|
|
|
- SysImplementPlanDTO.OnCheck r = new SysImplementPlanDTO.OnCheck();
|
|
|
- r.setPlanId(res.getPlanId());
|
|
|
- r.setResult(result);
|
|
|
- r.setMsg(msg);
|
|
|
-
|
|
|
- this.checkPlan(r, user);
|
|
|
-
|
|
|
- });
|
|
|
+ if (CollUtil.isNotEmpty(errorList)) {
|
|
|
+ return errorList;
|
|
|
+ }
|
|
|
|
|
|
- return Collections.emptyList();
|
|
|
+ resource.forEach(
|
|
|
+ res -> {
|
|
|
+ boolean result = "通过".equals(res.getResult());
|
|
|
+ String msg = res.getMsg();
|
|
|
|
|
|
+ SysImplementPlanDTO.OnCheck r = new SysImplementPlanDTO.OnCheck();
|
|
|
+ r.setPlanId(res.getPlanId());
|
|
|
+ r.setResult(result);
|
|
|
+ r.setMsg(msg);
|
|
|
|
|
|
- } finally {
|
|
|
- if (CollUtil.isNotEmpty(lockKey)) {
|
|
|
- redisTemplate.delete(lockKey);
|
|
|
- }
|
|
|
- }
|
|
|
+ this.checkPlan(r, user);
|
|
|
+ });
|
|
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
|
|
+ } finally {
|
|
|
+ if (CollUtil.isNotEmpty(lockKey)) {
|
|
|
+ redisTemplate.delete(lockKey);
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- private List<Map<String, String>> checkDataOnBatchCheckPlanInfo(List<SysImplementPlanDTO.OnBatchCheckInfo> resource) {
|
|
|
-
|
|
|
- List<Map<String, String>> errorList = new LinkedList<>();
|
|
|
-
|
|
|
- int size = resource.size();
|
|
|
-
|
|
|
- if (size == 0) {
|
|
|
- Map<String, String> errorMap = new HashMap<>(2);
|
|
|
- errorMap.put("idx", "1");
|
|
|
- errorMap.put("errorMsg", "空表单不支持审核");
|
|
|
- errorList.add(errorMap);
|
|
|
- return errorList;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- Map<Integer, List<SysImplementPlanDTO.OnBatchCheckInfo>> detailsId2batchCheck = resource.stream().collect(Collectors.groupingBy(SysImplementPlanDTO.OnBatchCheckInfo::getPlanId));
|
|
|
-
|
|
|
-
|
|
|
- for (int i = 0; i < size; i++) {
|
|
|
+ private List<Map<String, String>> checkDataOnBatchCheckPlanInfo(
|
|
|
+ List<SysImplementPlanDTO.OnBatchCheckInfo> resource) {
|
|
|
|
|
|
+ List<Map<String, String>> errorList = new LinkedList<>();
|
|
|
|
|
|
- StringBuilder errorMsg = new StringBuilder();
|
|
|
+ int size = resource.size();
|
|
|
|
|
|
- SysImplementPlanDTO.OnBatchCheckInfo onBatchCheck = resource.get(i);
|
|
|
+ if (size == 0) {
|
|
|
+ Map<String, String> errorMap = new HashMap<>(2);
|
|
|
+ errorMap.put("idx", "1");
|
|
|
+ errorMap.put("errorMsg", "空表单不支持审核");
|
|
|
+ errorList.add(errorMap);
|
|
|
+ return errorList;
|
|
|
+ }
|
|
|
|
|
|
- String result = onBatchCheck.getResult();
|
|
|
- String msg = onBatchCheck.getMsg();
|
|
|
- Integer planId = onBatchCheck.getPlanId();
|
|
|
+ Map<Integer, List<SysImplementPlanDTO.OnBatchCheckInfo>> detailsId2batchCheck =
|
|
|
+ resource.stream()
|
|
|
+ .collect(Collectors.groupingBy(SysImplementPlanDTO.OnBatchCheckInfo::getPlanId));
|
|
|
|
|
|
- // 校验空值
|
|
|
- if (StrUtil.hasBlank(result) || planId == null) {
|
|
|
- errorMsg.append("存在未填写的内容;");
|
|
|
- }
|
|
|
+ for (int i = 0; i < size; i++) {
|
|
|
|
|
|
+ StringBuilder errorMsg = new StringBuilder();
|
|
|
|
|
|
- List<SysImplementPlanDTO.OnBatchCheckInfo> onBatchChecks = detailsId2batchCheck.get(planId);
|
|
|
- if (CollUtil.isNotEmpty(onBatchChecks) && onBatchChecks.size() > 1) {
|
|
|
- errorMsg.append("表单中存在重复的详情ID;");
|
|
|
- }
|
|
|
-
|
|
|
- if (!StrUtil.equalsAny(result, "通过", "拒绝")) {
|
|
|
- errorMsg.append("审核结果只能是通过/拒绝;");
|
|
|
- }
|
|
|
+ SysImplementPlanDTO.OnBatchCheckInfo onBatchCheck = resource.get(i);
|
|
|
|
|
|
- if ("拒绝".equals(result) && StrUtil.isBlank(msg)) {
|
|
|
- errorMsg.append("审核信息必填;");
|
|
|
- }
|
|
|
+ String result = onBatchCheck.getResult();
|
|
|
+ String msg = onBatchCheck.getMsg();
|
|
|
+ Integer planId = onBatchCheck.getPlanId();
|
|
|
|
|
|
+ // 校验空值
|
|
|
+ if (StrUtil.hasBlank(result) || planId == null) {
|
|
|
+ errorMsg.append("存在未填写的内容;");
|
|
|
+ }
|
|
|
|
|
|
- if (StrUtil.isNotBlank(errorMsg)) {
|
|
|
- Map<String, String> errorMap = new HashMap<>(2);
|
|
|
- String idx = String.valueOf(i + 1);
|
|
|
- errorMap.put("idx", idx);
|
|
|
- errorMap.put("errorMsg", errorMsg.toString());
|
|
|
- errorList.add(errorMap);
|
|
|
- }
|
|
|
+ List<SysImplementPlanDTO.OnBatchCheckInfo> onBatchChecks = detailsId2batchCheck.get(planId);
|
|
|
+ if (CollUtil.isNotEmpty(onBatchChecks) && onBatchChecks.size() > 1) {
|
|
|
+ errorMsg.append("表单中存在重复的详情ID;");
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ if (!StrUtil.equalsAny(result, "通过", "拒绝")) {
|
|
|
+ errorMsg.append("审核结果只能是通过/拒绝;");
|
|
|
+ }
|
|
|
|
|
|
+ if ("拒绝".equals(result) && StrUtil.isBlank(msg)) {
|
|
|
+ errorMsg.append("审核信息必填;");
|
|
|
+ }
|
|
|
|
|
|
- return errorList;
|
|
|
+ if (StrUtil.isNotBlank(errorMsg)) {
|
|
|
+ Map<String, String> errorMap = new HashMap<>(2);
|
|
|
+ String idx = String.valueOf(i + 1);
|
|
|
+ errorMap.put("idx", idx);
|
|
|
+ errorMap.put("errorMsg", errorMsg.toString());
|
|
|
+ errorList.add(errorMap);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ return errorList;
|
|
|
+ }
|
|
|
}
|