package com.mes.md.service.impl;
|
|
import cn.smallbun.screw.core.util.CollectionUtils;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
import com.mes.md.entity.KBBTJPDrawingBP;
|
import com.mes.md.entity.KBBTProgramsOperationLogBP;
|
import com.mes.md.entity.TaskingLog;
|
import com.mes.md.mapper.KBBTJPDrawingBPMapper;
|
import com.mes.md.mapper.KBBTProgramsOperationLogBPMapper;
|
import com.mes.md.mapper.TaskingLogMapper;
|
import com.mes.md.service.TaskingLogService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* <p>
|
* 服务实现类
|
* </p>
|
*
|
* @author wu
|
* @since 2024-08-28
|
*/
|
@Slf4j
|
@Service
|
public class TaskingLogServiceImpl extends MPJBaseServiceImpl<TaskingLogMapper, TaskingLog> implements TaskingLogService {
|
|
@Autowired
|
KBBTProgramsOperationLogBPMapper kBBTProgramsOperationLogBPMapper;
|
@Autowired
|
KBBTJPDrawingBPMapper kBBTJPDrawingBPMapper;
|
|
@Override
|
public List<Map> selectMechanicalReport(int dayCount, Date startDate, Date endDate, String taskType, String operationRecord, String lineType) {
|
try {
|
// 构建查询条件
|
QueryWrapper<TaskingLog> taskingWrapper = new QueryWrapper<>();
|
|
// 添加完工状态过滤
|
taskingWrapper.eq("work_state", "完工");
|
|
// 时间范围处理
|
if (startDate != null && endDate != null) {
|
taskingWrapper.ge("operation_record_time", startDate)
|
.le("operation_record_time", endDate);
|
} else if (dayCount > 0) {
|
// 如果没有时间范围,使用默认的dayCount
|
Calendar cal = Calendar.getInstance();
|
cal.setTime(new Date());
|
cal.set(Calendar.HOUR_OF_DAY, 0);
|
cal.set(Calendar.MINUTE, 0);
|
cal.set(Calendar.SECOND, 0);
|
cal.set(Calendar.MILLISECOND, 0);
|
cal.add(Calendar.DATE, 1 - dayCount);
|
Date defaultStartDate = cal.getTime();
|
Date defaultEndDate = new Date();
|
|
taskingWrapper.ge("operation_record_time", defaultStartDate)
|
.le("operation_record_time", defaultEndDate);
|
}
|
|
// 添加可选条件
|
if (taskType != null && !taskType.isEmpty()) {
|
taskingWrapper.eq("task_type", taskType);
|
}
|
if (operationRecord != null && !operationRecord.isEmpty()) {
|
taskingWrapper.like("operation_record", operationRecord);
|
}
|
if (lineType != null && !lineType.isEmpty()) {
|
taskingWrapper.apply("operation_record REGEXP '.*[^0-9]" + lineType + "$'");
|
}
|
|
// 按时间排序
|
taskingWrapper.orderByDesc("operation_record_time");
|
|
// 执行查询
|
List<Map<String, Object>> taskingList = baseMapper.selectMaps(taskingWrapper);
|
|
// 直接返回查询结果
|
return new ArrayList<>(taskingList);
|
} catch (Exception e) {
|
log.error("查询异常", e);
|
throw e;
|
}
|
}
|
|
public List<TaskingLog> findTaskingLog(){
|
return new ArrayList<TaskingLog>();
|
}
|
|
/**
|
* 查询 dayCount 天 完工数量-分线路
|
*/
|
@Override
|
public List<Map> selectTaskingLog(int dayCount) {
|
Calendar cal = Calendar.getInstance();
|
//设置当前时间
|
cal.setTime(new Date());
|
cal.set(Calendar.HOUR_OF_DAY, 0);
|
cal.set(Calendar.MINUTE, 0);
|
cal.set(Calendar.SECOND, 0);
|
cal.set(Calendar.MILLISECOND, 0);
|
cal.add(Calendar.DATE, 1-dayCount);
|
Date startDate = cal.getTime();
|
|
QueryWrapper<KBBTJPDrawingBP> queryWrapper = new QueryWrapper<>();
|
queryWrapper.select("CAST(PlanDate AS DATE) AS CreateDate,isNull(sum(task_quantity),0) as task_quantity_sum")
|
.gt("PlanDate",startDate).groupBy("CAST(PlanDate AS DATE)")
|
.orderByAsc("CAST(PlanDate AS DATE)");
|
List<Map> list=kBBTJPDrawingBPMapper.selectMaps((QueryWrapper)queryWrapper);
|
|
List<Map<String, Object>> listTasking1 = baseMapper.selectMaps(new QueryWrapper<TaskingLog>()
|
.select("task_type, operation_record, operation_mode, DATE_FORMAT(operation_record_time, '%Y-%m-%d') as operation_record_time, count(*) as count")
|
.eq("task_type", "定制")
|
.eq("operation_record", "旋转1")
|
.eq("operation_mode", "结束")
|
.gt("operation_record_time", startDate)
|
.groupBy("task_type", "operation_record", "operation_mode", "DATE_FORMAT(operation_record_time, '%Y-%m-%d')")
|
.orderByAsc("DATE_FORMAT(operation_record_time, '%Y-%m-%d')"));
|
List<Map<String, Object>> listTasking2 = baseMapper.selectMaps(new QueryWrapper<TaskingLog>()
|
.select("task_type,operation_record,operation_mode,DATE_FORMAT(operation_record_time, '%Y-%m-%d') as operation_record_time,count(1) as count")
|
.eq("task_type", "定制")
|
.eq("operation_record", "旋转2")
|
.eq("operation_mode", "结束")
|
.gt("operation_record_time", startDate)
|
.groupBy("task_type", "operation_record", "operation_mode", "DATE_FORMAT(operation_record_time, '%Y-%m-%d')")
|
.orderByAsc("DATE_FORMAT(operation_record_time, '%Y-%m-%d')"));
|
|
//标准上片记录
|
List<Map<String, Object>> loadTaskingList1 = baseMapper.selectMaps(new QueryWrapper<TaskingLog>()
|
.select("task_type, operation_record, operation_mode, DATE_FORMAT(operation_record_time, '%Y-%m-%d') as operation_record_time, count(*) as count")
|
.eq("task_type", "标准")
|
.eq("operation_record", "上片1")
|
.eq("operation_mode", "结束")
|
.gt("operation_record_time", startDate)
|
.groupBy("task_type", "operation_record", "operation_mode", "DATE_FORMAT(operation_record_time, '%Y-%m-%d')")
|
.orderByAsc("DATE_FORMAT(operation_record_time, '%Y-%m-%d')"));
|
List<Map<String, Object>> loadTaskingList2 = baseMapper.selectMaps(new QueryWrapper<TaskingLog>()
|
.select("task_type, operation_record, operation_mode, DATE_FORMAT(operation_record_time, '%Y-%m-%d') as operation_record_time, count(*) as count")
|
.eq("task_type", "标准")
|
.eq("operation_record", "上片2")
|
.eq("operation_mode", "结束")
|
.gt("operation_record_time", startDate)
|
.groupBy("task_type", "operation_record", "operation_mode", "DATE_FORMAT(operation_record_time, '%Y-%m-%d')")
|
.orderByAsc("DATE_FORMAT(operation_record_time, '%Y-%m-%d')"));
|
|
// 存储每条线路的数据
|
Map<String, Map<String, Integer>> lineDataMap = new HashMap<>();
|
lineDataMap.put("line1", new HashMap<>());
|
lineDataMap.put("line2", new HashMap<>());
|
|
// 处理第一条线路数据
|
// 处理旋转1结束记录
|
for (Map<String, Object> map : listTasking1) {
|
String date = map.get("operation_record_time").toString();
|
int count = Integer.parseInt(map.get("count").toString());
|
Map<String, Integer> line1Map = lineDataMap.get("line1");
|
line1Map.put(date, line1Map.getOrDefault(date, 0) + count);
|
}
|
// 处理线路1上片记录
|
for (Map<String, Object> map : loadTaskingList1) {
|
String date = map.get("operation_record_time").toString();
|
int count = Integer.parseInt(map.get("count").toString());
|
Map<String, Integer> line1Map = lineDataMap.get("line1");
|
line1Map.put(date, line1Map.getOrDefault(date, 0) + count);
|
}
|
|
// 处理第二条线路数据
|
// 处理旋转2结束记录
|
for (Map<String, Object> map : listTasking2) {
|
String date = map.get("operation_record_time").toString();
|
int count = Integer.parseInt(map.get("count").toString());
|
Map<String, Integer> line2Map = lineDataMap.get("line2");
|
line2Map.put(date, line2Map.getOrDefault(date, 0) + count);
|
}
|
// 处理线路2上片记录
|
for (Map<String, Object> map : loadTaskingList2) {
|
String date = map.get("operation_record_time").toString();
|
int count = Integer.parseInt(map.get("count").toString());
|
Map<String, Integer> line2Map = lineDataMap.get("line2");
|
line2Map.put(date, line2Map.getOrDefault(date, 0) + count);
|
}
|
|
|
//log.info("客户表计划量:{},{},{}",list,listTasking1,listTasking2);
|
List<Map> Result=new ArrayList<>();
|
for (int i=0;i<dayCount;i++){
|
Date thisdate=cal.getTime();
|
cal.add(Calendar.DATE, 1);
|
Map thisMap=new HashMap<>();
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
String dateString = sdf.format(thisdate);
|
thisMap.put("date",dateString);
|
|
// 获取一线数据
|
thisMap.put("line1", lineDataMap.get("line1").getOrDefault(dateString, 0));
|
|
// 获取二线数据
|
thisMap.put("line2", lineDataMap.get("line2").getOrDefault(dateString, 0));
|
|
if (list.size()>0 && list.get(0).get("CreateDate").toString().equals(dateString)){
|
thisMap.put("plan",list.get(0).get("task_quantity_sum"));
|
list.remove(0);
|
}else{
|
thisMap.put("plan",0);
|
}
|
Result.add(thisMap);
|
}
|
|
return Result;
|
}
|
/**
|
* 回传报工数据+ 设备玻璃过片记录给 九牧
|
*/
|
@Override
|
public Integer reportTaskingLog() {
|
TaskingLog updateTaskingLog = new TaskingLog();
|
updateTaskingLog.setIsSend(1);
|
baseMapper.update(updateTaskingLog, new QueryWrapper<TaskingLog>().lambda().
|
eq(TaskingLog::getIsSend, 0));
|
List<TaskingLog> listTasking = baseMapper.selectList(new QueryWrapper<TaskingLog>().lambda()
|
.eq(TaskingLog::getIsSend, 1));
|
// 判端是否为空
|
if (CollectionUtils.isNotEmpty(listTasking)) {
|
// 进行拆解封装
|
List<KBBTProgramsOperationLogBP> report = listTasking.stream().map(item -> {
|
KBBTProgramsOperationLogBP newData = new KBBTProgramsOperationLogBP();
|
newData.setGlassId(item.getGlassId());
|
newData.setState(item.getState());
|
newData.setWorkState(item.getWorkState());
|
newData.setGlassState(item.getGlassState());
|
newData.setState(item.getState());
|
newData.setScanId(item.getScanId());
|
newData.setProgramId(item.getProgramId());
|
newData.setBatchNumber(item.getBatchNumber() == null ? "" : item.getBatchNumber());
|
newData.setLineConfigurationId(item.getLineConfigurationId());
|
newData.setTaskType(item.getTaskType());
|
newData.setLength(item.getLength());
|
newData.setWidth(item.getWidth());
|
newData.setThickness(item.getThickness());
|
newData.setDrawingMarking(item.getDrawingMarking());
|
newData.setIsSilkScreen(item.getIsSilkScreen());
|
newData.setIsWorking(1);
|
newData.setSilkScreenX(item.getSilkScreenX());
|
newData.setSilkScreenY(item.getSilkScreenY());
|
newData.setR_1_1(item.getR_1_1());
|
newData.setR_1_2(item.getR_1_2());
|
newData.setR_2_1(item.getR_2_1());
|
newData.setR_2_2(item.getR_2_2());
|
newData.setR_3_1(item.getR_3_1());
|
newData.setR_3_2(item.getR_3_2());
|
newData.setR_4_1(item.getR_4_1());
|
newData.setR_4_2(item.getR_4_2());
|
newData.setSilkScreenY(item.getSilkScreenY());
|
newData.setOperationRecord(item.getOperationRecord());
|
newData.setOperationMode(item.getOperationMode());
|
newData.setOperationRecordTime(item.getOperationRecordTime());
|
newData.setCreateDate(new Date());
|
kBBTProgramsOperationLogBPMapper.insert(newData);
|
return newData;
|
}).collect(Collectors.toList());
|
updateTaskingLog.setIsSend(2);
|
|
int successfulCount = baseMapper.update(updateTaskingLog, new QueryWrapper<TaskingLog>().lambda().
|
eq(TaskingLog::getIsSend, 1));
|
log.info("未提交的数量:{} 提交数量: {} 成功数量:{}", listTasking.size(), report.size(), successfulCount);
|
return successfulCount;
|
}
|
return 0;
|
}
|
}
|