2025年5月13日16:08:40

1.新功能。定时检查计划进度
main
liuao 2 weeks ago
parent 4613bbad2d
commit 46098b464d
  1. 2
      src/main/java/com/zilber/boot/IntelligenceSiteApplication.java
  2. 2
      src/main/java/com/zilber/boot/intelligencesite/entity/IWarn.java
  3. 7
      src/main/java/com/zilber/boot/intelligencesite/mapper/IResourceScheduleMapper.java
  4. 3
      src/main/java/com/zilber/boot/intelligencesite/mapper/IWarnMapper.java
  5. 116
      src/main/java/com/zilber/boot/intelligencesite/schedule/ResourceSchedules.java
  6. 49
      src/main/java/com/zilber/boot/intelligencesite/schedule/dto/PlanDTO.java
  7. 29
      src/main/java/com/zilber/boot/intelligencesite/schedule/enums/Info.java
  8. 3
      src/main/java/com/zilber/boot/intelligencesite/service/IIResourceScheduleService.java
  9. 3
      src/main/java/com/zilber/boot/intelligencesite/service/IIWarnService.java
  10. 5
      src/main/java/com/zilber/boot/intelligencesite/service/impl/IResourceScheduleServiceImpl.java
  11. 5
      src/main/java/com/zilber/boot/intelligencesite/service/impl/IWarnServiceImpl.java
  12. 5
      src/main/java/com/zilber/boot/module/vehicle/service/impl/TourRunServiceImpl.java
  13. 34
      src/main/resources/mappers/IResourceScheduleMapper.xml
  14. 5
      src/main/resources/mappers/IWarnMapper.xml

@ -5,6 +5,7 @@ import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
* 启动程序
@ -14,6 +15,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@EnableKnife4j
@MapperScan(basePackages = "com.zilber.boot.*.mapper")
@EnableScheduling
public class IntelligenceSiteApplication
{
public static void main(String[] args)

@ -71,5 +71,7 @@ public class IWarn implements Serializable {
@TableField(exist = false)
private Date endTime;
@ApiModelProperty(value = "当前进度")
private Integer currentProgress;
}

@ -2,7 +2,10 @@ package com.zilber.boot.intelligencesite.mapper;
import com.zilber.boot.intelligencesite.entity.IResourceSchedule;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zilber.boot.intelligencesite.schedule.dto.PlanDTO;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
/**
@ -16,4 +19,8 @@ import java.util.List;
public interface IResourceScheduleMapper extends BaseMapper<IResourceSchedule> {
List<IResourceSchedule> queryList(IResourceSchedule iResourceSchedule);
void removeAll();
List<PlanDTO> listCheckedPlan(@Param("date") Date date);
}

@ -18,4 +18,7 @@ public interface IWarnMapper extends BaseMapper<IWarn> {
List<IWarn> queryList(IWarn iWarn);
IWarn selectByPlanId(Long id);
void removeAll();
}

@ -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;
}
}

@ -16,4 +16,7 @@ import java.util.List;
public interface IIResourceScheduleService extends IService<IResourceSchedule> {
List<IResourceSchedule> queryList(IResourceSchedule iResourceSchedule);
void removeAll();
}

@ -16,4 +16,7 @@ import java.util.List;
public interface IIWarnService extends IService<IWarn> {
List<IWarn> queryList(IWarn iWarn);
void removeAll();
}

@ -29,4 +29,9 @@ public class IResourceScheduleServiceImpl extends ServiceImpl<IResourceScheduleM
public List<IResourceSchedule> queryList(IResourceSchedule iResourceSchedule) {
return iResourceScheduleMapper.queryList(iResourceSchedule);
}
@Override
public void removeAll() {
iResourceScheduleMapper.removeAll();
}
}

@ -27,4 +27,9 @@ public class IWarnServiceImpl extends ServiceImpl<IWarnMapper, IWarn> implements
public List<IWarn> queryList(IWarn iWarn) {
return iWarnMapper.queryList(iWarn);
}
@Override
public void removeAll() {
iWarnMapper.removeAll();
}
}

@ -288,13 +288,12 @@ public class TourRunServiceImpl
* @param errorMessage 自定义错误信息result为空时的异常信息
* @return
*/
private String handleResult(JSONObject result, String errorMessage)
{
private String handleResult(JSONObject result, String errorMessage) {
if ( result != null) {
if ( !result.get(Constant.CODE).toString().equals(Constant.SUCCESS_CODE)) {
throw new ServiceException(result.get(Constant.message).toString());
}
return ((JSONObject) result.get("result")).get("accessToken").toString();
return result.getJSONObject("result").get("accessToken").toString();
}
else {
throw new ServiceException(errorMessage);

@ -35,5 +35,39 @@ id, plan_id, plan_name, start_time, end_time, create_time, creator, current_prog
</where>
order by create_time desc
</select>
<select id="removeAll">
DELETE FROM i_resource_schedule
</select>
<select id="listCheckedPlan"
parameterType="java.util.Date"
resultType="com.zilber.boot.intelligencesite.schedule.dto.PlanDTO">
SELECT
id AS id,
plan_name AS planName,
start_time AS startTime,
end_time AS endTime,
duration AS duration,
IF(100/duration*DATEDIFF(NOW(),start_time) >= 100,100,FLOOR(duration*DATEDIFF(NOW(),start_time))) AS diff,
IFNULL(accumulative_progress, 0) AS accumulativeProgress
FROM
( SELECT
id, plan_name, start_time, end_time, duration
FROM i_production_plan
WHERE parent_id = 0
AND start_time &lt;= #{date}
) a
INNER JOIN
( SELECT
plan_id, accumulative_progress, process_date
FROM i_progress ba
INNER JOIN (SELECT plan_id AS bbId,MAX(process_date) AS real_date FROM i_progress GROUP BY plan_id) bb
ON ba.plan_id = bb.bbId AND ba.process_date = bb.real_date
WHERE parent_id = 0
AND process_date = (SELECT MAX(process_date) FROM i_progress bb WHERE bb.plan_id = ba.plan_id)
) b ON a.id = b.plan_id
</select>
</mapper>

@ -52,5 +52,10 @@ id, plan_id, plan_name, deviation_type, deviation_days, warn_info, create_time,
<select id="selectByPlanId" parameterType="long" resultType="com.zilber.boot.intelligencesite.entity.IWarn">
select * from i_warn where plan_id=#{id}
</select>
<select id="removeAll">
DELETE FROM i_warn
</select>
</mapper>

Loading…
Cancel
Save