复制整年计划功能 (生成保养计划、保养工单数据)

This commit is contained in:
shih
2026-04-17 11:24:43 +08:00
parent 9c10887e2f
commit 3ef5c4e4c9
9 changed files with 192 additions and 16 deletions

View File

@@ -83,4 +83,12 @@ public class ByglController extends BaseController {
byglByfaService.orderAuditNotPass(id);
return BaseWebResult.success("审批成功");
}
@PostMapping("/copyFullYearData")
public BaseWebResult copyFullYearData() {
byglByfaService.copyFullYearData();
return BaseWebResult.success("复制成功");
}
}

View File

@@ -3,15 +3,19 @@ package com.lideeyunji.core.framework.enhance.example.report.bygl;
import com.lideeyunji.core.framework.config.aspect.enhance.model.EnhanceContext;
import com.lideeyunji.core.framework.config.aspect.enhance.plugin.AroundAdvicePlugin;
import com.lideeyunji.core.framework.mapper.ByglByfaMapper;
import com.lideeyunji.core.framework.mapper.ByglByjhMapper;
import com.lideeyunji.core.framework.utils.Func;
import com.lideeyunji.service.system.api.IApiDeptApi;
import com.lideeyunji.service.system.dto.DeptRespDTO;
import com.lideeyunji.tool.framework.common.constant.ByglConstant;
import com.lideeyunji.tool.framework.yunji.utils.lideeYunJiUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;
@@ -27,15 +31,54 @@ public class ByglBygdPlugin implements AroundAdvicePlugin {
private static final String ORDER_ID_PREFIX = "GD";
@Autowired
private static final Long WBCJ_ID = 145L;
@Resource
private ByglByjhMapper byglByjhMapper;
@Resource
private IApiDeptApi apiDeptApi;
@Resource
private ByglByfaMapper byglByfaMapper;
@Override
public void beforeExecute(EnhanceContext enhanceContext) {
Map<String, Object> params = enhanceContext.getParam().getParams();
//新增方法默认状态字段
params.put("order_state",ByglConstant.GD_STATE_DKS);
String order_id = lideeYunJiUtils.getMap2Str(params, "order_id");
String plan_upkeep_time = lideeYunJiUtils.getMap2Str(params, "plan_upkeep_time");
LocalDate localDate = LocalDate.parse(plan_upkeep_time);
String year = String.valueOf(localDate.getYear());
params.put("belong_year",year);
String scx = lideeYunJiUtils.getMap2Str(params, "device_type_name");
Map<String,Object> map= byglByfaMapper.getScxXx(scx);
Long deptId = lideeYunJiUtils.getMap2Long(map, "dept_id");
// 通过部门ID获取部门信息进而获取负责人ID
Long leaderUserId = null;
if (deptId != null) {
DeptRespDTO dept = apiDeptApi.getDept(deptId);
if (dept != null) {
leaderUserId = dept.getLeaderUserId();
}
}
params.put("leader_user_id",leaderUserId);
//维保车间145 主任
Long wbcjzrUserId = null;
if (deptId != null) {
DeptRespDTO dept = apiDeptApi.getDept(WBCJ_ID);
if (dept != null) {
wbcjzrUserId = dept.getLeaderUserId();
}
}
params.put("wbcjzr_user_id",wbcjzrUserId);
boolean needGenerateNewId = shouldGenerateNewOrderId(order_id);
if(needGenerateNewId){
String newOrderId = generateOrderId();

View File

@@ -12,6 +12,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;
@@ -40,6 +41,10 @@ public class ByglByjhPlugin implements AroundAdvicePlugin {
// 创建工单并设置planUpkeepTime
String planUpkeepTime = dates[0].trim();
params.put("next_upkeep_time", planUpkeepTime);
LocalDate localDate = LocalDate.parse(planUpkeepTime);
String year = String.valueOf(localDate.getYear());
params.put("belong_year",year);
}
//新增方法默认状态字段

View File

@@ -176,6 +176,10 @@ public class ByManagementGd extends BaseTenantEntity {
/**
* 所属年份
*/
private String belongYear;

View File

@@ -91,4 +91,10 @@ public class ByManagementPlan extends BaseTenantEntity {
* 保养内容
*/
private String schemeInfo;
/**
* 所属年份
*/
private String belongYear;
}

View File

@@ -1,13 +1,19 @@
package com.lideeyunji.core.framework.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lideeyunji.core.framework.entity.ByManagementGd;
import com.lideeyunji.core.framework.entity.ByManagementPlan;
import com.lideeyunji.tool.framework.mybatis.core.mapper.BaseMapperX;
import java.util.List;
/**
* 保养管理-保养计划Mapper接口
*
* @date 2026-04-15
*/
public interface ByManagementPlanMapper extends BaseMapper<ByManagementPlan> {
public interface ByManagementPlanMapper extends BaseMapperX<ByManagementPlan> {
List<ByManagementPlan> getDataWithMaxBelongYear();
List<ByManagementGd> getOrderWithBelongYear(String belongYear);
}

View File

@@ -20,4 +20,6 @@ public interface IByglByfaService {
void auditNotPass(Long id);
void orderAuditNotPass(Long id);
void copyFullYearData();
}

View File

@@ -3,6 +3,7 @@ package com.lideeyunji.core.framework.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.lideeyunji.core.framework.entity.ByManagementGd;
import com.lideeyunji.core.framework.entity.ByManagementPlan;
import com.lideeyunji.core.framework.entity.ByManagementYs;
@@ -22,11 +23,10 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Year;
import java.time.format.DateTimeFormatter;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;
/**
*保养管理-保养方案
@@ -202,10 +202,10 @@ public class ByglByfaServiceImpl implements IByglByfaService {
@Override
public void auditNotPass(Long id) {
ByManagementGd gzbx = new ByManagementGd();
gzbx.setId(id);
gzbx.setOrderState(ByglConstant.GD_STATE_BTG);
byManagementGdMapper.updateById(gzbx);
ByManagementGd bygd = new ByManagementGd();
bygd.setId(id);
bygd.setOrderState(ByglConstant.GD_STATE_BTG);
byManagementGdMapper.updateById(bygd);
}
@@ -219,6 +219,77 @@ public class ByglByfaServiceImpl implements IByglByfaService {
byManagementYsMapper.deleteById(id);
}
@Override
public void copyFullYearData() {
List<ByManagementPlan> newPlans = new ArrayList<>();
List<ByManagementGd> newGds = new ArrayList<>();
List<ByManagementPlan> plans = byManagementPlanMapper.getDataWithMaxBelongYear();
if(plans == null || plans.isEmpty()){
return;
}
String belongYear = plans.get(0).getBelongYear();
List<ByManagementGd> gds = byManagementPlanMapper.getOrderWithBelongYear(belongYear);
String nextYear = String.valueOf(Integer.parseInt(belongYear) + 1);
// 1. 将子表 List 转换为 MapplanId -> List<ByManagementGd>
Map<String, List<ByManagementGd>> itemMap = gds.stream()
.collect(Collectors.groupingBy(ByManagementGd::getPlanId));
// 2. 一次遍历主表,从 Map 中获取关联数据
plans.forEach(plan -> {
Long newId = IdWorker.getId();
//重新插入所属年份
plan.setBelongYear(nextYear);
//修改时间区间
String scheduledDate = plan.getScheduledDate();
String replace = scheduledDate.replace(belongYear, nextYear);
plan.setScheduledDate(replace);
//插入下次保养时间
String[] dates = replace.split(",");
if(dates.length > 0){
String planUpkeepTime = dates[0].trim();
plan.setNextUpkeepTime(planUpkeepTime);
}
//修改planId
String planId = plan.getPlanId();
String replace1 = planId.replace(belongYear, nextYear);
plan.setPlanId(replace1);
//状态更新
plan.setPlanState("0");
List<ByManagementGd> relatedItems = itemMap.getOrDefault(String.valueOf(plan.getId()), new ArrayList<>());
relatedItems.forEach(order -> {
order.setId(IdWorker.getId());
order.setPlanId(newId+"");
order.setOrderState("0");
order.setBelongYear(nextYear);
String replace2 = order.getPlanUpkeepTime().replace(belongYear, nextYear);
order.setPlanUpkeepTime(replace2);
order.setRemark(null);
order.setUpkeepTime(null);
order.setBygdCljg(null);
order.setMaintainer(null);
order.setLeaderUserYj(null);
order.setWbcjzrUserYj(null);
order.setLeaderUpkeepTime(null);
order.setLeaderUserZt(0);
order.setWbcjzrUserZt(0);
newGds.add(order);
});
//生成新id
plan.setId(newId);
newPlans.add(plan);
});
byManagementGdMapper.insertBatch(newGds,500);
byManagementPlanMapper.insertBatch(newPlans,500);
}
/**
* 生成工单ID
* 格式GD + 时间戳yyyyMMddHHmmss
@@ -227,6 +298,7 @@ public class ByglByfaServiceImpl implements IByglByfaService {
return ORDER_ID_PREFIX + LocalDateTime.now().format(DATE_TIME_FORMATTER);
}
/**
* 如果日期是28号、29号、30号或31号顺延到下个月1号
*/
@@ -239,6 +311,8 @@ public class ByglByfaServiceImpl implements IByglByfaService {
return date;
}
}

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lideeyunji.core.framework.mapper.ByManagementPlanMapper">
<select id="getDataWithMaxBelongYear" resultType="com.lideeyunji.core.framework.entity.ByManagementPlan">
SELECT
*
FROM
by_management_plan
WHERE
is_deleted = 0
AND
belong_year = (SELECT MAX(belong_year) FROM by_management_plan)
</select>
<select id="getOrderWithBelongYear" resultType="com.lideeyunji.core.framework.entity.ByManagementGd">
SELECT
*
FROM
by_management_gd
WHERE
is_deleted = 0
AND
belong_year = #{belongYear}
</select>
</mapper>