parent
4613bbad2d
commit
46098b464d
@ -0,0 +1,116 @@ |
|||||||
|
package com.zilber.boot.intelligencesite.schedule; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||||
|
import com.zilber.boot.intelligencesite.entity.IProductionPlan; |
||||||
|
import com.zilber.boot.intelligencesite.entity.IResourceSchedule; |
||||||
|
import com.zilber.boot.intelligencesite.entity.IWarn; |
||||||
|
import com.zilber.boot.intelligencesite.mapper.IResourceScheduleMapper; |
||||||
|
import com.zilber.boot.intelligencesite.schedule.dto.PlanDTO; |
||||||
|
import com.zilber.boot.intelligencesite.schedule.enums.Info; |
||||||
|
import com.zilber.boot.intelligencesite.service.IIProductionPlanService; |
||||||
|
import com.zilber.boot.intelligencesite.service.IIResourceScheduleService; |
||||||
|
import com.zilber.boot.intelligencesite.service.IIWarnService; |
||||||
|
import com.zilber.boot.system.pojo.SysDictionary; |
||||||
|
import com.zilber.boot.system.service.ISysDictionaryService; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.scheduling.annotation.Scheduled; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
import java.text.SimpleDateFormat; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author LJX |
||||||
|
* @TIME 2025-05-13 13:50 |
||||||
|
* @PROJECT intelligence-site |
||||||
|
* created by Intellij IDEA |
||||||
|
* Description |
||||||
|
*/ |
||||||
|
@Component |
||||||
|
@Slf4j |
||||||
|
public class ResourceSchedules { |
||||||
|
|
||||||
|
@Resource |
||||||
|
private IIWarnService warnService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private IIResourceScheduleService rsService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private ISysDictionaryService dictionaryService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private IResourceScheduleMapper resourceScheduleMapper; |
||||||
|
|
||||||
|
@Scheduled(cron = "0 */5 * * * ?") |
||||||
|
public void checkPlan() { |
||||||
|
Date now = new Date(); |
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
||||||
|
log.info("开始检测各个计划的进度:" + sdf.format(now)); |
||||||
|
Integer expenses = null; |
||||||
|
//在字典查询进度警告标度。如果报错或为空,默认值是5
|
||||||
|
LambdaQueryWrapper<SysDictionary> dictionaryWrapper = new LambdaQueryWrapper<>(); |
||||||
|
dictionaryWrapper.eq(SysDictionary::getName, "purpose_expenses"); |
||||||
|
try { |
||||||
|
SysDictionary one = dictionaryService.getOne(dictionaryWrapper); |
||||||
|
// if ( one != null) {
|
||||||
|
// expenses = Integer.parseInt(one.getCode());
|
||||||
|
// }
|
||||||
|
expenses = Integer.parseInt(one.getCode()); |
||||||
|
} |
||||||
|
catch ( Exception e) { |
||||||
|
//如果出现异常,初始化标度
|
||||||
|
expenses = 5; |
||||||
|
} |
||||||
|
//查询计划开始时间小于当前时间,计划结束时间大于当前时间的parentId为0的计划以及当前进度
|
||||||
|
List<PlanDTO> planDTOS = resourceScheduleMapper.listCheckedPlan(now); |
||||||
|
//删除之前的数据
|
||||||
|
rsService.removeAll(); |
||||||
|
warnService.removeAll(); |
||||||
|
//循环比较,插入数据
|
||||||
|
for ( PlanDTO plan: planDTOS) { |
||||||
|
if ( plan.getAccumulativeProgress() <= plan.getDiff() - expenses) {//进度慢
|
||||||
|
log.info("计划\"" + plan.getPlanName() + "\"进度较慢"); |
||||||
|
rsService.save(productionPlan(plan, now, Info.PRODUCTION_PLAN_SLOW.getMessage())); |
||||||
|
warnService.save(warn(plan, now, Info.WARN_SLOW.getMessage())); |
||||||
|
log.info("计划\"" + plan.getPlanName() + "\"进度更新完毕"); |
||||||
|
} |
||||||
|
else if ( plan.getAccumulativeProgress() >= plan.getDiff() + expenses){//进度快
|
||||||
|
log.info("计划\"" + plan.getPlanName() + "\"进度更新完毕"); |
||||||
|
rsService.save(productionPlan(plan, now, Info.PRODUCTION_PLAN_QUICK.getMessage())); |
||||||
|
log.info("计划\"" + plan.getPlanName() + "\"进度较慢"); |
||||||
|
} |
||||||
|
} |
||||||
|
Date end = new Date(); |
||||||
|
log.info("全部计划进度更新已完毕:" + sdf.format(end)); |
||||||
|
} |
||||||
|
|
||||||
|
private IResourceSchedule productionPlan(PlanDTO dto, Date date, String message) { |
||||||
|
IResourceSchedule rs = new IResourceSchedule(); |
||||||
|
rs.setPlanId(dto.getId()); |
||||||
|
rs.setPlanName(dto.getPlanName()); |
||||||
|
rs.setStartTime(dto.getStartTime()); |
||||||
|
rs.setEndTime(dto.getEndTime()); |
||||||
|
rs.setCreateTime(date); |
||||||
|
rs.setCreator("admin"); |
||||||
|
rs.setCurrentProgress(dto.getAccumulativeProgress()); |
||||||
|
rs.setAdvises(message); |
||||||
|
return rs; |
||||||
|
} |
||||||
|
|
||||||
|
private IWarn warn(PlanDTO dto, Date date, String message) { |
||||||
|
IWarn warn = new IWarn(); |
||||||
|
warn.setPlanId(dto.getId()); |
||||||
|
warn.setPlanName(dto.getPlanName()); |
||||||
|
warn.setWarnInfo(message); |
||||||
|
warn.setStartTime(dto.getStartTime()); |
||||||
|
warn.setEndTime(dto.getEndTime()); |
||||||
|
warn.setCreateTime(date); |
||||||
|
warn.setCreator("admin"); |
||||||
|
warn.setCurrentProgress(dto.getAccumulativeProgress()); |
||||||
|
return warn; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,49 @@ |
|||||||
|
package com.zilber.boot.intelligencesite.schedule.dto; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableField; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||||
|
import com.zilber.boot.intelligencesite.entity.IProductionPlan; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.NoArgsConstructor; |
||||||
|
import org.springframework.format.annotation.DateTimeFormat; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author LJX |
||||||
|
* @TIME 2025-05-13 14:14 |
||||||
|
* @PROJECT intelligence-site |
||||||
|
* created by Intellij IDEA |
||||||
|
* Description |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@NoArgsConstructor |
||||||
|
@AllArgsConstructor |
||||||
|
public class PlanDTO { |
||||||
|
|
||||||
|
@TableId(value = "id") |
||||||
|
private Long id; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "计划名称") |
||||||
|
private String planName; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "计划开始时间") |
||||||
|
private Date startTime; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "计划结束时间") |
||||||
|
private Date endTime; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "总工期天数") |
||||||
|
private Integer duration; |
||||||
|
|
||||||
|
private Integer diff; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "累计完成进度") |
||||||
|
private Integer accumulativeProgress; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,29 @@ |
|||||||
|
package com.zilber.boot.intelligencesite.schedule.enums; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author LJX |
||||||
|
* @TIME 2025-05-13 15:20 |
||||||
|
* @PROJECT intelligence-site |
||||||
|
* created by Intellij IDEA |
||||||
|
* Description |
||||||
|
*/ |
||||||
|
public enum Info { |
||||||
|
|
||||||
|
PRODUCTION_PLAN_SLOW("进度偏慢,建议增派人手。"), |
||||||
|
PRODUCTION_PLAN_QUICK("进度较快,建议考虑减少人手"), |
||||||
|
WARN_SLOW("施工进度较偏慢"), |
||||||
|
; |
||||||
|
|
||||||
|
private String message; |
||||||
|
|
||||||
|
public String getMessage() { |
||||||
|
return message; |
||||||
|
} |
||||||
|
|
||||||
|
Info() { |
||||||
|
} |
||||||
|
|
||||||
|
Info(String message) { |
||||||
|
this.message = message; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue