2022-03-11 17:33:03 +08:00
|
|
|
|
package com.xkrs.service.impl;
|
2022-03-10 19:24:42 +08:00
|
|
|
|
|
2022-03-16 12:53:49 +08:00
|
|
|
|
import com.xkrs.dao.CraftItemDao;
|
2022-03-11 17:30:56 +08:00
|
|
|
|
import com.xkrs.dao.QcItemDao;
|
|
|
|
|
import com.xkrs.dao.QcSourceDao;
|
2022-03-12 14:43:52 +08:00
|
|
|
|
import com.xkrs.dao.QcSpecDao;
|
2022-03-12 13:52:15 +08:00
|
|
|
|
import com.xkrs.encapsulation.PromptMessageEnum;
|
2022-03-16 12:53:49 +08:00
|
|
|
|
import com.xkrs.model.entity.CraftItemEntity;
|
2022-03-11 17:33:03 +08:00
|
|
|
|
import com.xkrs.model.entity.QcItemEntity;
|
|
|
|
|
import com.xkrs.model.entity.QcSourceEntity;
|
2022-03-12 14:43:52 +08:00
|
|
|
|
import com.xkrs.model.entity.QcSpecEntity;
|
2022-03-11 17:33:03 +08:00
|
|
|
|
import com.xkrs.model.qo.QcSourceQoDelete;
|
|
|
|
|
import com.xkrs.model.qo.QcSourceQoInsert;
|
|
|
|
|
import com.xkrs.service.QcSourceService;
|
|
|
|
|
import com.xkrs.util.Constant;
|
2022-03-12 13:52:15 +08:00
|
|
|
|
import com.xkrs.util.ExcelUploadUtil;
|
2022-03-11 17:33:03 +08:00
|
|
|
|
import com.xkrs.util.LocalDateUtils;
|
|
|
|
|
import com.xkrs.util.LocalStringUtils;
|
2022-03-12 13:52:15 +08:00
|
|
|
|
import org.apache.http.util.TextUtils;
|
2022-03-10 20:09:26 +08:00
|
|
|
|
import org.springframework.context.i18n.LocaleContextHolder;
|
2022-03-11 16:07:31 +08:00
|
|
|
|
import org.springframework.stereotype.Service;
|
2022-03-11 16:30:05 +08:00
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
2022-03-10 20:09:26 +08:00
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
2022-03-12 13:52:15 +08:00
|
|
|
|
import javax.transaction.Transactional;
|
2022-03-11 17:03:37 +08:00
|
|
|
|
import java.io.IOException;
|
2022-03-12 13:52:15 +08:00
|
|
|
|
import java.util.*;
|
2022-03-10 19:24:42 +08:00
|
|
|
|
|
2022-03-10 20:50:21 +08:00
|
|
|
|
import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
|
|
|
|
|
2022-03-11 16:07:31 +08:00
|
|
|
|
@Service
|
2022-03-10 19:24:42 +08:00
|
|
|
|
public class QcSourceServiceImpl implements QcSourceService {
|
2022-03-10 20:09:26 +08:00
|
|
|
|
|
|
|
|
|
private Locale locale = LocaleContextHolder.getLocale();
|
|
|
|
|
|
2022-03-16 12:53:49 +08:00
|
|
|
|
@Resource
|
|
|
|
|
private CraftItemDao craftItemDao;
|
|
|
|
|
|
2022-03-11 17:03:37 +08:00
|
|
|
|
@Resource
|
|
|
|
|
private QcItemDao qcItemDao;
|
|
|
|
|
|
2022-03-10 20:09:26 +08:00
|
|
|
|
@Resource
|
|
|
|
|
private QcSourceDao qcSourceDao;
|
|
|
|
|
|
2022-03-12 14:43:52 +08:00
|
|
|
|
@Resource
|
|
|
|
|
private QcSpecDao qcSpecDao;
|
|
|
|
|
|
2022-03-10 20:50:21 +08:00
|
|
|
|
/**
|
2022-03-11 15:37:06 +08:00
|
|
|
|
* 添加检验数据
|
2022-03-10 20:50:21 +08:00
|
|
|
|
*/
|
2022-03-10 19:33:25 +08:00
|
|
|
|
@Override
|
2022-03-11 16:30:05 +08:00
|
|
|
|
public String insertQcSource(QcSourceQoInsert insertQo, MultipartFile picture) {
|
2022-03-10 20:50:21 +08:00
|
|
|
|
String batchNo = insertQo.getBatchNo();
|
|
|
|
|
String machineNo = insertQo.getMachineNo();
|
|
|
|
|
String materialNo = insertQo.getMaterialNo();
|
|
|
|
|
String mouldNo = insertQo.getMouldNo();
|
|
|
|
|
String varietyNo = insertQo.getVarietyNo();
|
2022-03-16 12:53:49 +08:00
|
|
|
|
String craftItemNo = insertQo.getCraftItemNo();
|
2022-03-10 20:50:21 +08:00
|
|
|
|
String qcItemNo = insertQo.getQcItemNo();
|
|
|
|
|
String qcValue = insertQo.getQcValue();
|
2022-03-16 12:53:49 +08:00
|
|
|
|
Optional<CraftItemEntity> craftItemByNo = craftItemDao.findByCraftItemNo(craftItemNo);
|
|
|
|
|
if (craftItemByNo.isEmpty()) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "不存在该工艺项目,请先添加工艺项目!", locale);
|
|
|
|
|
}
|
|
|
|
|
Optional<QcItemEntity> qcItemByNo = qcItemDao.findByQcItemNo(qcItemNo);
|
|
|
|
|
if (qcItemByNo.isEmpty()) {
|
2022-03-11 17:03:37 +08:00
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "不存在该检验项目,请先添加检验项目!", locale);
|
|
|
|
|
}
|
2022-03-16 12:53:49 +08:00
|
|
|
|
if (Constant.QC_ITEM_TYPE_STRING.equals(qcItemByNo.get().getQcItemType())) {
|
2022-03-11 17:03:37 +08:00
|
|
|
|
QcSourceEntity entity = new QcSourceEntity();
|
|
|
|
|
entity.setCreateTime(LocalDateUtils.getCurrentSecond());
|
|
|
|
|
entity.setBatchNo(LocalStringUtils.formatEmptyValue(batchNo));
|
|
|
|
|
entity.setMachineNo(LocalStringUtils.formatEmptyValue(machineNo));
|
|
|
|
|
entity.setMaterialNo(LocalStringUtils.formatEmptyValue(materialNo));
|
|
|
|
|
entity.setMouldNo(LocalStringUtils.formatEmptyValue(mouldNo));
|
|
|
|
|
entity.setVarietyNo(LocalStringUtils.formatEmptyValue(varietyNo));
|
2022-03-16 12:53:49 +08:00
|
|
|
|
entity.setCraftItemNo(LocalStringUtils.formatEmptyValue(craftItemNo));
|
2022-03-11 17:03:37 +08:00
|
|
|
|
entity.setQcItemNo(LocalStringUtils.formatEmptyValue(qcItemNo));
|
|
|
|
|
entity.setQcValue(LocalStringUtils.formatEmptyValue(qcValue));
|
|
|
|
|
qcSourceDao.save(entity);
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale);
|
|
|
|
|
}
|
2022-03-16 12:53:49 +08:00
|
|
|
|
if (Constant.QC_ITEM_TYPE_PICTURE.equals(qcItemByNo.get().getQcItemType())) {
|
2022-03-11 17:03:37 +08:00
|
|
|
|
if (picture == null) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "上传图片不能为空!", locale);
|
|
|
|
|
}
|
|
|
|
|
String picturePath;
|
|
|
|
|
try {
|
|
|
|
|
picturePath = ExcelUploadUtil.memoryFile(picture, 2);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "上传图片失败!", locale);
|
|
|
|
|
}
|
|
|
|
|
QcSourceEntity entity = new QcSourceEntity();
|
|
|
|
|
entity.setCreateTime(LocalDateUtils.getCurrentSecond());
|
|
|
|
|
entity.setBatchNo(LocalStringUtils.formatEmptyValue(batchNo));
|
|
|
|
|
entity.setMachineNo(LocalStringUtils.formatEmptyValue(machineNo));
|
|
|
|
|
entity.setMaterialNo(LocalStringUtils.formatEmptyValue(materialNo));
|
|
|
|
|
entity.setMouldNo(LocalStringUtils.formatEmptyValue(mouldNo));
|
|
|
|
|
entity.setVarietyNo(LocalStringUtils.formatEmptyValue(varietyNo));
|
2022-03-16 12:53:49 +08:00
|
|
|
|
entity.setCraftItemNo(LocalStringUtils.formatEmptyValue(craftItemNo));
|
2022-03-11 17:03:37 +08:00
|
|
|
|
entity.setQcItemNo(LocalStringUtils.formatEmptyValue(qcItemNo));
|
|
|
|
|
entity.setQcValue(LocalStringUtils.formatEmptyValue(picturePath));
|
|
|
|
|
qcSourceDao.save(entity);
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale);
|
|
|
|
|
}
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "添加失败!", locale);
|
2022-03-10 19:33:25 +08:00
|
|
|
|
}
|
2022-03-11 10:28:36 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2022-03-11 15:37:06 +08:00
|
|
|
|
* 删除检验数据
|
|
|
|
|
*/
|
2022-03-12 13:52:15 +08:00
|
|
|
|
@Transactional(rollbackOn = Exception.class)
|
2022-03-11 15:37:06 +08:00
|
|
|
|
@Override
|
|
|
|
|
public String deleteQcSource(QcSourceQoDelete deleteQo) {
|
|
|
|
|
Integer id = deleteQo.getId();
|
|
|
|
|
Optional<QcSourceEntity> entityById = qcSourceDao.findById(id);
|
|
|
|
|
if (entityById.isEmpty()) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "不存在该检验数据,请先添加检验数据!", locale);
|
|
|
|
|
}
|
|
|
|
|
qcSourceDao.deleteById(id);
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "删除成功!", locale);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询检验数据
|
2022-03-11 10:28:36 +08:00
|
|
|
|
*/
|
|
|
|
|
@Override
|
2022-03-16 12:53:49 +08:00
|
|
|
|
public String queryQcSource(String batchNo, String machineNo, String materialNo, String mouldNo, String varietyNo, String craftItemNo) {
|
2022-03-12 13:52:15 +08:00
|
|
|
|
List<QcItemEntity> qcItemList = qcItemDao.findAll();
|
|
|
|
|
if (qcItemList.isEmpty()) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "未添加检验项目,请先添加检验项目!", locale);
|
2022-03-11 14:09:37 +08:00
|
|
|
|
}
|
2022-03-16 12:53:49 +08:00
|
|
|
|
List<Map<String, Object>> sourceList = qcSourceDao.queryQcSource(LocalStringUtils.formatEmptyValue(batchNo), LocalStringUtils.formatEmptyValue(machineNo), LocalStringUtils.formatEmptyValue(materialNo), LocalStringUtils.formatEmptyValue(mouldNo), LocalStringUtils.formatEmptyValue(varietyNo), LocalStringUtils.formatEmptyValue(craftItemNo));
|
2022-03-12 14:43:52 +08:00
|
|
|
|
List<Map<String, Object>> resultList = generateResultList(sourceList);
|
2022-03-12 13:52:15 +08:00
|
|
|
|
if (resultList.isEmpty()) {
|
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该检验数据的信息!", locale);
|
2022-03-11 17:23:34 +08:00
|
|
|
|
}
|
2022-03-12 13:52:15 +08:00
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, resultList, locale);
|
|
|
|
|
}
|
2022-03-11 17:23:34 +08:00
|
|
|
|
|
2022-03-12 14:43:52 +08:00
|
|
|
|
/**
|
|
|
|
|
* 生成返回结果
|
|
|
|
|
*/
|
|
|
|
|
private List<Map<String, Object>> generateResultList(List<Map<String, Object>> sourceList) {
|
2022-03-12 13:52:15 +08:00
|
|
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
|
|
if (sourceList == null || sourceList.isEmpty()) {
|
|
|
|
|
return resultList;
|
|
|
|
|
}
|
|
|
|
|
for (Map<String, Object> source : sourceList) {
|
|
|
|
|
String batchNo = (String) source.getOrDefault("batchNo", "");
|
|
|
|
|
String machineNo = (String) source.getOrDefault("machineNo", "");
|
|
|
|
|
String materialNo = (String) source.getOrDefault("materialNo", "");
|
|
|
|
|
String mouldNo = (String) source.getOrDefault("mouldNo", "");
|
|
|
|
|
String varietyNo = (String) source.getOrDefault("varietyNo", "");
|
2022-03-16 12:53:49 +08:00
|
|
|
|
String craftItemNo = (String) source.getOrDefault("craftItemNo", "");
|
2022-03-12 13:52:15 +08:00
|
|
|
|
String qcItemNo = (String) source.getOrDefault("qcItemNo", "");
|
|
|
|
|
String qcValue = (String) source.getOrDefault("qcValue", "");
|
|
|
|
|
if (TextUtils.isEmpty(qcItemNo) || TextUtils.isEmpty(qcValue)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2022-03-16 12:53:49 +08:00
|
|
|
|
String formatValue = getFormatValue(varietyNo, craftItemNo, qcItemNo, qcValue);
|
2022-03-12 13:52:15 +08:00
|
|
|
|
Map<String, Object> emptyRoom = findEmptyRoom(resultList, batchNo, qcItemNo);
|
|
|
|
|
if (emptyRoom == null) {
|
|
|
|
|
Map<String, Object> newRoom = new HashMap<>();
|
|
|
|
|
newRoom.put("batchNo", batchNo);
|
|
|
|
|
newRoom.put("machineNo", machineNo);
|
|
|
|
|
newRoom.put("materialNo", materialNo);
|
|
|
|
|
newRoom.put("mouldNo", mouldNo);
|
|
|
|
|
newRoom.put("varietyNo", varietyNo);
|
2022-03-16 12:53:49 +08:00
|
|
|
|
newRoom.put("craftItemNo", craftItemNo);
|
2022-03-12 14:43:52 +08:00
|
|
|
|
newRoom.put(qcItemNo, formatValue);
|
2022-03-12 13:52:15 +08:00
|
|
|
|
resultList.add(newRoom);
|
|
|
|
|
} else {
|
2022-03-12 14:43:52 +08:00
|
|
|
|
emptyRoom.put(qcItemNo, formatValue);
|
2022-03-12 13:52:15 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return resultList;
|
|
|
|
|
}
|
2022-03-11 17:23:34 +08:00
|
|
|
|
|
2022-03-12 14:43:52 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取添加了 ##H 或 ##L 后缀的测量值(如果可能的话)
|
|
|
|
|
*/
|
2022-03-16 12:53:49 +08:00
|
|
|
|
private String getFormatValue(String varietyNo, String craftItemNo, String qcItemNo, String qcValue) {
|
|
|
|
|
Optional<QcSpecEntity> existsQcSpecOptional = qcSpecDao.findExistsQcSpec(varietyNo, craftItemNo, qcItemNo);
|
|
|
|
|
if (existsQcSpecOptional.isEmpty()) {
|
2022-03-12 14:43:52 +08:00
|
|
|
|
return qcValue;
|
|
|
|
|
}
|
2022-03-16 12:53:49 +08:00
|
|
|
|
QcSpecEntity existsQcSpec = existsQcSpecOptional.get();
|
|
|
|
|
double valueMax = stringToDouble(existsQcSpec.getMax());
|
|
|
|
|
double valueMin = stringToDouble(existsQcSpec.getMin());
|
2022-03-12 14:43:52 +08:00
|
|
|
|
double value = stringToDouble(qcValue);
|
|
|
|
|
if (valueMax >= 0 && value >= 0 && value >= valueMax) {
|
|
|
|
|
return qcValue + "##H";
|
|
|
|
|
}
|
|
|
|
|
if (valueMin >= 0 && value >= 0 && value <= valueMin) {
|
|
|
|
|
return qcValue + "##L";
|
|
|
|
|
}
|
|
|
|
|
return qcValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 格式化字符串为Double
|
|
|
|
|
*/
|
|
|
|
|
private Double stringToDouble(String stringValue) {
|
|
|
|
|
try {
|
|
|
|
|
return Double.parseDouble(stringValue);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return -1D;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 尝试找到一个qcItemNo有空位置的Map
|
|
|
|
|
*/
|
2022-03-12 13:52:15 +08:00
|
|
|
|
private Map<String, Object> findEmptyRoom(List<Map<String, Object>> mapList, String batchNo, String qcItemNo) {
|
|
|
|
|
if (mapList == null || mapList.isEmpty() || TextUtils.isEmpty(batchNo) || TextUtils.isEmpty(qcItemNo)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
for (Map<String, Object> room : mapList) {
|
|
|
|
|
if (room.getOrDefault("batchNo", "").equals(batchNo)) {
|
|
|
|
|
if (!room.containsKey(qcItemNo)) {
|
|
|
|
|
return room;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
2022-03-11 10:28:36 +08:00
|
|
|
|
}
|
2022-03-12 13:52:15 +08:00
|
|
|
|
|
2022-03-10 19:24:42 +08:00
|
|
|
|
}
|