|
@@ -0,0 +1,219 @@
|
|
|
+package com.qunzhixinxi.hnqz.admin.manager;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.constant.UpmsType.AreaType;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.SysCheckChainNodeCheckHistory;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.SysDept;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.SysUser;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.WmDaDrugEntDrugtable;
|
|
|
+import com.qunzhixinxi.hnqz.admin.controller.task.vo.TaskReqVO;
|
|
|
+import com.qunzhixinxi.hnqz.admin.controller.task.vo.TaskRespVO;
|
|
|
+import com.qunzhixinxi.hnqz.admin.controller.task.vo.TaskRespVO.ToDirectCheck;
|
|
|
+import com.qunzhixinxi.hnqz.admin.mapper.SysCheckChainNodeCheckHistoryMapper;
|
|
|
+import com.qunzhixinxi.hnqz.admin.mapper.WmTaskV2Mapper;
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.SysUserAreaService;
|
|
|
+import com.qunzhixinxi.hnqz.common.core.constant.CacheConstants;
|
|
|
+import com.qunzhixinxi.hnqz.common.security.service.HnqzUser;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.validation.Valid;
|
|
|
+import org.springframework.data.redis.core.ListOperations;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 任务管理器
|
|
|
+ *
|
|
|
+ * @author jimmy
|
|
|
+ * @date 2025-01-10 16:14
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public final class TaskManager {
|
|
|
+
|
|
|
+ @Resource private RedisTemplate redisTemplate;
|
|
|
+ @Resource private WmTaskV2Mapper taskMapper;
|
|
|
+ @Resource private SysUserAreaService userAreaService;
|
|
|
+ @Resource private SysCheckChainNodeCheckHistoryMapper checkChainNodeCheckHistoryMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询
|
|
|
+ *
|
|
|
+ * @param query 筛选参数
|
|
|
+ * @param user 操作人
|
|
|
+ */
|
|
|
+ public Page<TaskRespVO.ToDirectCheck> pageTaskToCheck(
|
|
|
+ @Valid TaskReqVO.OnPage query, HnqzUser user) {
|
|
|
+
|
|
|
+ // 获取vendor
|
|
|
+ List<Integer> vendorList = getVendorList(query.getVendorId(), user);
|
|
|
+
|
|
|
+ // 计算服务包查询周期
|
|
|
+ Map<String, LocalDate> pkgPeriod = this.calcPkgPeriod(query.getYear(), query.getQuarter());
|
|
|
+ LocalDate issueDate = pkgPeriod.get("issueDate");
|
|
|
+ LocalDate expiryDate = pkgPeriod.get("expiryDate");
|
|
|
+
|
|
|
+ LocalDateTime startTime = null;
|
|
|
+ LocalDateTime endTime = null;
|
|
|
+ LocalDate createTime = query.getCreateTime();
|
|
|
+ if (createTime != null) {
|
|
|
+ startTime = LocalDateTime.of(query.getCreateTime(), LocalTime.MIN);
|
|
|
+ endTime = LocalDateTime.of(query.getCreateTime(), LocalTime.MAX);
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<TaskRespVO.ToDirectCheck> page = new Page<>(query.getCurrent(), query.getSize());
|
|
|
+
|
|
|
+ taskMapper.pageDirectCheck(
|
|
|
+ page,
|
|
|
+ issueDate,
|
|
|
+ expiryDate,
|
|
|
+ startTime,
|
|
|
+ endTime,
|
|
|
+ query.getTaskTypeId(),
|
|
|
+ vendorList,
|
|
|
+ query.getSalesId(),
|
|
|
+ query.getProvAbbr(),
|
|
|
+ query.getNodeId());
|
|
|
+
|
|
|
+ return build(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 组装数据
|
|
|
+ private Page<TaskRespVO.ToDirectCheck> build(Page<TaskRespVO.ToDirectCheck> page) {
|
|
|
+
|
|
|
+ List<ToDirectCheck> records = page.getRecords();
|
|
|
+
|
|
|
+ if (CollUtil.isEmpty(records)) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ ListOperations operations = redisTemplate.opsForList();
|
|
|
+ // 从缓存中获取用户信息
|
|
|
+ List<SysUser> users = operations.range(CacheConstants.USER_KEY, 0, -1);
|
|
|
+ Map<Integer, SysUser> userMap =
|
|
|
+ users.stream().collect(Collectors.toMap(SysUser::getUserId, Function.identity()));
|
|
|
+
|
|
|
+ // 从缓存中获取企业信息
|
|
|
+ List<SysDept> depts = operations.range(CacheConstants.DEPT_KEY, 0, -1);
|
|
|
+ Map<Integer, SysDept> deptMap =
|
|
|
+ depts.stream().collect(Collectors.toMap(SysDept::getDeptId, Function.identity()));
|
|
|
+
|
|
|
+ // 从缓存中获取商品信息
|
|
|
+ List<WmDaDrugEntDrugtable> drugs = operations.range(CacheConstants.DRUG_KEY, 0, -1);
|
|
|
+ Map<String, WmDaDrugEntDrugtable> drugtableMap =
|
|
|
+ drugs.stream().collect(Collectors.toMap(WmDaDrugEntDrugtable::getId, Function.identity()));
|
|
|
+
|
|
|
+ List<Integer> taskIds =
|
|
|
+ records.stream()
|
|
|
+ .mapToInt(ToDirectCheck::getTaskId)
|
|
|
+ .distinct()
|
|
|
+ .sorted()
|
|
|
+ .boxed()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // List<Map<String, Object>> taskCheckHis =
|
|
|
+ // checkChainNodeCheckHistoryMapper.listTaskCheckHis(taskIds);
|
|
|
+ //
|
|
|
+ // Map<Long, List<Map<String, Object>>> his =
|
|
|
+ // taskCheckHis.stream().collect(Collectors.groupingBy(r -> (Long) r.get("target_id")));
|
|
|
+
|
|
|
+ records.forEach(
|
|
|
+ record -> {
|
|
|
+ SysUser sysUser = userMap.get(record.getTaskUserId());
|
|
|
+ SysDept dept = deptMap.get(record.getEntId());
|
|
|
+ WmDaDrugEntDrugtable drugtable = drugtableMap.get(record.getSkuId());
|
|
|
+
|
|
|
+ record.setSalesName(sysUser != null ? sysUser.getRealname() : "");
|
|
|
+ record.setEntName(dept.getName());
|
|
|
+ record.setSkuName(drugtable.getDrugnameTy());
|
|
|
+ record.setMahName(drugtable.getDrugEntName());
|
|
|
+
|
|
|
+ // 查询审核记录
|
|
|
+ // List<Map<String, Object>> maps = his.get((long) record.getTaskId());
|
|
|
+ // record.setCheckHistoryList(maps);
|
|
|
+ });
|
|
|
+
|
|
|
+ page.setRecords(records);
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取可见vendor
|
|
|
+ private List<Integer> getVendorList(Integer vendorId, HnqzUser user) {
|
|
|
+
|
|
|
+ // 指定查询企业
|
|
|
+ if (vendorId != null) {
|
|
|
+ return Collections.singletonList(vendorId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (user == null) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer userId = user.getId();
|
|
|
+ // int userId = 1;
|
|
|
+
|
|
|
+ return userAreaService.listUserDept((long) userId, AreaType.DISTRICT.getType()).stream()
|
|
|
+ .map(Long::intValue)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取当前节点
|
|
|
+ private List<Integer> getCurrentNodeList(Integer nodeId, Integer current, Integer size) {
|
|
|
+
|
|
|
+ Page<Integer> integerPage =
|
|
|
+ checkChainNodeCheckHistoryMapper.pageCurrentNodeList(new Page<>(current, size), nodeId);
|
|
|
+
|
|
|
+ return CollUtil.isEmpty(integerPage.getRecords())
|
|
|
+ ? Collections.emptyList()
|
|
|
+ : integerPage.getRecords();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算积分包周期
|
|
|
+ private Map<String, LocalDate> calcPkgPeriod(String yearStr, String quarterStr) {
|
|
|
+
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ LocalDate issue;
|
|
|
+ LocalDate expiry;
|
|
|
+ int year;
|
|
|
+ int month;
|
|
|
+ boolean annual = false;
|
|
|
+
|
|
|
+ // 没有参数 就查询当前日期的全年
|
|
|
+ if (StrUtil.isAllBlank(yearStr, quarterStr)) {
|
|
|
+ year = today.getYear();
|
|
|
+ month = 1;
|
|
|
+ annual = true;
|
|
|
+ } else {
|
|
|
+ year = StrUtil.isBlank(yearStr) ? today.getYear() : Integer.parseInt(yearStr);
|
|
|
+
|
|
|
+ if (StrUtil.isBlank(quarterStr)) {
|
|
|
+ month = 1;
|
|
|
+ annual = true;
|
|
|
+ } else {
|
|
|
+ month = getMonthValue(quarterStr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ issue = LocalDate.of(year, month, 1);
|
|
|
+ expiry = issue.plusMonths(annual ? 12 : 3).minusDays(1);
|
|
|
+ Map<String, LocalDate> pkgPeriod = new HashMap<>(2);
|
|
|
+ pkgPeriod.put("issueDate", issue);
|
|
|
+ pkgPeriod.put("expiryDate", expiry);
|
|
|
+ return pkgPeriod;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算季度开始月份
|
|
|
+ private int getMonthValue(String quarterStr) {
|
|
|
+ return Integer.parseInt(quarterStr) * 3 - 2;
|
|
|
+ }
|
|
|
+}
|