|
@@ -2,6 +2,7 @@ package com.rongwei.bscommon.sys.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.rongwei.bscommon.sys.dao.ZhcxPmqManagementDistributionDao;
|
|
|
import com.rongwei.bscommon.sys.service.ZhcxPmqManagementDistributionDetailService;
|
|
|
import com.rongwei.bscommon.sys.service.ZhcxPmqManagementDistributionService;
|
|
@@ -30,6 +31,7 @@ import java.io.File;
|
|
|
import java.sql.*;
|
|
|
import java.util.*;
|
|
|
import java.util.Date;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -245,40 +247,95 @@ public class ZhcxPmqManagementRecoredServiceImpl extends ServiceImpl<ZhcxPmqMana
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 构建2.5层三单数据(已保存)
|
|
|
+ * 构建2.5层三单数据(已保存) 不调用sqlserver查询机台状态
|
|
|
* @param id record_id
|
|
|
* @return 集合
|
|
|
*/
|
|
|
private List<ZhcxPmqManagementDistributionDo> getDistributionDataByPid(String id){
|
|
|
+ // 生成第2.5层数据结果
|
|
|
+ List<ZhcxPmqManagementDistributionDo> distributions = baseMapper.getDistributionsByPid(id);
|
|
|
+ for (ZhcxPmqManagementDistributionDo distribution : distributions) {
|
|
|
+ if(!StringUtils.isNotBlank(distribution.getId())){
|
|
|
+ distribution.setId(SecurityUtil.getUUID());
|
|
|
+ zhcxPmqManagementDistributionService.save(distribution);
|
|
|
+ }else {
|
|
|
+ zhcxPmqManagementDistributionService.updateById(distribution);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return distributions;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建2.5层三单数据(已保存) 调用sqlserver查询机台状态
|
|
|
+ * @param id record_id
|
|
|
+ */
|
|
|
+ private void getDistributionDataByPidInSqlServer(String id){
|
|
|
ZhcxPmqManagementRecoredDo recoredDo = this.getById(id);
|
|
|
// 生成第2.5层数据结果
|
|
|
List<ZhcxPmqManagementDistributionDo> distributions = baseMapper.getDistributionsByPid(id);
|
|
|
+ if(!distributions.isEmpty()){
|
|
|
// 拿到发单流水号和部门id
|
|
|
String deptid = recoredDo.getDeptid();
|
|
|
String seqno = String.valueOf(recoredDo.getSeqno());
|
|
|
// 触发器
|
|
|
boolean isSave = false;
|
|
|
int index = 0;
|
|
|
+ int naIndex = 0;
|
|
|
if(StringUtils.isNotBlank(deptid) || StringUtils.isNotBlank(seqno)){
|
|
|
Map<String, JutInfo> sqlServer = getStutasInSqlServer(deptid, seqno);
|
|
|
if(!sqlServer.isEmpty()) {
|
|
|
- for (ZhcxPmqManagementDistributionDo distribution : distributions) {
|
|
|
- // 获取机号
|
|
|
- String machineno = distribution.getMachineno();
|
|
|
- if (StringUtils.isNotBlank(machineno)) {
|
|
|
- machineno = machineno.replace("#", "");
|
|
|
- log.info("三单派单右边列表拿到的sqlServer对象:{}", sqlServer.get(machineno));
|
|
|
- if (Objects.nonNull(sqlServer.get(machineno))) {
|
|
|
- // 代表在sqlserver那边已关闭
|
|
|
- distribution.setStatus("已关闭");
|
|
|
- distribution.setRemark("NX系统关闭,SqlServerId:"+sqlServer.get(machineno).getRecordID());
|
|
|
- index++;
|
|
|
- if(!StringUtils.isNotBlank(distribution.getId())){
|
|
|
- distribution.setId(SecurityUtil.getUUID());
|
|
|
- zhcxPmqManagementDistributionService.save(distribution);
|
|
|
- if(!isSave){ isSave = true;}
|
|
|
- }else {
|
|
|
- zhcxPmqManagementDistributionService.updateById(distribution);
|
|
|
+ // 判断是否含有 0号机 -1号机
|
|
|
+ if(Objects.nonNull(sqlServer.get("-1")) || Objects.nonNull(sqlServer.get("0"))){
|
|
|
+ String status = null;
|
|
|
+ if(Objects.nonNull(sqlServer.get("-1"))){
|
|
|
+ status = sqlServer.get("-1").getStatus();
|
|
|
+ }
|
|
|
+ if(Objects.nonNull(sqlServer.get("0"))){
|
|
|
+ status = sqlServer.get("0").getStatus();
|
|
|
+ }
|
|
|
+ for (ZhcxPmqManagementDistributionDo distribution : distributions) {
|
|
|
+ // 代表在sqlserver那边已关闭
|
|
|
+ distribution.setStatus(status);
|
|
|
+ distribution.setRemark("NX系统存在0号机或-1号已关闭/NA");
|
|
|
+ index++;
|
|
|
+ if(status.equals("NA")){
|
|
|
+ naIndex++;
|
|
|
+ }
|
|
|
+ if (!StringUtils.isNotBlank(distribution.getId())) {
|
|
|
+ distribution.setId(SecurityUtil.getUUID());
|
|
|
+ zhcxPmqManagementDistributionService.save(distribution);
|
|
|
+ if (!isSave) {
|
|
|
+ isSave = true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ zhcxPmqManagementDistributionService.updateById(distribution);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ for (ZhcxPmqManagementDistributionDo distribution : distributions) {
|
|
|
+ // 获取机号
|
|
|
+ String machineno = distribution.getMachineno();
|
|
|
+ if (StringUtils.isNotBlank(machineno)) {
|
|
|
+ machineno = machineno.replace("#", "");
|
|
|
+ JutInfo jutInfo = sqlServer.get(machineno);
|
|
|
+ log.info("三单派单右边列表拿到的sqlServer对象:{}", jutInfo);
|
|
|
+ if (Objects.nonNull(jutInfo) && StringUtils.isNotBlank(jutInfo.getStatus())) {
|
|
|
+ // 代表在sqlserver那边已关闭
|
|
|
+ distribution.setStatus(jutInfo.getStatus());
|
|
|
+ distribution.setRemark("NX系统关闭/NA,SqlServerId:" + jutInfo.getRecordID());
|
|
|
+ index++;
|
|
|
+ if(jutInfo.getStatus().equals("NA")){
|
|
|
+ naIndex++;
|
|
|
+ }
|
|
|
+ if (!StringUtils.isNotBlank(distribution.getId())) {
|
|
|
+ distribution.setId(SecurityUtil.getUUID());
|
|
|
+ zhcxPmqManagementDistributionService.save(distribution);
|
|
|
+ if (!isSave) {
|
|
|
+ isSave = true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ zhcxPmqManagementDistributionService.updateById(distribution);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -287,22 +344,26 @@ public class ZhcxPmqManagementRecoredServiceImpl extends ServiceImpl<ZhcxPmqMana
|
|
|
}
|
|
|
if(isSave){
|
|
|
// 更改派单状态/更新第二层的状态
|
|
|
- int sized = (int) distributions.stream().filter(item -> !item.getStatus().equals("已关闭") && StringUtils.isEmpty(item.getConfirmer())).count();
|
|
|
+ //int sized = (int) distributions.stream().filter(item -> !item.getStatus().equals("已关闭") && StringUtils.isEmpty(item.getConfirmer())).count();
|
|
|
+ int sized = (int) distributions.stream().filter(item -> Objects.isNull(item.getStatus())).count();
|
|
|
if(sized >0){
|
|
|
recoredDo.setDispatchstatus("2");//部分派单
|
|
|
- }else {
|
|
|
+ }else{
|
|
|
recoredDo.setDispatchstatus("1");//已派单
|
|
|
}
|
|
|
- if(index == distributions.size()){
|
|
|
+ if(naIndex == distributions.size()){
|
|
|
+ recoredDo.setClosestatus("NA");
|
|
|
+ this.updateById(recoredDo);
|
|
|
+ zhcxPmqManagementDistributionDetailService.updateClosedStateInSecondFloor(id);
|
|
|
+ }else if(index == distributions.size()){
|
|
|
recoredDo.setClosestatus("已关闭");
|
|
|
this.updateById(recoredDo);
|
|
|
zhcxPmqManagementDistributionDetailService.updateClosedStateInSecondFloor(id);
|
|
|
}else {
|
|
|
this.updateById(recoredDo);
|
|
|
}
|
|
|
- log.info("更新关闭状态");
|
|
|
}
|
|
|
- return distributions;
|
|
|
+ }
|
|
|
}
|
|
|
/**
|
|
|
* 三单派单右边列表
|
|
@@ -317,7 +378,17 @@ public class ZhcxPmqManagementRecoredServiceImpl extends ServiceImpl<ZhcxPmqMana
|
|
|
log.info("三单派单右边列表连接字符串" + url);
|
|
|
try(Connection connection = DriverManager.getConnection(url,nxdbuser,nxdbpw);
|
|
|
Statement statement = connection.createStatement()) {
|
|
|
- String sqlStr = "SELECT 发单流水号,当前部门ID,机号,质检,质检确认日期,关闭状态,RecordID FROM [JUT753] WHERE 关闭状态 = '已关闭' AND [发单流水号] = N'"+seqno+"' AND [当前部门ID] = N'"+deptid+"' ";
|
|
|
+ String sqlStr = "SELECT\n" +
|
|
|
+ " 发单流水号,当前部门ID,机号,质检,质检确认日期,\n" +
|
|
|
+ " case \n" +
|
|
|
+ " WHEN (关闭状态 = '已关闭') THEN '已关闭'\n" +
|
|
|
+ " WHEN (质检 IS NOT NULL AND 质检 != '' AND 质检确认日期 IS NOT NULL AND 质检确认日期 != '') THEN '已关闭'\n" +
|
|
|
+ " WHEN ((质检 IS NULL or 质检 = '') AND 关闭状态 = 'NA') THEN 'NA'\n" +
|
|
|
+ " ELSE ''\n" +
|
|
|
+ " END AS 关闭状态,\n" +
|
|
|
+ " RecordID \n" +
|
|
|
+ "FROM [JUT753] \n" +
|
|
|
+ "WHERE [发单流水号] = N'"+seqno+"' AND [当前部门ID] = N'"+deptid+"' AND 关闭状态 IS NOT NULL";
|
|
|
ResultSet resultSet = statement.executeQuery(sqlStr);
|
|
|
while (resultSet.next()) {
|
|
|
JutInfo jutInfo = new JutInfo();
|
|
@@ -336,7 +407,12 @@ public class ZhcxPmqManagementRecoredServiceImpl extends ServiceImpl<ZhcxPmqMana
|
|
|
}
|
|
|
Map<String, JutInfo> map = new HashMap<>();
|
|
|
if(!result.isEmpty()){
|
|
|
- map = result.stream().collect(Collectors.toMap(JutInfo::getMachineno, info -> info));
|
|
|
+ map = result.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ JutInfo::getMachineno,
|
|
|
+ Function.identity(),
|
|
|
+ (existing, replacement) -> existing
|
|
|
+ ));
|
|
|
}
|
|
|
return map;
|
|
|
}
|
|
@@ -349,7 +425,19 @@ public class ZhcxPmqManagementRecoredServiceImpl extends ServiceImpl<ZhcxPmqMana
|
|
|
// 执行第2.5层保存操作
|
|
|
getDistributionDataByPid(recordId);
|
|
|
}
|
|
|
+ // 查询组装
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateClosedStatus() {
|
|
|
+ // 谨慎调用
|
|
|
+ LambdaQueryWrapper<ZhcxPmqManagementRecoredDo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(ZhcxPmqManagementRecoredDo::getDeleted,"0")
|
|
|
+ .isNotNull(ZhcxPmqManagementRecoredDo::getDeptid)
|
|
|
+ .isNotNull(ZhcxPmqManagementRecoredDo::getSeqno);
|
|
|
+ List<ZhcxPmqManagementRecoredDo> list = this.list(queryWrapper);
|
|
|
+ list.forEach(item -> getDistributionDataByPidInSqlServer(item.getId()));
|
|
|
+ }
|
|
|
}
|