|
|
@ -1,6 +1,7 @@
|
|
|
|
package com.op.device.service.impl;
|
|
|
|
package com.op.device.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
|
import com.op.common.core.domain.R;
|
|
|
|
import com.op.common.core.domain.R;
|
|
|
|
import com.op.common.core.utils.DateUtils;
|
|
|
|
import com.op.common.core.utils.DateUtils;
|
|
|
@ -10,8 +11,12 @@ import com.op.common.core.web.domain.AjaxResult;
|
|
|
|
import com.op.device.domain.*;
|
|
|
|
import com.op.device.domain.*;
|
|
|
|
import com.op.device.mapper.*;
|
|
|
|
import com.op.device.mapper.*;
|
|
|
|
import com.op.device.service.IDeviceTaskService;
|
|
|
|
import com.op.device.service.IDeviceTaskService;
|
|
|
|
|
|
|
|
import com.op.system.api.RemoteOpenService;
|
|
|
|
import com.op.system.api.RemoteUserService;
|
|
|
|
import com.op.system.api.RemoteUserService;
|
|
|
|
|
|
|
|
import com.op.system.api.domain.SysNoticeGroup;
|
|
|
|
import com.op.system.api.domain.SysUser;
|
|
|
|
import com.op.system.api.domain.SysUser;
|
|
|
|
|
|
|
|
import com.op.system.api.domain.device.WorkOrderTangentDTO;
|
|
|
|
|
|
|
|
import com.op.system.api.domain.dto.WechartDTO;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
@ -19,12 +24,15 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.time.LocalDate;
|
|
|
|
import java.time.LocalDate;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
import static com.op.common.core.web.domain.AjaxResult.error;
|
|
|
|
import static com.op.common.core.web.domain.AjaxResult.error;
|
|
|
@ -81,6 +89,15 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private EquOperationMapper equOperationMapper;
|
|
|
|
private EquOperationMapper equOperationMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private EquRepairOrderMapper equRepairOrderMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private RemoteOpenService remoteOpenService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//全局变量
|
|
|
|
|
|
|
|
private List<String> addSpotCheckTask = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 根据点检计划生成点检任务
|
|
|
|
* 根据点检计划生成点检任务
|
|
|
|
**/
|
|
|
|
**/
|
|
|
@ -263,6 +280,102 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
logger.info("++++++++++++" + poolName + "++++点检结束++++++++++");
|
|
|
|
logger.info("++++++++++++" + poolName + "++++点检结束++++++++++");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//切线后 创建点检工单
|
|
|
|
|
|
|
|
public AjaxResult createSpotCheckWorkOrder(com.op.system.api.domain.device.WorkOrderTangentDTO workOrderTangentDTO) {
|
|
|
|
|
|
|
|
DynamicDataSourceContextHolder.push(workOrderTangentDTO.getFactoryCode());// 这是数据源的key
|
|
|
|
|
|
|
|
logger.info(workOrderTangentDTO.getFactoryCode() + "工厂切线接口传输参数:" + JSONArray.toJSONString(workOrderTangentDTO));
|
|
|
|
|
|
|
|
DynamicDataSourceContextHolder.push(workOrderTangentDTO.getFactoryCode());// 这是数据源的key
|
|
|
|
|
|
|
|
EquPlan equPlan = new EquPlan();
|
|
|
|
|
|
|
|
equPlan.setPlanType("spotInspection");
|
|
|
|
|
|
|
|
List<EquPlan> plans = deviceTaskMapper.getPlans(equPlan);//所有的
|
|
|
|
|
|
|
|
List<String> changeLineCodeList = workOrderTangentDTO.getAddLineCodes();//切线后的实际传过来的要新增的产线信息
|
|
|
|
|
|
|
|
List<EquPlan> addProducePlans = new ArrayList<>();//切线后,真正能生成的生产线 下面的设备的点检计划
|
|
|
|
|
|
|
|
List<String> addProduceLine = new ArrayList<>();//真正能生成的切线生产线
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!CollectionUtils.isEmpty(changeLineCodeList) && !CollectionUtils.isEmpty(plans)){
|
|
|
|
|
|
|
|
for(String lineCode : changeLineCodeList){
|
|
|
|
|
|
|
|
for(EquPlan plan : plans){
|
|
|
|
|
|
|
|
if(!StringUtils.isBlank(plan.getLineCode())){
|
|
|
|
|
|
|
|
if(plan.getLineCode().equals(lineCode)){
|
|
|
|
|
|
|
|
addProducePlans.add(plan);
|
|
|
|
|
|
|
|
logger.info(workOrderTangentDTO.getFactoryCode() + "工厂切线后新生成计划信息:" + JSONArray.toJSONString(plan));
|
|
|
|
|
|
|
|
addProduceLine.add(lineCode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
addProduceLine = addProduceLine.stream().distinct().collect(Collectors.toList());
|
|
|
|
|
|
|
|
logger.info(workOrderTangentDTO.getFactoryCode() + "工厂切线后新生成产线:" + JSONArray.toJSONString(addProduceLine));
|
|
|
|
|
|
|
|
addSpotCheckTask = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (EquPlan plan : addProducePlans) {
|
|
|
|
|
|
|
|
EquOrder hasTask = deviceTaskMapper.getNewTaskOrder(plan);
|
|
|
|
|
|
|
|
if (hasTask == null || Integer.parseInt(plan.getPlanLoop()) <= hasTask.getDays() || checkHourTask(hasTask, plan)) {
|
|
|
|
|
|
|
|
//生成点检计划
|
|
|
|
|
|
|
|
int m = this.createOrderPlan(plan);
|
|
|
|
|
|
|
|
if (m == 0) {
|
|
|
|
|
|
|
|
error("equ_order相关添加失败");
|
|
|
|
|
|
|
|
return error();
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.info("++++++++++++" + workOrderTangentDTO.getFactoryCode() + "++++切线后创建微信提醒开始++++++++++");
|
|
|
|
|
|
|
|
this.spotCheckSendWeChat(addProduceLine,workOrderTangentDTO);
|
|
|
|
|
|
|
|
logger.info("++++++++++++" + workOrderTangentDTO.getFactoryCode() + "++++切线后创建微信提醒结束++++++++++");
|
|
|
|
|
|
|
|
logger.info("++++++++++++" + workOrderTangentDTO.getFactoryCode() + "++++切线后创建点检工单流程结束++++++++++");
|
|
|
|
|
|
|
|
return success();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void spotCheckSendWeChat(List<String> addProduceLine, WorkOrderTangentDTO workOrderTangentDTO) {
|
|
|
|
|
|
|
|
//发企业微信--------------------开始(跟班组有关)
|
|
|
|
|
|
|
|
SimpleDateFormat myFmt=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒"); //规范时间格式
|
|
|
|
|
|
|
|
SysNoticeGroup noticeQo = new SysNoticeGroup();
|
|
|
|
|
|
|
|
noticeQo.setNoticeId(24L); //id写死了?
|
|
|
|
|
|
|
|
List<SysNoticeGroup> notices = equRepairOrderMapper.getNoticesGroup(noticeQo);
|
|
|
|
|
|
|
|
if(!CollectionUtils.isEmpty(notices)) {
|
|
|
|
|
|
|
|
List<WechartDTO> wecharts = new ArrayList<>();
|
|
|
|
|
|
|
|
List<String> userCodes = notices.stream()
|
|
|
|
|
|
|
|
.map(SysNoticeGroup::getUserCode)
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
for (SysNoticeGroup noticeDto : notices) {
|
|
|
|
|
|
|
|
WechartDTO wechart0 = new WechartDTO();
|
|
|
|
|
|
|
|
wechart0.setUserId(noticeDto.getWxId());
|
|
|
|
|
|
|
|
String contentInfo = noticeDto.getNoticeContent();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//在前端填的时候,需要判空!!!!!!
|
|
|
|
|
|
|
|
contentInfo = contentInfo
|
|
|
|
|
|
|
|
.replace("${n}", "\n")
|
|
|
|
|
|
|
|
.replace("${previousLines}", workOrderTangentDTO.getPreviousLineCodes() + "\n")//切线前产线
|
|
|
|
|
|
|
|
.replace("${currentLines}", workOrderTangentDTO.getCurrentLineCodes() + "\n")//切线后产线
|
|
|
|
|
|
|
|
.replace("${addLines}", addProduceLine + "\n")//新增产线
|
|
|
|
|
|
|
|
.replace("${changeLineType}", workOrderTangentDTO.getChangeLineType())//切线类型
|
|
|
|
|
|
|
|
.replace("${orderCode}", addSpotCheckTask + "")//点检工单号
|
|
|
|
|
|
|
|
.replace("${workOrderCode}", workOrderTangentDTO.getWorkOrderCode());//工单号
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//替换标签
|
|
|
|
|
|
|
|
Pattern p= Pattern.compile("<[^>]+>");
|
|
|
|
|
|
|
|
Matcher m = p.matcher(contentInfo);
|
|
|
|
|
|
|
|
contentInfo = m.replaceAll("");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wechart0.setText(contentInfo);
|
|
|
|
|
|
|
|
wecharts.add(wechart0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.info(workOrderTangentDTO.getChangeLineType()+ "后,企业微信提醒维修请求:" + JSONObject.toJSONString(wecharts));
|
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(wecharts)) {
|
|
|
|
|
|
|
|
new Thread(() -> {
|
|
|
|
|
|
|
|
AjaxResult wxResult = remoteOpenService.sendWeChartMessage(wecharts);
|
|
|
|
|
|
|
|
logger.info("企业微信返回结果:" + JSONObject.toJSONString(wxResult));
|
|
|
|
|
|
|
|
}).start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.info("企业微信发送维修信息成功!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void createPatrolCheckPlanFunc(String poolName) {
|
|
|
|
public void createPatrolCheckPlanFunc(String poolName) {
|
|
|
|
DynamicDataSourceContextHolder.push(poolName);// 这是数据源的key
|
|
|
|
DynamicDataSourceContextHolder.push(poolName);// 这是数据源的key
|
|
|
|
/**equ_plan equ_plan_equ**/
|
|
|
|
/**equ_plan equ_plan_equ**/
|
|
|
@ -345,6 +458,7 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
|
|
|
|
|
|
|
|
/**equ_order**/
|
|
|
|
/**equ_order**/
|
|
|
|
sce = equOrderMapper.insertEquOrder(order);
|
|
|
|
sce = equOrderMapper.insertEquOrder(order);
|
|
|
|
|
|
|
|
addSpotCheckTask.add(orderCode);//新增点检任务
|
|
|
|
System.out.println(plan.getPlanCode() + "========equ_order:" + sce);
|
|
|
|
System.out.println(plan.getPlanCode() + "========equ_order:" + sce);
|
|
|
|
/**equ_plan_equ_spare->equ_spare_apply*************************************************************/
|
|
|
|
/**equ_plan_equ_spare->equ_spare_apply*************************************************************/
|
|
|
|
EquPlanEquSpare equPlanEquSpare = new EquPlanEquSpare();
|
|
|
|
EquPlanEquSpare equPlanEquSpare = new EquPlanEquSpare();
|
|
|
@ -564,17 +678,11 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
List<String> produceLine = new ArrayList<>();
|
|
|
|
List<String> produceLine = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
for(String str : planProduceLine){
|
|
|
|
for(String str : planProduceLine){
|
|
|
|
str = str.substring(1, str.length() - 1);
|
|
|
|
JSONArray array = JSONArray.parseArray(str);
|
|
|
|
String[] subArrays = str.split("],\\[");
|
|
|
|
for (int i = 0; i < array.size(); i++) {
|
|
|
|
for (String subArrayStr : subArrays) {
|
|
|
|
JSONArray subArray = (JSONArray) array.get(i);
|
|
|
|
subArrayStr = subArrayStr.substring(1, subArrayStr.length() - 1);
|
|
|
|
for (int j = 1; j < subArray.size(); j++) {
|
|
|
|
String[] parts = subArrayStr.split("\",\"");
|
|
|
|
planProduceLineCode.add(subArray.get(j).toString());
|
|
|
|
for (int i = 1 ; i < parts.length ; i++) {
|
|
|
|
|
|
|
|
if(i == parts.length - 1){
|
|
|
|
|
|
|
|
planProduceLineCode.add(parts[i].replaceAll("\"", ""));
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
planProduceLineCode.add(parts[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -595,8 +703,8 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
produceLine = produceLine.stream().distinct().collect(Collectors.toList());
|
|
|
|
produceLine = produceLine.stream().distinct().collect(Collectors.toList());
|
|
|
|
logger.info(poolName + "工厂今日生成的产线:" + JSONArray.toJSONString(produceLine));
|
|
|
|
logger.info("工厂:" + poolName + ",时间:" + DateUtils.getDate() + ",今日生产的产线:" + JSONArray.toJSONString(produceLine));
|
|
|
|
logger.info(poolName + "工厂返回生成今日生产的产线点检计划信息:" + JSONArray.toJSONString(returnPlanList));
|
|
|
|
logger.info("工厂:" + poolName + ",时间:" + DateUtils.getDate() + "凌晨,返回今日生成的点检计划信息:" + JSONArray.toJSONString(returnPlanList));
|
|
|
|
return returnPlanList;
|
|
|
|
return returnPlanList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|