|
|
|
@ -1,14 +1,44 @@
|
|
|
|
|
package com.op.quality.service.impl;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
|
|
import com.op.common.core.domain.R;
|
|
|
|
|
import com.op.common.core.utils.DateUtils;
|
|
|
|
|
import com.op.common.core.utils.StringUtils;
|
|
|
|
|
import com.op.common.core.utils.bean.BeanUtils;
|
|
|
|
|
import com.op.common.core.web.domain.AjaxResult;
|
|
|
|
|
import com.op.quality.domain.*;
|
|
|
|
|
import com.op.quality.mapper.QcCheckTaskIncomeMapper;
|
|
|
|
|
import com.op.system.api.RemoteOpenService;
|
|
|
|
|
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.dto.WechartDTO;
|
|
|
|
|
import com.op.system.api.domain.mes.ProOrderWorkorderDTO;
|
|
|
|
|
import com.op.system.api.domain.quality.QcUserMaterialDTO;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import com.op.quality.mapper.QcCheckTaskDetailMapper;
|
|
|
|
|
import com.op.quality.domain.QcCheckTaskDetail;
|
|
|
|
|
import com.op.quality.service.IQcCheckTaskDetailService;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
import static com.op.common.core.web.domain.AjaxResult.error;
|
|
|
|
|
import static com.op.common.core.web.domain.AjaxResult.success;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检验任务详情Service业务层处理
|
|
|
|
@ -18,9 +48,22 @@ import com.op.quality.service.IQcCheckTaskDetailService;
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
public class QcCheckTaskDetailServiceImpl implements IQcCheckTaskDetailService {
|
|
|
|
|
protected Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private QcCheckTaskDetailMapper qcCheckTaskDetailMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private RemoteUserService remoteUserService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private QcCheckTaskIncomeMapper qcCheckTaskIncomeMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private RemoteOpenService remoteOpenService;
|
|
|
|
|
|
|
|
|
|
private static Pattern p2= Pattern.compile("<[^>]+>");
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询检验任务详情
|
|
|
|
|
*
|
|
|
|
@ -94,4 +137,106 @@ public class QcCheckTaskDetailServiceImpl implements IQcCheckTaskDetailService {
|
|
|
|
|
public int deleteQcCheckTaskDetailByRecordId(String recordId) {
|
|
|
|
|
return qcCheckTaskDetailMapper.deleteQcCheckTaskDetailByRecordId(recordId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**质量检验任务提醒,一小时后微信二次发送**/
|
|
|
|
|
@Override
|
|
|
|
|
public AjaxResult resendWXTask() {
|
|
|
|
|
|
|
|
|
|
// 加载sf-cloud库的sys_datasource
|
|
|
|
|
SysUser sysUser = new SysUser();
|
|
|
|
|
sysUser.setUserId(1L);
|
|
|
|
|
R<List<Map<String, String>>> dateSources0 = remoteUserService.getPoolNameList(sysUser);
|
|
|
|
|
List<Map<String, String>> dateSources = dateSources0.getData();
|
|
|
|
|
ExecutorService executorService = new ThreadPoolExecutor(
|
|
|
|
|
dateSources.size(),
|
|
|
|
|
dateSources.size(),
|
|
|
|
|
0L, TimeUnit.MILLISECONDS,
|
|
|
|
|
new LinkedBlockingQueue<Runnable>());
|
|
|
|
|
try {
|
|
|
|
|
dateSources.forEach(dateSource -> {
|
|
|
|
|
logger.info("++++++++++++" + dateSource.get("poolName") + "++++质量检验任务提醒,一小时后微信二次发送开始++++++++++");
|
|
|
|
|
Runnable run = () -> resendWXFunc(dateSource.get("poolName"));
|
|
|
|
|
executorService.execute(run);
|
|
|
|
|
});
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("service == resendWXTask == exception", e);
|
|
|
|
|
return error("service == resendWXTask == exception");
|
|
|
|
|
} finally {
|
|
|
|
|
executorService.shutdown();
|
|
|
|
|
}
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void resendWXFunc(String poolName){
|
|
|
|
|
DynamicDataSourceContextHolder.push(poolName); //这是数据源的key
|
|
|
|
|
List<QcCheckReportIncome> noCheckList = qcCheckTaskDetailMapper.selectNoCheckList();
|
|
|
|
|
//发企业微信--------------------开始
|
|
|
|
|
SysNoticeGroup noticeQo = new SysNoticeGroup();
|
|
|
|
|
//筛选成品检验 id 7
|
|
|
|
|
List<QcCheckReportIncome> noCheckListCP = noCheckList.stream().filter(condition -> condition.getCheckType().equals("checkTypeCP")).collect(Collectors.toList());
|
|
|
|
|
String CP = StringUtils.join(noCheckListCP.stream().map(QcCheckReportIncome::getCheckNo).collect(Collectors.toList()).toArray(),",");
|
|
|
|
|
//批次成品检验 id 12
|
|
|
|
|
List<QcCheckReportIncome> noCheckListCPPC = noCheckList.stream().filter(condition -> condition.getCheckType().equals("checkTypeCPPC")).collect(Collectors.toList());
|
|
|
|
|
String CPPC = StringUtils.join(noCheckListCPPC.stream().map(QcCheckReportIncome::getCheckNo).collect(Collectors.toList()).toArray(),",");
|
|
|
|
|
//来料检验 id 6
|
|
|
|
|
List<QcCheckReportIncome> noCheckListLL = noCheckList.stream().filter(condition -> condition.getCheckType().equals("checkTypeLL")).collect(Collectors.toList());
|
|
|
|
|
String LL = StringUtils.join(noCheckListLL.stream().map(QcCheckReportIncome::getCheckNo).collect(Collectors.toList()).toArray(),",");
|
|
|
|
|
//过程巡检 id 20
|
|
|
|
|
List<QcCheckReportIncome> noCheckListSCXJ = noCheckList.stream().filter(condition -> condition.getCheckType().equals("checkTypeSCXJ")).collect(Collectors.toList());
|
|
|
|
|
String SCXJ = StringUtils.join(noCheckListSCXJ.stream().map(QcCheckReportIncome::getCheckNo).collect(Collectors.toList()).toArray(),",");
|
|
|
|
|
//首件检验 id 19
|
|
|
|
|
List<QcCheckReportIncome> noCheckListSC = noCheckList.stream().filter(condition -> condition.getCheckType().equals("checkTypeSC")).collect(Collectors.toList());
|
|
|
|
|
String SC = StringUtils.join(noCheckListSC.stream().map(QcCheckReportIncome::getCheckNo).collect(Collectors.toList()).toArray(),",");
|
|
|
|
|
|
|
|
|
|
if(noCheckListCP != null || noCheckListCP.size() > 0) {
|
|
|
|
|
noticeQo.setNoticeId(7L);
|
|
|
|
|
sendWeChartMessage(noticeQo,CP,noCheckListCP.size()+"个成品检验",noCheckListCP);
|
|
|
|
|
}
|
|
|
|
|
if(noCheckListCPPC != null || noCheckListCPPC.size() > 0){
|
|
|
|
|
noticeQo.setNoticeId(12L);
|
|
|
|
|
sendWeChartMessage(noticeQo,CPPC,noCheckListCPPC.size()+"个批次成品检验",noCheckListCPPC);
|
|
|
|
|
}
|
|
|
|
|
if(noCheckListLL != null || noCheckListLL.size() > 0){
|
|
|
|
|
noticeQo.setNoticeId(6L);
|
|
|
|
|
sendWeChartMessage(noticeQo,LL,noCheckListLL.size()+"个来料检验",noCheckListLL);
|
|
|
|
|
}
|
|
|
|
|
if(noCheckListSCXJ != null || noCheckListSCXJ.size() > 0){
|
|
|
|
|
noticeQo.setNoticeId(20L);
|
|
|
|
|
sendWeChartMessage(noticeQo,SCXJ,noCheckListSCXJ.size()+"个过程巡检",noCheckListSCXJ);
|
|
|
|
|
}
|
|
|
|
|
if(noCheckListSC != null || noCheckListSC.size() > 0){
|
|
|
|
|
noticeQo.setNoticeId(19L);
|
|
|
|
|
sendWeChartMessage(noticeQo,SC,noCheckListSC.size()+"个首件检验",noCheckListSC);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void sendWeChartMessage(SysNoticeGroup noticeQo,String checkNoList,String message,List<QcCheckReportIncome> noCheckList){
|
|
|
|
|
if(StringUtils.isNotEmpty(checkNoList)){
|
|
|
|
|
List<SysNoticeGroup> notices = qcCheckTaskIncomeMapper.getNoticesGroup(noticeQo);
|
|
|
|
|
if(!CollectionUtils.isEmpty(notices) && notices.size() > 0) {
|
|
|
|
|
List<WechartDTO> wecharts = new ArrayList<>();
|
|
|
|
|
for (SysNoticeGroup noticedto : notices) {
|
|
|
|
|
WechartDTO wechart0 = new WechartDTO();
|
|
|
|
|
wechart0.setUserId(noticedto.getWxId());
|
|
|
|
|
String contentInfo = notices.get(0).getNoticeContent();
|
|
|
|
|
contentInfo = contentInfo.replace("${checkNo}", checkNoList + "(批量检验任务二次提醒)"+"\n");
|
|
|
|
|
Matcher m = p2.matcher(contentInfo);
|
|
|
|
|
contentInfo = m.replaceAll("");
|
|
|
|
|
wechart0.setText(contentInfo);
|
|
|
|
|
wecharts.add(wechart0);
|
|
|
|
|
}
|
|
|
|
|
logger.info("任务编号为:"+ checkNoList + "的"+ message + ",企业微信二次提醒请求:" + JSONObject.toJSONString(wecharts));
|
|
|
|
|
if (!CollectionUtils.isEmpty(wecharts)) {
|
|
|
|
|
new Thread(() -> {
|
|
|
|
|
AjaxResult result = remoteOpenService.sendWeChartMessage(wecharts);
|
|
|
|
|
logger.info("企业微信二次提醒结果:" + JSONObject.toJSONString(result));
|
|
|
|
|
}).start();
|
|
|
|
|
}
|
|
|
|
|
//发企业微信--------------------结束
|
|
|
|
|
qcCheckTaskDetailMapper.updateBatchConfirmTime(noCheckList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|