|
@@ -0,0 +1,368 @@
|
|
|
|
+package com.qunzhixinxi.hnqz.admin.manager;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import cn.hutool.core.lang.tree.Tree;
|
|
|
|
+import cn.hutool.core.lang.tree.TreeNode;
|
|
|
|
+import cn.hutool.core.lang.tree.TreeUtil;
|
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
|
+import cn.hutool.core.util.ArrayUtil;
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.constant.UpmsState;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.dto.SysImplementPlanDTO;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.dto.SysImplementPlanDetailsDTO;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.SysDept;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.SysImplPlanDetails;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.SysImplPlanDetailsItem;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.SysImplementPlan;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.vo.SysImplementPlanVO;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.SysDeptService;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.SysImplPlanDetailsItemService;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.SysImplPlanDetailsService;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.SysImplementPlanService;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.WmDaDrugEntDrugtableService;
|
|
|
|
+import com.qunzhixinxi.hnqz.common.core.exception.BizException;
|
|
|
|
+import com.qunzhixinxi.hnqz.common.security.service.HnqzUser;
|
|
|
|
+import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
|
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Arrays;
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Set;
|
|
|
|
+import java.util.function.Function;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 执行计划管理器
|
|
|
|
+ *
|
|
|
|
+ * @author jimmy
|
|
|
|
+ * @version 1.0.0
|
|
|
|
+ * @date 2024/05/19 11:44
|
|
|
|
+ */
|
|
|
|
+@Slf4j
|
|
|
|
+@Service
|
|
|
|
+@AllArgsConstructor
|
|
|
|
+public class SysImplementPlanManager {
|
|
|
|
+
|
|
|
|
+ private final SysImplementPlanService implementPlanService;
|
|
|
|
+ private final SysImplPlanDetailsService implPlanDetailsService;
|
|
|
|
+ private final SysDeptService deptService;
|
|
|
|
+ private final SysImplPlanDetailsItemService implPlanDetailsItemService;
|
|
|
|
+ private final WmDaDrugEntDrugtableService drugEntDrugtableService;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 创建计划
|
|
|
|
+ *
|
|
|
|
+ * @param resource 计划信息
|
|
|
|
+ * @param operator 操作人
|
|
|
|
+ * @return 创建结果
|
|
|
|
+ */
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public Boolean createPlan(SysImplementPlanDTO.OnCreate resource, HnqzUser operator) {
|
|
|
|
+
|
|
|
|
+ String username = operator.getUsername();
|
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
|
+ SysImplementPlan plan = BeanUtil.copyProperties(resource, SysImplementPlan.class);
|
|
|
|
+ plan.setPlanState(UpmsState.ImplementPlanState.INIT);
|
|
|
|
+ plan.setConsignorId(operator.getDeptId());
|
|
|
|
+ plan.setCreateBy(username);
|
|
|
|
+ plan.setUpdateBy(username);
|
|
|
|
+ plan.setCreateTime(now);
|
|
|
|
+ plan.setUpdateTime(now);
|
|
|
|
+
|
|
|
|
+ return implementPlanService.createPlan(plan);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取计划分页
|
|
|
|
+ *
|
|
|
|
+ * @param query 查询条件
|
|
|
|
+ * @param operator 操作人
|
|
|
|
+ * @return 分页结果
|
|
|
|
+ */
|
|
|
|
+ public Page<?> pagePlans(SysImplementPlanDTO.OnPage query, HnqzUser operator) {
|
|
|
|
+
|
|
|
|
+ // 获取根目录分页
|
|
|
|
+ Page<SysImplementPlan> page = this.getPage(operator, query.getCurrent(), query.getSize(), query.getPlanName(),
|
|
|
|
+ query.getConsigneeId(), operator.getDeptId(), query.getPeriod());
|
|
|
|
+
|
|
|
|
+ List<SysImplementPlan> records = page.getRecords();
|
|
|
|
+
|
|
|
|
+ if (CollUtil.isEmpty(records)) {
|
|
|
|
+ return page;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 查询出子数据
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 获取承接人ID
|
|
|
|
+ Set<Integer> consigneeIds = records.stream().mapToInt(SysImplementPlan::getConsigneeId).boxed().collect(Collectors.toSet());
|
|
|
|
+
|
|
|
|
+ // 获取承接人
|
|
|
|
+ Map<Integer, SysDept> consigneeMap = deptService.mapConsignee(consigneeIds);
|
|
|
|
+
|
|
|
|
+ // 获取商品信息
|
|
|
|
+ List<Map<String, String>> skuList = drugEntDrugtableService.listDrugByDeptId(consigneeIds);
|
|
|
|
+ Map<Integer, Map<String, String>> skuMap = skuList.stream().collect(Collectors.toMap(sku -> Integer.valueOf(sku.get("drug_id")), Function.identity()));
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 封装返回结果
|
|
|
|
+ Page<Tree<Integer>> newPage = new Page<>(page.getCurrent(), page.getSize(), page.getTotal());
|
|
|
|
+ List<TreeNode<Integer>> toPages = getToPages(records, consigneeMap, skuMap);
|
|
|
|
+
|
|
|
|
+ // Map<Integer, List<TreeNode<Integer>>> collect = toPages.stream().collect(Collectors.groupingBy(TreeNode::getParentId));
|
|
|
|
+ //
|
|
|
|
+ // List<List<Tree<Integer>>> builds = new ArrayList<>(collect.size());
|
|
|
|
+ //for (Map.Entry<Integer, List<TreeNode<Integer>>> entry : collect.entrySet()){
|
|
|
|
+ // List<Tree<Integer>> build = TreeUtil.build(entry.getValue(), entry.getKey());
|
|
|
|
+ // builds.add(build);
|
|
|
|
+ //}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ newPage.setRecords(TreeUtil.build(toPages, 0));
|
|
|
|
+
|
|
|
|
+ return newPage;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<TreeNode<Integer>> getToPages(List<SysImplementPlan> records, Map<Integer, SysDept> consigneeMap, Map<Integer, Map<String, String>> skuMap) {
|
|
|
|
+ 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);
|
|
|
|
+
|
|
|
|
+ // 执行包总值
|
|
|
|
+ p.setExecScoreValue(0L);
|
|
|
|
+
|
|
|
|
+ // 产品信息
|
|
|
|
+ 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);
|
|
|
|
+
|
|
|
|
+ // 获取计划详情
|
|
|
|
+ SysImplPlanDetails one = implPlanDetailsService.getOne(Wrappers.<SysImplPlanDetails>lambdaQuery().eq(SysImplPlanDetails::getPlanId, record.getPlanId()));
|
|
|
|
+ p.setPlanDetailId(one != null ? one.getDetailsId() : null);
|
|
|
|
+
|
|
|
|
+ TreeNode<Integer> treeNode = new TreeNode<>();
|
|
|
|
+ treeNode.setId(p.getPlanId());
|
|
|
|
+ //treeNode.setParentId(p.getParentId());
|
|
|
|
+ treeNode.setParentId(0);
|
|
|
|
+ treeNode.setName(p.getPlanName());
|
|
|
|
+ treeNode.setWeight(p.getPlanId());
|
|
|
|
+ Map<String, Object> extra = BeanUtil.beanToMap(p);
|
|
|
|
+ treeNode.setExtra(extra);
|
|
|
|
+
|
|
|
|
+ return treeNode;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Page<SysImplementPlan> getPage(HnqzUser user,
|
|
|
|
+ Integer current,
|
|
|
|
+ Integer size,
|
|
|
|
+ String planName,
|
|
|
|
+ Integer consigneeId,
|
|
|
|
+ Integer consignorId,
|
|
|
|
+ LocalDate[] period) {
|
|
|
|
+
|
|
|
|
+ List<Integer> roleIds = SecurityUtils.getRoles();
|
|
|
|
+
|
|
|
|
+ LambdaQueryWrapper<SysImplementPlan> wrapper = Wrappers.<SysImplementPlan>lambdaQuery()
|
|
|
|
+ .like(StrUtil.isNotBlank(planName), SysImplementPlan::getPlanName, planName);
|
|
|
|
+
|
|
|
|
+ // 服务商管理员
|
|
|
|
+ if (roleIds.contains(37)){
|
|
|
|
+ wrapper.eq(SysImplementPlan::getConsigneeId, user.getDeptId());
|
|
|
|
+ } else {
|
|
|
|
+ wrapper.eq(SysImplementPlan::getParentId, 0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //LambdaQueryWrapper<SysImplementPlan> wrapper = Wrappers.<SysImplementPlan>lambdaQuery()
|
|
|
|
+ // .like(StrUtil.isNotBlank(planName), SysImplementPlan::getPlanName, planName)
|
|
|
|
+ // .eq(SysImplementPlan::getParentId, 0);
|
|
|
|
+ //.eq(consigneeId != null, SysImplementPlan::getConsigneeId, consigneeId)
|
|
|
|
+ //.eq(SysImplementPlan::getConsignorId, consignorId);
|
|
|
|
+
|
|
|
|
+ if (ArrayUtil.isNotEmpty(period) && period.length == 2) {
|
|
|
|
+ wrapper.between(SysImplementPlan::getCreateTime, period[0], period[1]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return implementPlanService.page(new Page<>(current, size), wrapper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 审核计划
|
|
|
|
+ *
|
|
|
|
+ * @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);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ 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) {
|
|
|
|
+ detailsMap = BeanUtil.beanToMap(details);
|
|
|
|
+
|
|
|
|
+ List<SysImplPlanDetailsItem> items = implPlanDetailsItemService.listDetailItems(details.getDetailsId());
|
|
|
|
+
|
|
|
|
+ detailsMap.put("items", CollUtil.isNotEmpty(items) ? items : Collections.emptyList());
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ detailsMap = Collections.emptyMap();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return detailsMap;
|
|
|
|
+ }
|
|
|
|
+}
|