
12 changed files with 267 additions and 3 deletions
@ -0,0 +1,14 @@ |
|||
package com.yxt.supervise.dispatchcenter.api.enums; |
|||
|
|||
public enum CommonConstant { |
|||
PATROLPERIOD_DAY(5),PATROLPERIOD_MONTH(2); |
|||
private int code; |
|||
|
|||
public int getCode() { |
|||
return code; |
|||
} |
|||
|
|||
CommonConstant(int code) { |
|||
this.code = code; |
|||
} |
|||
} |
@ -0,0 +1,70 @@ |
|||
package com.yxt.supervise.dispatchcenter.config; |
|||
|
|||
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
@Slf4j |
|||
@Configuration |
|||
public class XxlJobConfig { |
|||
|
|||
@Value("${xxl.job.admin.addresses}") |
|||
private String adminAddresses; |
|||
|
|||
@Value("${xxl.job.accessToken}") |
|||
private String accessToken; |
|||
|
|||
@Value("${xxl.job.executor.appname}") |
|||
private String appname; |
|||
|
|||
@Value("${xxl.job.executor.address}") |
|||
private String address; |
|||
|
|||
@Value("${xxl.job.executor.ip}") |
|||
private String ip; |
|||
|
|||
@Value("${xxl.job.executor.port}") |
|||
private int port; |
|||
|
|||
@Value("${xxl.job.executor.logpath}") |
|||
private String logPath; |
|||
|
|||
@Value("${xxl.job.executor.logretentiondays}") |
|||
private int logRetentionDays; |
|||
|
|||
|
|||
@Bean |
|||
public XxlJobSpringExecutor xxlJobExecutor() { |
|||
log.info(">>>>>>>>>>> xxl-job config init."); |
|||
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor(); |
|||
xxlJobSpringExecutor.setAdminAddresses(adminAddresses); |
|||
xxlJobSpringExecutor.setAppname(appname); |
|||
xxlJobSpringExecutor.setAddress(address); |
|||
xxlJobSpringExecutor.setIp(ip); |
|||
xxlJobSpringExecutor.setPort(port); |
|||
xxlJobSpringExecutor.setAccessToken(accessToken); |
|||
xxlJobSpringExecutor.setLogPath(logPath); |
|||
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays); |
|||
|
|||
return xxlJobSpringExecutor; |
|||
} |
|||
|
|||
/** |
|||
* 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP; |
|||
* |
|||
* 1、引入依赖: |
|||
* <dependency> |
|||
* <groupId>org.springframework.cloud</groupId> |
|||
* <artifactId>spring-cloud-commons</artifactId> |
|||
* <version>${version}</version> |
|||
* </dependency> |
|||
* |
|||
* 2、配置文件,或者容器启动变量 |
|||
* spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.' |
|||
* |
|||
* 3、获取IP |
|||
* String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); |
|||
*/ |
|||
|
|||
} |
@ -0,0 +1,135 @@ |
|||
package com.yxt.supervise.dispatchcenter.scheduing; |
|||
|
|||
import cn.hutool.core.bean.BeanUtil; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.xxl.job.core.biz.model.ReturnT; |
|||
import com.xxl.job.core.handler.annotation.XxlJob; |
|||
import com.yxt.supervise.dispatchcenter.api.dispatchorderinfo.DispatchOrderinfo; |
|||
import com.yxt.supervise.dispatchcenter.api.dispatchorderinfo.DispatchOrderinfoDto; |
|||
import com.yxt.supervise.dispatchcenter.api.dispatchpatrolplan.DispatchPatrolPlan; |
|||
import com.yxt.supervise.dispatchcenter.api.dispatchplanworker.DispatchPlanWorker; |
|||
import com.yxt.supervise.dispatchcenter.api.dispatchworker.DispatchWorkerDto; |
|||
import com.yxt.supervise.dispatchcenter.api.enums.CommonConstant; |
|||
import com.yxt.supervise.dispatchcenter.biz.dispatchorderinfo.DispatchOrderinfoService; |
|||
import com.yxt.supervise.dispatchcenter.biz.dispatchpatrolplan.DispatchPatrolPlanService; |
|||
import com.yxt.supervise.dispatchcenter.biz.dispatchplanworker.DispatchPlanWorkerService; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.CommandLineRunner; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.text.ParseException; |
|||
import java.text.SimpleDateFormat; |
|||
import java.time.LocalDate; |
|||
import java.time.format.DateTimeFormatter; |
|||
import java.util.ArrayList; |
|||
import java.util.Calendar; |
|||
import java.util.Date; |
|||
import java.util.List; |
|||
@Slf4j |
|||
@Component |
|||
public class PlanScheduing { |
|||
@Autowired |
|||
private DispatchPatrolPlanService dispatchPatrolPlanService; |
|||
@Autowired |
|||
private DispatchPlanWorkerService dispatchPlanWorkerService; |
|||
@Autowired |
|||
private DispatchOrderinfoService dispatchOrderinfoService; |
|||
@XxlJob("planScheduing") |
|||
public ReturnT<String> planScheduing(String param) throws Exception { |
|||
List<DispatchPatrolPlan> lists = dispatchPatrolPlanService.list(); |
|||
log.info("lists:{}", JSONObject.toJSONString(lists)); |
|||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|||
String today= LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
|||
//对未结束的 策略生成计划
|
|||
lists.stream() |
|||
.filter(data->data.getStartdate()!=null && data.getEnddate()!=null ) |
|||
.forEach(data->{ |
|||
|
|||
Date dEnd = null; |
|||
try { |
|||
dEnd = sdf.parse(data.getEnddate()); |
|||
} catch (ParseException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
Calendar startDate = Calendar.getInstance(); |
|||
//开始日期
|
|||
try { |
|||
startDate.setTime(sdf.parse(data.getStartdate())); |
|||
} catch (ParseException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
int type = Calendar.DAY_OF_MONTH; |
|||
|
|||
if (CommonConstant.PATROLPERIOD_MONTH.equals(data.getCycletypekey())){ |
|||
type = Calendar.MONTH; |
|||
} |
|||
|
|||
while (dEnd.after(startDate.getTime())) { |
|||
if (today.equals(sdf.format(startDate.getTime())) || |
|||
(new Date().before(startDate.getTime()))){ |
|||
List<DispatchPatrolPlan> list = dispatchPatrolPlanService |
|||
.list(new LambdaQueryWrapper<DispatchPatrolPlan>() |
|||
.eq(DispatchPatrolPlan::getSid, data.getSid())); |
|||
if (list == null || list.size()==0) |
|||
newPlanOrder(data); |
|||
break; |
|||
} |
|||
startDate.add(type,Integer.valueOf(data.getCyclevalue())); |
|||
} |
|||
} |
|||
); |
|||
|
|||
return ReturnT.SUCCESS; |
|||
} |
|||
|
|||
public DispatchOrderinfoDto newPlanOrder(DispatchPatrolPlan data) { |
|||
DispatchOrderinfoDto iesPatrolOrder = new DispatchOrderinfoDto(); |
|||
iesPatrolOrder.setCustid(data.getCustid()); // 客户ID
|
|||
iesPatrolOrder.setCustname(data.getCustname()); // 客户名称
|
|||
iesPatrolOrder.setSupervisesid(data.getSupervisesid()); // 监管公司id
|
|||
String no_s = getNo(data); |
|||
iesPatrolOrder.setOrderno(no_s); // 用法说明:工单编号规则。
|
|||
iesPatrolOrder.setOrdername(data.getCustname()); // 工单名称
|
|||
iesPatrolOrder.setOrderdegree("一般"); // 描述:1-一般;2-重要; 3-紧急;4-督办。
|
|||
iesPatrolOrder.setOrderdegreekey("1"); |
|||
iesPatrolOrder.setOrdertype(data.getPatroltype()); // 描述:1-计划巡视;
|
|||
iesPatrolOrder.setOrdertypekey(data.getPatroltypekey()); |
|||
iesPatrolOrder.setReceiveperson(data.getContactperson()); // 现场联系人
|
|||
iesPatrolOrder.setReceivetel(data.getContactphone()); // 现场联系人电话
|
|||
iesPatrolOrder.setTemplatesid(data.getTemplateid()); // templatesid
|
|||
List<DispatchPlanWorker> list = dispatchPlanWorkerService.selectByPlanSid(data.getSid()); |
|||
List<DispatchWorkerDto> workers=new ArrayList<>(); |
|||
list.forEach(l->{ |
|||
DispatchWorkerDto dd=new DispatchWorkerDto(); |
|||
BeanUtil.copyProperties(l,dd); |
|||
workers.add(dd); |
|||
}); |
|||
iesPatrolOrder.setWorkers(workers); |
|||
dispatchOrderinfoService.saveOrUpdateDto(iesPatrolOrder); |
|||
|
|||
return iesPatrolOrder; |
|||
} |
|||
|
|||
private String getNo(DispatchPatrolPlan data ) { |
|||
SimpleDateFormat sdf=new SimpleDateFormat("YYYY-MM-dd"); |
|||
int no=dispatchOrderinfoService.selectByCustSidAndDate(data.getCustid(), sdf.format(new Date())); |
|||
String no_s="01"; |
|||
if (no==0){ |
|||
no_s="01"; |
|||
} |
|||
if(no>0&&no<10){ |
|||
no++; |
|||
no_s="0"+no; |
|||
} |
|||
if(no>10){ |
|||
no++; |
|||
no_s=""+no; |
|||
} |
|||
return "GD"+sdf.format(new Date())+no_s; |
|||
} |
|||
|
|||
} |
Loading…
Reference in new issue