保养管理 功能修改 审批 验收

This commit is contained in:
shih
2026-04-16 16:28:33 +08:00
parent 303a6f0cb0
commit 97c1fb4b61
16 changed files with 771 additions and 98 deletions

View File

@@ -55,4 +55,32 @@ public class ByglController extends BaseController {
}
@PostMapping("/generateWorkOrder")
public BaseWebResult generateWorkOrder(@RequestBody Map<String,Object> model) {
Long id = lideeYunJiUtils.getMap2Long(model, "id");
byglByfaService.generateWorkOrder(id);
return BaseWebResult.success("成功");
}
@PostMapping("/auditNotPass")
public BaseWebResult auditNotPass(@RequestBody Map<String,Object> model) {
Long id = lideeYunJiUtils.getMap2Long(model, "id");
if(id == null){
return BaseWebResult.error(FrameErrorCodeConstants.FRAME_OP_ERROR);
}
byglByfaService.auditNotPass(id);
return BaseWebResult.success("审批成功");
}
@PostMapping("/orderAuditNotPass")
public BaseWebResult orderAuditNotPass(@RequestBody Map<String,Object> model) {
Long id = lideeYunJiUtils.getMap2Long(model, "id");
if(id == null){
return BaseWebResult.error(FrameErrorCodeConstants.FRAME_OP_ERROR);
}
byglByfaService.orderAuditNotPass(id);
return BaseWebResult.success("审批成功");
}
}

View File

@@ -1,19 +1,20 @@
package com.lideeyunji.core.framework.enhance.example.report.bygl;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.lideeyunji.core.framework.adapter.FrameWorkAdapter;
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.entity.ByManagementGd;
import com.lideeyunji.core.framework.entity.ByManagementJl;
import com.lideeyunji.core.framework.entity.ByManagementPlan;
import com.lideeyunji.core.framework.entity.ByManagementYs;
import com.lideeyunji.core.framework.mapper.ByManagementGdMapper;
import com.lideeyunji.core.framework.mapper.ByManagementJlMapper;
import com.lideeyunji.core.framework.mapper.ByManagementYsMapper;
import com.lideeyunji.core.framework.mapper.ByglByjhMapper;
import com.lideeyunji.core.framework.mapper.*;
import com.lideeyunji.tool.framework.common.constant.ByglConstant;
import com.lideeyunji.tool.framework.common.util.object.BeanUtils;
import com.lideeyunji.tool.framework.security.core.LoginUser;
import com.lideeyunji.tool.framework.security.core.util.SecurityFrameworkUtils;
import com.lideeyunji.tool.framework.yunji.tool.spring.SpringUtils;
import com.lideeyunji.tool.framework.yunji.utils.lideeYunJiUtils;
import lombok.extern.slf4j.Slf4j;
@@ -21,7 +22,12 @@ 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.Date;
import java.util.List;
import java.util.Map;
/**
@@ -34,7 +40,11 @@ public class ByglBygdBjPlugin implements AroundAdvicePlugin {
/**
* 操作类型常量
*/
private static final String SUBMIT_TYPE_CL = "cl";
private static final String SUBMIT_TYPE_CJZRCL = "cjzrcl";
private static final String SUBMIT_TYPE_WBZRCL = "wbzrcl";
private static final String SUBMIT_TYPE_SQRCL = "sqrcl";
private static final String SUBMIT_TYPE_YS = "ys";
/**
@@ -42,18 +52,19 @@ public class ByglBygdBjPlugin implements AroundAdvicePlugin {
*/
private static final int NOT_DELETED = 0;
@Autowired
private ByglByjhMapper byglByjhMapper;
@Autowired
@Resource
private ByManagementJlMapper byManagementJlMapper;
@Autowired
@Resource
private ByManagementYsMapper byManagementYsMapper;
@Autowired
@Resource
private ByManagementGdMapper byManagementGdMapper;
@Resource
private ByManagementPlanMapper byManagementPlanMapper;
@Override
public void beforeExecute(EnhanceContext enhanceContext) {
Map<String, Object> params = enhanceContext.getParam().getParams();
@@ -64,12 +75,20 @@ public class ByglBygdBjPlugin implements AroundAdvicePlugin {
return;
}
String id = lideeYunJiUtils.getMap2Str(params, "id");
validateParams(id, submit_type);
if(StringUtils.isBlank(id)){
throw new IllegalArgumentException("工单ID不能为空");
}
FrameWorkAdapter adapter = SpringUtils.getBean(FrameWorkAdapter.class);
switch (submit_type) {
case SUBMIT_TYPE_CL://处理操作
handleClOperation(id, params, adapter);
case SUBMIT_TYPE_CJZRCL://车间主任处理操作
handleCjzrclOperation(id, params, adapter);
break;
case SUBMIT_TYPE_WBZRCL://维保主任处理操作
handleWbzrclOperation(id, params, adapter);
break;
case SUBMIT_TYPE_SQRCL://申请人处理操作
handleSqrclOperation(id, params, adapter);
break;
case SUBMIT_TYPE_YS://验收操作
handleYsOperation(id, params, adapter);
@@ -79,7 +98,24 @@ public class ByglBygdBjPlugin implements AroundAdvicePlugin {
@Override
public void afterExecute(EnhanceContext enhanceContext) {
Map<String, Object> params = enhanceContext.getParam().getParams();
Long id = lideeYunJiUtils.getMap2Long(params, "id");
if (id == null) {
return;
}
ByManagementGd gd = byManagementGdMapper.selectOne("id", id);
if (gd == null) {
return;
}
if(ByglConstant.GD_STATE_BTG.equals(gd.getOrderState())){
gd.setOrderState(ByglConstant.GD_STATE_DKS);
gd.setLeaderUserYj(null);
gd.setWbcjzrUserYj(null);
gd.setLeaderUpkeepTime(null);
gd.setLeaderUserZt(0);
gd.setWbcjzrUserZt(0);
byManagementGdMapper.updateById(gd);
}
}
@@ -88,90 +124,180 @@ public class ByglBygdBjPlugin implements AroundAdvicePlugin {
*/
private void handleYsOperation(String id, Map<String, Object> params, FrameWorkAdapter adapter) {
String gdys_yj = lideeYunJiUtils.getMap2Str(params, "gdys_yj");
String pjxj = lideeYunJiUtils.getMap2Str(params, "pjxj");
ByManagementJl jl = byManagementJlMapper.selectById(id);
ByManagementYs ys = byManagementYsMapper.selectById(id);
jl.setYsTime(DateUtil.now());
jl.setPjxj(pjxj);
jl.setState(ByglConstant.YSZT_STATE_YYS);
jl.setGdysYj(gdys_yj);
jl.setUpdateTime(LocalDateTime.now());
jl.setUpdateUser(adapter.getOnlineUserId());
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
if (loginUser == null) {
return;
}
Long userId = loginUser.getId();
byManagementJlMapper.updateById(jl);
if(ys.getWbcjzrYsZt() == 0 && userId.equals(ys.getWbcjzrUserId())){
ys.setWbcjzrYsZt(1);
ys.setWbcjzrYsYj(gdys_yj);
}
ByManagementYs ys = BeanUtils.toBean(jl, ByManagementYs.class);
if(ys == null){
if(ys.getLeaderYsZt() == 0 && userId.equals(ys.getLeaderUserId())){
ys.setLeaderYsZt(1);
ys.setLeaderYsYj(gdys_yj);
}
if(ys.getLeaderYsZt() == 1 && ys.getWbcjzrYsZt() == 1){
ys.setYsTime(DateUtil.now());
ys.setState(ByglConstant.YSZT_STATE_YYS);
ys.setUpdateTime(LocalDateTime.now());
ys.setUpdateUser(adapter.getOnlineUserId());
//验收完之后需要修改计划表数据
//当前工单 修改为已完成
ByManagementGd gd = byManagementGdMapper.selectOne("order_id", ys.getOrderId());
gd.setOrderState(ByglConstant.BY_STATE_YWC);
byManagementGdMapper.updateById(gd);
String planId = gd.getPlanId();
//查询当前计划的工单
LambdaQueryWrapper<ByManagementGd> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ByManagementGd::getPlanId, planId);
wrapper.eq(ByManagementGd::getOrderState, ByglConstant.BY_STATE_YWC);
List<ByManagementGd> byManagementGds = byManagementGdMapper.selectList(wrapper);
//当前计划
ByManagementPlan plan = byManagementPlanMapper.selectById(planId);
//保养周期
String interval = plan.getScheduledInterval();
if("1".equals(interval)) {//周期为180天
//如果有两条已完成的工单,则将计划状态修改为已完成
if(byManagementGds.size() >= 2) {
plan.setPlanState(ByglConstant.JH_STATE_YWC);
byManagementPlanMapper.updateById(plan);
}else{
String planUpkeepTime = gd.getPlanUpkeepTime();
// 解析完成时间只有日期部分需要转换为LocalDateTime
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate completeLocalDate = LocalDate.parse(planUpkeepTime, formatter);
LocalDateTime completeDate = completeLocalDate.atStartOfDay();
// 往后推180天
LocalDateTime nextMaintenanceDate = adjustToNextMonthFirstDayIfNeeded(completeDate.plusDays(180));
// 判断是否超过本年
int completeYear = completeDate.getYear();
int nextMaintenanceYear = nextMaintenanceDate.getYear();
boolean isCrossYear = nextMaintenanceYear > completeYear;
if(isCrossYear){
plan.setPlanState(ByglConstant.JH_STATE_YWC);
byManagementPlanMapper.updateById(plan);
}else{
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String nextMaintenanceDateStr = nextMaintenanceDate.format(dateFormatter);
plan.setNextUpkeepTime(nextMaintenanceDateStr);
byManagementPlanMapper.updateById(plan);
}
}
}else if("2".equals(interval)) {//周期为360天
plan.setPlanState(ByglConstant.JH_STATE_YWC);
byManagementPlanMapper.updateById(plan);
}
}
byManagementYsMapper.updateById(ys);
ByManagementJl jl = BeanUtils.toBean(ys, ByManagementJl.class);
jl.setId(null);
if(jl == null){
throw new RuntimeException("对象转换失败");
}
byManagementYsMapper.updateById(ys);
byManagementJlMapper.insert(jl);
log.info("工单验收成功ID: {}", id);
}
/**
* 处理操作
* 车间主任处理操作
*/
private void handleClOperation(String id, Map<String, Object> params, FrameWorkAdapter adapter) {
String bygd_cljg = lideeYunJiUtils.getMap2Str(params, "bygd_cljg");
int result = byglByjhMapper.updateClBygd(id, bygd_cljg, ByglConstant.BY_STATE_YWC);
if (result <= 0) {
log.info("工单处理失败ID: {}", id);
return;
}
private void handleCjzrclOperation(String id, Map<String, Object> params, FrameWorkAdapter adapter) {
String leader_user_yj = lideeYunJiUtils.getMap2Str(params, "leader_user_yj");
String leader_upkeep_time = lideeYunJiUtils.getMap2Str(params, "leader_upkeep_time");
ByManagementGd gd = byManagementGdMapper.selectById(id);
ByManagementJl jl = createByManagementJl(gd, adapter);
byManagementJlMapper.insert(jl);
syncToYsTable(jl);
log.info("工单处理成功ID: {}", id);
gd.setLeaderUserYj(leader_user_yj);
gd.setLeaderUserZt(1);
gd.setLeaderUpkeepTime(leader_upkeep_time);
if(ByglConstant.GD_STATE_DKS.equals(gd.getOrderState())){
gd.setOrderState(ByglConstant.GD_STATE_JXZ);
}
byManagementGdMapper.updateById(gd);
}
/**
* 创建保养记录
* 维保主任处理操作
*/
private ByManagementJl createByManagementJl(ByManagementGd gd, FrameWorkAdapter adapter) {
ByManagementJl jl = new ByManagementJl();
jl.setId(IdWorker.getId());
jl.setOrderId(gd.getOrderId());
jl.setOrderName(gd.getOrderName());
jl.setEquipmentInfo(gd.getEquipmentInfo());
jl.setEquipmentCode(gd.getEquipmentCode());
jl.setUpkeepLevel(gd.getUpkeepLevel());
jl.setUpkeepTime(gd.getUpkeepTime());
jl.setPriority(gd.getPriority());
jl.setState(ByglConstant.YSZT_STATE_DYS);
jl.setExecutor(gd.getExecutor());
jl.setCreateTime(LocalDateTime.now());
jl.setCreateUser(adapter.getOnlineUserId());
jl.setIsDeleted(NOT_DELETED);
return jl;
private void handleWbzrclOperation(String id, Map<String, Object> params, FrameWorkAdapter adapter) {
String wbcjzr_user_yj = lideeYunJiUtils.getMap2Str(params, "wbcjzr_user_yj");
ByManagementGd gd = byManagementGdMapper.selectById(id);
gd.setWbcjzrUserYj(wbcjzr_user_yj);
gd.setWbcjzrUserZt(1);
if(ByglConstant.GD_STATE_DKS.equals(gd.getOrderState())){
gd.setOrderState(ByglConstant.GD_STATE_JXZ);
}
byManagementGdMapper.updateById(gd);
}
/**
* 同步到验收表
* 申请人处理操作
*/
private void syncToYsTable(ByManagementJl jl) {
ByManagementYs ys = BeanUtils.toBean(jl, ByManagementYs.class);
if(ys == null){
throw new RuntimeException("对象转换失败");
}
private void handleSqrclOperation(String id, Map<String, Object> params, FrameWorkAdapter adapter) {
String bygd_cljg = lideeYunJiUtils.getMap2Str(params, "bygd_cljg");
String maintainer = lideeYunJiUtils.getMap2Str(params, "maintainer");
String schemeInfo = lideeYunJiUtils.getMap2Str(params, "scheme_info");
ByManagementGd gd = byManagementGdMapper.selectById(id);
gd.setBygdCljg(bygd_cljg);
gd.setMaintainer(maintainer);
gd.setSchemeInfo(schemeInfo);
gd.setOrderState(ByglConstant.GD_STATE_DYS);
gd.setUpkeepTime(LocalDate.now().toString());
byManagementGdMapper.updateById(gd);
ByManagementYs ys = new ByManagementYs();
ys.setOrderId(gd.getOrderId());
ys.setOrderName(gd.getOrderName());
ys.setEquipmentInfo(gd.getEquipmentInfo());
ys.setEquipmentCode(gd.getEquipmentCode());
ys.setUpkeepLevel(gd.getUpkeepLevel());
ys.setUpkeepTime(gd.getUpkeepTime());
ys.setPriority(gd.getPriority());
ys.setState(ByglConstant.YSZT_STATE_DYS);
ys.setExecutor(gd.getExecutor());
ys.setLeaderUserId(gd.getLeaderUserId());
ys.setWbcjzrUserId(gd.getWbcjzrUserId());
ys.setLeaderYsZt(0);
ys.setWbcjzrYsZt(0);
ys.setMaintainer(gd.getMaintainer());
ys.setSchemeInfo(gd.getSchemeInfo());
ys.setCreateTime(LocalDateTime.now());
ys.setCreateUser(adapter.getOnlineUserId());
ys.setIsDeleted(NOT_DELETED);
byManagementYsMapper.insert(ys);
}
/**
* 参数校验
* 如果日期是28号、29号、30号或31号顺延到下个月1号
*/
private void validateParams(String id, String submit_type) {
if(StringUtils.isBlank(id)){
throw new IllegalArgumentException("工单ID不能为空");
}
if(!SUBMIT_TYPE_CL.equals(submit_type) && !SUBMIT_TYPE_YS.equals(submit_type)){
throw new IllegalArgumentException("不支持的操作类型: " + submit_type);
private LocalDateTime adjustToNextMonthFirstDayIfNeeded(LocalDateTime date) {
int dayOfMonth = date.getDayOfMonth();
if (dayOfMonth >= 28) {
// 顺延到下个月1号
return date.plusMonths(1).withDayOfMonth(1);
}
return date;
}
}

View File

@@ -9,6 +9,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Map;
@@ -24,7 +26,6 @@ public class ByglByjhLbPlugin implements AroundAdvicePlugin {
@Override
public void beforeExecute(EnhanceContext enhanceContext) {
}
@Override
@@ -38,6 +39,32 @@ public class ByglByjhLbPlugin implements AroundAdvicePlugin {
Map<String, Object> countByPlanId = byglByjhMapper.getCountByPlanId(plan_id);
record.put("plan_count",lideeYunJiUtils.getMap2Long(countByPlanId,"jhs"));
record.put("completed_count",lideeYunJiUtils.getMap2Long(countByPlanId,"wcs"));
// 计算距离下次保养时间还有几天order_state为1时不计算
String planState = lideeYunJiUtils.getMap2Str(record, "plan_state");
record.put("days_until_next_upkeep", "-");
if (!"1".equals(planState)) {
String nextUpkeepTimeStr = lideeYunJiUtils.getMap2Str(record, "next_upkeep_time");
if (Func.isNotEmpty(nextUpkeepTimeStr)) {
try {
// 解析日期字符串格式yyyy-MM-dd
LocalDate nextUpkeepTime = LocalDate.parse(nextUpkeepTimeStr.substring(0, 10));
LocalDate today = LocalDate.now();
// 计算天数差(可能为负数,表示已过期)
long daysUntilNext = ChronoUnit.DAYS.between(today, nextUpkeepTime);
if(daysUntilNext<0){
record.put("days_until_next_upkeep", "已超期"+Math.abs(daysUntilNext)+"");
}else {
record.put("days_until_next_upkeep", daysUntilNext+"");
}
} catch (Exception e) {
log.warn("解析下次保养时间失败: {}", nextUpkeepTimeStr, e);
}
}
}else {
record.put("next_upkeep_time", "-");
}
}
}
}

View File

@@ -33,6 +33,15 @@ public class ByglByjhPlugin implements AroundAdvicePlugin {
@Override
public void beforeExecute(EnhanceContext enhanceContext) {
Map<String, Object> params = enhanceContext.getParam().getParams();
String scheduledDate = lideeYunJiUtils.getMap2Str(params, "scheduled_date");
String[] dates = scheduledDate.split(",");
if(dates.length > 0){
// 创建工单并设置planUpkeepTime
String planUpkeepTime = dates[0].trim();
params.put("next_upkeep_time", planUpkeepTime);
}
//新增方法默认状态字段
params.put("plan_state", ByglConstant.JH_STATE_JXZ);
String plan_id = lideeYunJiUtils.getMap2Str(params, "plan_id");

View File

@@ -1,11 +1,15 @@
package com.lideeyunji.core.framework.entity;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.lideeyunji.tool.framework.yunji.model.global.BaseTenantEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* 保养管理-保养工单
*/
@@ -100,15 +104,80 @@ public class ByManagementGd extends BaseTenantEntity {
*/
private String schemeId;
/**
* 处理结果
*/
private String bygdCljg;
/**
* 计划id
*/
private String planId;
/**
* 保养内容
*/
private String schemeInfo;
/**
* 保养人
*/
private String maintainer;
/**
* 设备所属车间领导
*/
private Long leaderUserId;
/**
* 维保中心领导
*/
private Long wbcjzrUserId;
/**
* 设备所属车间领导意见
*/
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private String leaderUserYj;
/**
* 维保中心领导意见
*/
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private String wbcjzrUserYj;
/**
* 车间领导确定保养时间
*/
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private String leaderUpkeepTime;
/**
* 处理结果
*/
private String bygdCljg;
/**
* 车间领导审批状态
*/
private Integer leaderUserZt;
/**
* 维保领导审批状态
*/
private Integer wbcjzrUserZt;
}

View File

@@ -67,16 +67,51 @@ public class ByManagementJl extends BaseTenantEntity {
*验收时间
*/
private String ysTime;
/**
* 设备所属车间领导
*/
private Long leaderUserId;
/**
*评价星级
* 维保中心领导
*/
private String pjxj;
private Long wbcjzrUserId;
/**
*验收意见
* 车间领导验收状态
*/
private String gdysYj;
private Integer leaderYsZt;
/**
* 维保领导验收状态
*/
private Integer wbcjzrYsZt;
/**
* 车间领导验收意见
*/
private String leaderYsYj;
/**
* 维保领导验收意见
*/
private String wbcjzrYsYj;
/**
* 保养人
*/
private String maintainer;
/**
* 保养内容
*/
private String schemeInfo;
}

View File

@@ -0,0 +1,94 @@
package com.lideeyunji.core.framework.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.lideeyunji.tool.framework.yunji.model.global.BaseTenantEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 保养管理-保养计划
*/
@TableName("by_management_plan")
@Data
@EqualsAndHashCode
public class ByManagementPlan extends BaseTenantEntity {
/**
* 主键
*/
private Long id;
/**
* 计划编号
*/
private String planId;
/**
* 计划名称
*/
private String planName;
/**
* 生产线
*/
private String deviceTypeName;
/**
* 设备
*/
private String equipmentInfo;
/**
* 设备编号
*/
private String equipmentCode;
/**
* 保养级别
*/
private String upkeepLevel;
/**
* 保养方案
*/
private String schemeId;
/**
* 可能更换零件
*/
private String possibleReplacements;
/**
* 保养周期
*/
private String scheduledInterval;
/**
* 下次保养时间
*/
private String nextUpkeepTime;
/**
* 执行人
*/
private String executor;
/**
* 状态
*/
private String planState;
/**
* 备注
*/
private String remark;
/**
* 起止时间
*/
private String scheduledDate;
/**
* 保养内容
*/
private String schemeInfo;
}

View File

@@ -70,14 +70,51 @@ public class ByManagementYs extends BaseTenantEntity {
private String ysTime;
/**
*评价星级
* 设备所属车间领导
*/
private String pjxj;
private Long leaderUserId;
/**
*验收意见
* 维保中心领导
*/
private String gdysYj;
private Long wbcjzrUserId;
/**
* 车间领导验收状态
*/
private Integer leaderYsZt;
/**
* 维保领导验收状态
*/
private Integer wbcjzrYsZt;
/**
* 车间领导验收意见
*/
private String leaderYsYj;
/**
* 维保领导验收意见
*/
private String wbcjzrYsYj;
/**
* 保养人
*/
private String maintainer;
/**
* 保养内容
*/
private String schemeInfo;
}

View File

@@ -1,13 +1,13 @@
package com.lideeyunji.core.framework.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lideeyunji.core.framework.entity.ByManagementGd;
import com.lideeyunji.tool.framework.mybatis.core.mapper.BaseMapperX;
/**
* 保养管理-保养工单Mapper接口
*
* @date 2026-03-20
*/
public interface ByManagementGdMapper extends BaseMapper<ByManagementGd> {
public interface ByManagementGdMapper extends BaseMapperX<ByManagementGd> {
}

View File

@@ -0,0 +1,13 @@
package com.lideeyunji.core.framework.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lideeyunji.core.framework.entity.ByManagementPlan;
/**
* 保养管理-保养计划Mapper接口
*
* @date 2026-04-15
*/
public interface ByManagementPlanMapper extends BaseMapper<ByManagementPlan> {
}

View File

@@ -17,4 +17,6 @@ public interface ByglByfaMapper {
List<Map<String, Object>> getByXx(String dev_type, String dev_code);
List<Map<String, Object>> getWxXx(String dev_type, String dev_code);
Map<String, Object> getScxXx(String scx);
}

View File

@@ -14,4 +14,10 @@ public interface IByglByfaService {
List<Map<String, Object>> getByXx(String dev_type, String dev_code);
List<Map<String, Object>> getWxXx(String dev_type, String dev_code);
void generateWorkOrder(Long id);
void auditNotPass(Long id);
void orderAuditNotPass(Long id);
}

View File

@@ -2,13 +2,31 @@
package com.lideeyunji.core.framework.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lideeyunji.core.framework.entity.ByManagementGd;
import com.lideeyunji.core.framework.entity.ByManagementPlan;
import com.lideeyunji.core.framework.entity.ByManagementYs;
import com.lideeyunji.core.framework.mapper.ByManagementGdMapper;
import com.lideeyunji.core.framework.mapper.ByManagementPlanMapper;
import com.lideeyunji.core.framework.mapper.ByManagementYsMapper;
import com.lideeyunji.core.framework.mapper.ByglByfaMapper;
import com.lideeyunji.core.framework.service.IByglByfaService;
import org.springframework.beans.factory.annotation.Autowired;
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.common.util.object.BeanUtils;
import com.lideeyunji.tool.framework.yunji.enums.AcceptanceStatusEnum;
import com.lideeyunji.tool.framework.yunji.utils.lideeYunJiUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
*保养管理-保养方案
@@ -16,9 +34,27 @@ import java.util.Map;
@Service
public class ByglByfaServiceImpl implements IByglByfaService {
@Autowired
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
private static final String ORDER_ID_PREFIX = "GD";
private static final Long WBCJ_ID = 145L;
@Resource
private ByglByfaMapper byglByfaMapper;
@Resource
private ByManagementPlanMapper byManagementPlanMapper;
@Resource
private ByManagementGdMapper byManagementGdMapper;
@Resource
private ByManagementYsMapper byManagementYsMapper;
@Resource
private IApiDeptApi apiDeptApi;
@Override
public int changeFaState(String id, String state) {
int result = byglByfaMapper.changeFaState(id, state);
@@ -36,4 +72,174 @@ public class ByglByfaServiceImpl implements IByglByfaService {
return byglByfaMapper.getWxXx(dev_type, dev_code);
}
@Override
public void generateWorkOrder(Long id) {
//查询当前保养计划
ByManagementPlan plan = byManagementPlanMapper.selectById(id);
//查询当前计划的工单
LambdaQueryWrapper<ByManagementGd> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ByManagementGd::getPlanId, id);
List<ByManagementGd> byManagementGds = byManagementGdMapper.selectList(wrapper);
ByManagementGd order = BeanUtils.toBean(plan, ByManagementGd.class);
order.setId(null);
order.setOrderId(generateOrderId());
order.setOrderName(plan.getPlanName());
order.setOrderState("0");
order.setPriority(order.getUpkeepLevel());
order.setApplyForParts("0");
order.setIsStopped("0");
order.setPlanId(id+"");
order.setSchemeInfo(plan.getSchemeInfo());
//需要查询对应设备车间的车间主任 维保主任
String scx = order.getDeviceTypeName();//生成线 需要去sblx查询对应车间
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();
}
}
order.setLeaderUserId(leaderUserId);
//维保车间145 主任
Long wbcjzrUserId = null;
if (deptId != null) {
DeptRespDTO dept = apiDeptApi.getDept(WBCJ_ID);
if (dept != null) {
wbcjzrUserId = dept.getLeaderUserId();
}
}
order.setWbcjzrUserId(wbcjzrUserId);
//找到planUpkeepTime最近的一条工单
Optional<ByManagementGd> latestCompleted = byManagementGds.stream()
.filter(gd -> gd.getPlanUpkeepTime() != null && !gd.getPlanUpkeepTime().isEmpty())
.max(Comparator.comparing(gd -> {
try {
// 尝试解析完成时间,支持多种格式
String time = gd.getPlanUpkeepTime();
if (time.contains("T")) {
return LocalDateTime.parse(time, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
} else if (time.contains(" ")) {
return LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
} else {
return LocalDateTime.parse(time + "T00:00:00", DateTimeFormatter.ISO_LOCAL_DATE_TIME);
}
} catch (Exception e) {
return LocalDateTime.MIN;
}
}));
String interval = plan.getScheduledInterval();//保养周期
String scheduledDate = plan.getScheduledDate();//首次保养时间区间
if("1".equals(interval)){//周期为180天
//判断最近的工单
if(latestCompleted.isPresent()){
if(byManagementGds.size() >= 2 ){//周期为180天左右半年1次 1年最多2次 超过就返回
return;
}
ByManagementGd completedGd = latestCompleted.get();
String planUpkeepTime = completedGd.getPlanUpkeepTime();
// 解析完成时间只有日期部分需要转换为LocalDateTime
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate completeLocalDate = LocalDate.parse(planUpkeepTime, formatter);
LocalDateTime completeDate = completeLocalDate.atStartOfDay();
// 往后推180天
LocalDateTime nextMaintenanceDate = adjustToNextMonthFirstDayIfNeeded(completeDate.plusDays(180));
// 判断是否超过本年
int completeYear = completeDate.getYear();
int nextMaintenanceYear = nextMaintenanceDate.getYear();
boolean isCrossYear = nextMaintenanceYear > completeYear;
if(isCrossYear){
return;
}else{
// 未超过本年,在当年内 保存工单
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String nextMaintenanceDateStr = nextMaintenanceDate.format(dateFormatter);
order.setPlanUpkeepTime(nextMaintenanceDateStr);
byManagementGdMapper.insert(order);
}
}else{
// 没有已完成的工单使用scheduledDate的第一个时间
if(scheduledDate != null && !scheduledDate.isEmpty()){
String[] dates = scheduledDate.split(",");
if(dates.length > 0){
// 创建工单并设置planUpkeepTime
String planUpkeepTime = dates[0].trim();
order.setPlanUpkeepTime(planUpkeepTime);
byManagementGdMapper.insert(order);
}
}
}
}else if("2".equals(interval)){//周期为360天
//周期为360天 要是没有工单可以生成 有工单直接返回
if(!latestCompleted.isPresent()){
// 没有已完成的工单使用scheduledDate的第一个时间
if(scheduledDate != null && !scheduledDate.isEmpty()){
String[] dates = scheduledDate.split(",");
if(dates.length > 0){
// 创建工单并设置planUpkeepTime
String planUpkeepTime = dates[0].trim();
order.setPlanUpkeepTime(planUpkeepTime);
byManagementGdMapper.insert(order);
}
}
}
}
}
@Override
public void auditNotPass(Long id) {
ByManagementGd gzbx = new ByManagementGd();
gzbx.setId(id);
gzbx.setOrderState(ByglConstant.GD_STATE_BTG);
byManagementGdMapper.updateById(gzbx);
}
@Override
public void orderAuditNotPass(Long id) {
ByManagementYs ys = byManagementYsMapper.selectById(id);
ByManagementGd gd = byManagementGdMapper.selectOne("order_id", ys.getOrderId());
gd.setOrderState(ByglConstant.GD_STATE_YSBTG);
byManagementGdMapper.updateById(gd);
byManagementYsMapper.deleteById(id);
}
/**
* 生成工单ID
* 格式GD + 时间戳yyyyMMddHHmmss
*/
private String generateOrderId() {
return ORDER_ID_PREFIX + LocalDateTime.now().format(DATE_TIME_FORMATTER);
}
/**
* 如果日期是28号、29号、30号或31号顺延到下个月1号
*/
private LocalDateTime adjustToNextMonthFirstDayIfNeeded(LocalDateTime date) {
int dayOfMonth = date.getDayOfMonth();
if (dayOfMonth >= 28) {
// 顺延到下个月1号
return date.plusMonths(1).withDayOfMonth(1);
}
return date;
}
}

View File

@@ -28,4 +28,15 @@
is_deleted = 0
AND dev_type = #{dev_type} AND dev_no = #{dev_code}
</select>
<select id="getScxXx" resultType="java.util.Map">
SELECT
*
FROM
dev_sblx
WHERE
is_deleted = 0
AND id = #{scx}
</select>
</mapper>

View File

@@ -5,7 +5,7 @@
<select id="getCountByPlanId" resultType="java.util.Map">
SELECT
COUNT(*) AS jhs,
COUNT(CASE WHEN order_state = '1' THEN 1 ELSE NULL END) AS wcs
COUNT(CASE WHEN order_state = '3' THEN 1 ELSE NULL END) AS wcs
FROM
by_management_gd
WHERE

View File

@@ -13,8 +13,18 @@ public interface ByglConstant {
/**待开始*/
String GD_STATE_DKS = "0";
/**进行中*/
String GD_STATE_JXZ = "1";
/**待验收*/
String GD_STATE_DYS = "2";
/**已完成*/
String BY_STATE_YWC = "1";
String BY_STATE_YWC = "3";
/**不通过*/
String GD_STATE_BTG = "4";
/**验收不通过*/
String GD_STATE_YSBTG = "5";
/**方案停用*/
String FA_STATE_TY = "0";