|
|
|
@ -12,6 +12,7 @@ import com.gaotao.modules.pms.entity.vo.PartInformationVo; |
|
|
|
import com.gaotao.modules.pms.entity.vo.PartLabelTemplateVo; |
|
|
|
import com.gaotao.modules.pms.mapper.QcBaseInfoMapper; |
|
|
|
import com.gaotao.modules.pms.service.QcBaseInfoService; |
|
|
|
import com.gaotao.modules.sys.dao.ApiLogIdDao; |
|
|
|
import com.gaotao.modules.sys.entity.SysUserEntity; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
@ -27,6 +28,8 @@ import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import java.io.InputStream; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
@ -36,9 +39,17 @@ import java.util.Map; |
|
|
|
@Slf4j |
|
|
|
public class QcBaseInfoServiceImpl implements QcBaseInfoService { |
|
|
|
|
|
|
|
private static final String LABEL_TEMPLATE_LOG_INTERFACE_NAME = "PartLabelTemplateSetting"; |
|
|
|
private static final String LABEL_TEMPLATE_LOG_TYPE = "System"; |
|
|
|
private static final int LABEL_TEMPLATE_LOG_MAX_LENGTH = 1000; |
|
|
|
private static final DateTimeFormatter LABEL_TEMPLATE_LOG_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private QcBaseInfoMapper qcBaseInfoMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ApiLogIdDao apiLogIdDao; |
|
|
|
|
|
|
|
// ======================= 检验方法 ======================= |
|
|
|
|
|
|
|
/** |
|
|
|
@ -1412,6 +1423,9 @@ public class QcBaseInfoServiceImpl implements QcBaseInfoService { |
|
|
|
throw new RuntimeException("该标签编码已存在!"); |
|
|
|
} |
|
|
|
qcBaseInfoMapper.saveLabelTemplate(data); |
|
|
|
String operator = getCurrentUserName(data.getCreatedBy()); |
|
|
|
String message = buildSaveLabelTemplateMessage(operator, data); |
|
|
|
saveLabelTemplateSystemLog(data, message, operator); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -1420,7 +1434,12 @@ public class QcBaseInfoServiceImpl implements QcBaseInfoService { |
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public void deleteLabelTemplate(PartLabelTemplateVo data) { |
|
|
|
PartLabelTemplateVo oldData = getLabelTemplateDetail(data); |
|
|
|
qcBaseInfoMapper.deleteLabelTemplate(data); |
|
|
|
String operator = getCurrentUserName(data.getCreatedBy()); |
|
|
|
PartLabelTemplateVo logData = oldData != null ? oldData : data; |
|
|
|
String message = buildDeleteLabelTemplateMessage(operator, logData); |
|
|
|
saveLabelTemplateSystemLog(logData, message, operator); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -1429,7 +1448,167 @@ public class QcBaseInfoServiceImpl implements QcBaseInfoService { |
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public void updateLabelTemplate(PartLabelTemplateVo data) { |
|
|
|
PartLabelTemplateVo oldData = getLabelTemplateDetail(data); |
|
|
|
if (oldData != null && data.getOperationDesc() == null) { |
|
|
|
data.setOperationDesc(oldData.getOperationDesc()); |
|
|
|
} |
|
|
|
if (oldData != null && StringUtils.isBlank(data.getLabelType())) { |
|
|
|
data.setLabelType(oldData.getLabelType()); |
|
|
|
} |
|
|
|
qcBaseInfoMapper.updateLabelTemplate(data); |
|
|
|
String operator = getCurrentUserName(data.getCreatedBy()); |
|
|
|
String message = buildUpdateLabelTemplateMessage(operator, oldData, data); |
|
|
|
saveLabelTemplateSystemLog(data, message, operator); |
|
|
|
} |
|
|
|
|
|
|
|
private PartLabelTemplateVo getLabelTemplateDetail(PartLabelTemplateVo data) { |
|
|
|
List<PartLabelTemplateVo> list = qcBaseInfoMapper.getPartLabelTemplate(data); |
|
|
|
if (list == null || list.isEmpty()) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
return list.get(0); |
|
|
|
} |
|
|
|
|
|
|
|
private String getCurrentUserName(String fallbackUserName) { |
|
|
|
try { |
|
|
|
SysUserEntity user = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
if (user != null && StringUtils.isNotBlank(user.getUsername())) { |
|
|
|
return user.getUsername(); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.warn("获取当前登录用户失败,使用入参用户。", e); |
|
|
|
} |
|
|
|
return StringUtils.isNotBlank(fallbackUserName) ? fallbackUserName : "SYSTEM"; |
|
|
|
} |
|
|
|
|
|
|
|
private String buildSaveLabelTemplateMessage(String operator, PartLabelTemplateVo data) { |
|
|
|
String timeText = LocalDateTime.now().format(LABEL_TEMPLATE_LOG_TIME_FORMATTER); |
|
|
|
return String.format( |
|
|
|
"用户【%s】在【%s】新增标签模版设置:物料【%s】标签编码【%s】、标签名称【%s】、工序【%s】、默认标识【%s】", |
|
|
|
toLogValue(operator), |
|
|
|
timeText, |
|
|
|
toLogValue(data.getPartNo()), |
|
|
|
toLogValue(data.getLabelTypeTb()), |
|
|
|
toLogValue(data.getLabelType()), |
|
|
|
toLogValue(data.getOperationDesc()), |
|
|
|
toDefaultFlagText(data.getDefaultFlag()) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
private String buildDeleteLabelTemplateMessage(String operator, PartLabelTemplateVo data) { |
|
|
|
String timeText = LocalDateTime.now().format(LABEL_TEMPLATE_LOG_TIME_FORMATTER); |
|
|
|
return String.format( |
|
|
|
"用户【%s】在【%s】删除标签模版设置:物料【%s】标签编码【%s】、标签名称【%s】、工序【%s】、默认标识【%s】", |
|
|
|
toLogValue(operator), |
|
|
|
timeText, |
|
|
|
toLogValue(data.getPartNo()), |
|
|
|
toLogValue(data.getLabelTypeTb()), |
|
|
|
toLogValue(data.getLabelType()), |
|
|
|
toLogValue(data.getOperationDesc()), |
|
|
|
toDefaultFlagText(data.getDefaultFlag()) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
private String buildUpdateLabelTemplateMessage(String operator, PartLabelTemplateVo oldData, PartLabelTemplateVo newData) { |
|
|
|
String timeText = LocalDateTime.now().format(LABEL_TEMPLATE_LOG_TIME_FORMATTER); |
|
|
|
String oldDefault = oldData != null ? oldData.getDefaultFlag() : null; |
|
|
|
String oldOperationDesc = oldData != null ? oldData.getOperationDesc() : null; |
|
|
|
StringBuilder changeBuilder = new StringBuilder(); |
|
|
|
appendChangedField(changeBuilder, "默认标识", toDefaultFlagText(oldDefault), toDefaultFlagText(newData.getDefaultFlag())); |
|
|
|
appendChangedField(changeBuilder, "工序", toLogValue(oldOperationDesc), toLogValue(newData.getOperationDesc())); |
|
|
|
if (changeBuilder.length() == 0) { |
|
|
|
changeBuilder.append("未检测到属性变化"); |
|
|
|
} |
|
|
|
|
|
|
|
return String.format( |
|
|
|
"用户【%s】在【%s】编辑标签模版设置:物料【%s】标签编码【%s】;%s", |
|
|
|
toLogValue(operator), |
|
|
|
timeText, |
|
|
|
toLogValue(newData.getPartNo()), |
|
|
|
toLogValue(newData.getLabelTypeTb()), |
|
|
|
changeBuilder.toString() |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
private void appendChangedField(StringBuilder changeBuilder, String fieldName, String oldValue, String newValue) { |
|
|
|
if (StringUtils.equals(oldValue, newValue)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
if (changeBuilder.length() > 0) { |
|
|
|
changeBuilder.append(";"); |
|
|
|
} |
|
|
|
changeBuilder.append(fieldName) |
|
|
|
.append("【") |
|
|
|
.append(toLogValue(oldValue)) |
|
|
|
.append("】=>【") |
|
|
|
.append(toLogValue(newValue)) |
|
|
|
.append("】"); |
|
|
|
} |
|
|
|
|
|
|
|
private String toDefaultFlagText(String defaultFlag) { |
|
|
|
if ("1".equals(defaultFlag) || "Y".equalsIgnoreCase(defaultFlag)) { |
|
|
|
return "默认"; |
|
|
|
} |
|
|
|
if ("0".equals(defaultFlag) || "N".equalsIgnoreCase(defaultFlag)) { |
|
|
|
return "非默认"; |
|
|
|
} |
|
|
|
return toLogValue(defaultFlag); |
|
|
|
} |
|
|
|
|
|
|
|
private String toLogValue(String value) { |
|
|
|
return StringUtils.isNotBlank(value) ? value : "空"; |
|
|
|
} |
|
|
|
|
|
|
|
private void saveLabelTemplateSystemLog(PartLabelTemplateVo data, String message, String operator) { |
|
|
|
if (data == null || StringUtils.isBlank(data.getSite()) || StringUtils.isBlank(data.getBuNo())) { |
|
|
|
log.warn("标签模版设置系统日志写入跳过:site或buNo为空。"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
String requestId = null; |
|
|
|
try { |
|
|
|
requestId = apiLogIdDao.getAndIncrementRequestId(LABEL_TEMPLATE_LOG_INTERFACE_NAME); |
|
|
|
} catch (Exception e) { |
|
|
|
log.warn("获取系统日志requestId失败,改用时间戳。interfaceName: {}", LABEL_TEMPLATE_LOG_INTERFACE_NAME, e); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(requestId)) { |
|
|
|
requestId = String.valueOf(System.currentTimeMillis()); |
|
|
|
} |
|
|
|
|
|
|
|
Map<String, Object> params = new HashMap<>(); |
|
|
|
params.put("site", data.getSite()); |
|
|
|
params.put("buNo", data.getBuNo()); |
|
|
|
params.put("requestId", requestId); |
|
|
|
params.put("interfaceName", LABEL_TEMPLATE_LOG_INTERFACE_NAME); |
|
|
|
params.put("requestGroupId", 0); |
|
|
|
params.put("orderNo", data.getPartNo()); |
|
|
|
params.put("statusCode", "200"); |
|
|
|
params.put("message", truncateLogMessage(message)); |
|
|
|
params.put("sourceSystem", "WMS"); |
|
|
|
params.put("targetSystem", "WMS"); |
|
|
|
params.put("needRetryFlag", 0); |
|
|
|
params.put("retryCount", 0); |
|
|
|
params.put("maxRetryCount", 0); |
|
|
|
params.put("retryInterval", 0); |
|
|
|
params.put("type", LABEL_TEMPLATE_LOG_TYPE); |
|
|
|
params.put("createdBy", operator); |
|
|
|
|
|
|
|
qcBaseInfoMapper.saveApiSystemLog(params); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("写入标签模版设置系统日志失败,site: {}, buNo: {}, partNo: {}, error: {}", |
|
|
|
data.getSite(), data.getBuNo(), data.getPartNo(), e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private String truncateLogMessage(String message) { |
|
|
|
if (message == null) { |
|
|
|
return ""; |
|
|
|
} |
|
|
|
if (message.length() <= LABEL_TEMPLATE_LOG_MAX_LENGTH) { |
|
|
|
return message; |
|
|
|
} |
|
|
|
return message.substring(0, LABEL_TEMPLATE_LOG_MAX_LENGTH); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
|