Browse Source

生产车间负责人

master
han\hanst 3 weeks ago
parent
commit
dfa4f366b0
  1. 4
      src/main/java/com/xujie/sys/modules/erf/data/ErfExpApplyData.java
  2. 4
      src/main/java/com/xujie/sys/modules/erf/entity/ErfExpApply.java
  3. 187
      src/main/java/com/xujie/sys/modules/erf/service/impl/ErfExpApplyServiceImpl.java

4
src/main/java/com/xujie/sys/modules/erf/data/ErfExpApplyData.java

@ -221,9 +221,9 @@ public class ErfExpApplyData implements Serializable {
private String pjmLeaderName;
/**
* 生产车间负责人用户ID
* 生产车间负责人用户ID支持多选英文逗号分隔
*/
private Long workshopLeaderUserId;
private String workshopLeaderUserId;
/**
* 生产车间负责人姓名

4
src/main/java/com/xujie/sys/modules/erf/entity/ErfExpApply.java

@ -106,9 +106,9 @@ public class ErfExpApply implements Serializable {
private String pjmLeaderName;
/**
* 生产车间负责人用户ID
* 生产车间负责人用户ID支持多选英文逗号分隔
*/
private Long workshopLeaderUserId;
private String workshopLeaderUserId;
/**
* 生产车间负责人姓名

187
src/main/java/com/xujie/sys/modules/erf/service/impl/ErfExpApplyServiceImpl.java

@ -217,9 +217,7 @@ public class ErfExpApplyServiceImpl extends ServiceImpl<ErfExpApplyMapper, ErfEx
}
}
if (StringUtils.isNotBlank(data.getProjectLeader())) {
SysUserEntity userByDisplay = sysUserDao.selectOne(new QueryWrapper<SysUserEntity>()
.eq("user_display", data.getProjectLeader().trim())
.last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY"));
SysUserEntity userByDisplay = getFirstUserByDisplay(data.getProjectLeader().trim());
if (userByDisplay != null) {
data.setProjectLeaderId(userByDisplay.getUserId());
}
@ -1346,20 +1344,85 @@ public class ErfExpApplyServiceImpl extends ServiceImpl<ErfExpApplyMapper, ErfEx
* 校验生产车间负责人是否为生产车间负责人角色用户
*/
private void validateWorkshopLeader(ErfExpApplyData data) {
if (data == null || data.getWorkshopLeaderUserId() == null) {
if (data == null || StringUtils.isBlank(data.getWorkshopLeaderUserId())) {
if (data != null) {
data.setWorkshopLeaderUserId("");
data.setWorkshopLeaderName("");
}
return;
}
List<Long> workshopLeaderIds = parseUserIdCsv(data.getWorkshopLeaderUserId(), "生产车间负责人", true);
if (workshopLeaderIds.isEmpty()) {
data.setWorkshopLeaderUserId("");
data.setWorkshopLeaderName("");
return;
}
List<String> inputNameList = parseNameCsv(data.getWorkshopLeaderName());
List<String> resolvedNameList = new ArrayList<>();
for (int i = 0; i < workshopLeaderIds.size(); i++) {
Long workshopLeaderId = workshopLeaderIds.get(i);
List<UserRoleDto> roles = sysUserDao.getUserRolesByRoleNames(
data.getWorkshopLeaderUserId(), List.of("生产车间负责人"));
workshopLeaderId, List.of("生产车间负责人"));
if (roles == null || roles.isEmpty()) {
throw new XJException("生产车间负责人必须是【生产车间负责人】角色用户");
}
if (StringUtils.isBlank(data.getWorkshopLeaderName())) {
String workshopDisplay = sysUserDao.getUserDisplayById(data.getWorkshopLeaderUserId());
if (StringUtils.isNotBlank(workshopDisplay)) {
data.setWorkshopLeaderName(workshopDisplay);
String workshopDisplay = sysUserDao.getUserDisplayById(workshopLeaderId);
if (StringUtils.isBlank(workshopDisplay) && i < inputNameList.size()) {
workshopDisplay = inputNameList.get(i);
}
if (StringUtils.isBlank(workshopDisplay)) {
workshopDisplay = String.valueOf(workshopLeaderId);
}
resolvedNameList.add(workshopDisplay);
}
data.setWorkshopLeaderUserId(workshopLeaderIds.stream()
.map(String::valueOf)
.collect(Collectors.joining(",")));
data.setWorkshopLeaderName(String.join(",", resolvedNameList));
}
/**
* 解析逗号分隔用户ID串
*/
private List<Long> parseUserIdCsv(String userIdCsv, String fieldLabel, boolean strict) {
if (StringUtils.isBlank(userIdCsv)) {
return Collections.emptyList();
}
LinkedHashSet<Long> userIdSet = new LinkedHashSet<>();
String[] parts = userIdCsv.split(",");
for (String part : parts) {
String trimmed = part == null ? "" : part.trim();
if (trimmed.isEmpty()) {
continue;
}
try {
userIdSet.add(Long.valueOf(trimmed));
} catch (NumberFormatException ex) {
if (strict) {
throw new XJException(fieldLabel + "格式不正确");
}
log.warn("{}存在无法解析的用户ID: {}", fieldLabel, trimmed);
}
}
return new ArrayList<>(userIdSet);
}
/**
* 解析逗号分隔姓名串
*/
private List<String> parseNameCsv(String nameCsv) {
if (StringUtils.isBlank(nameCsv)) {
return Collections.emptyList();
}
return Arrays.stream(nameCsv.split(","))
.map(String::trim)
.filter(StringUtils::isNotBlank)
.collect(Collectors.toList());
}
/**
@ -1848,9 +1911,9 @@ public class ErfExpApplyServiceImpl extends ServiceImpl<ErfExpApplyMapper, ErfEx
addRecipientRole(recipientRoleMap, pjmLeader.getUserId(), "PJM负责人");
}
// 4. 生产车间负责人
UserEmailInfoDto workshopLeader = resolveWorkshopLeaderEmailInfo(entity);
if (workshopLeader != null) {
// 4. 生产车间负责人支持多人
List<UserEmailInfoDto> workshopLeaders = resolveWorkshopLeaderEmailInfos(entity);
for (UserEmailInfoDto workshopLeader : workshopLeaders) {
addRecipientRole(recipientRoleMap, workshopLeader.getUserId(), "生产车间负责人");
}
@ -2656,16 +2719,11 @@ public class ErfExpApplyServiceImpl extends ServiceImpl<ErfExpApplyMapper, ErfEx
*/
private void sendWorkshopLeaderApprovalPassedNotification(ErfExpApply entity) {
try {
UserEmailInfoDto workshopLeader = resolveWorkshopLeaderEmailInfo(entity);
if (workshopLeader == null) {
List<UserEmailInfoDto> workshopLeaderList = resolveWorkshopLeaderEmailInfos(entity);
if (workshopLeaderList.isEmpty()) {
log.info("未维护生产车间负责人或无法解析邮箱,跳过审批通过通知: applyNo={}", entity.getApplyNo());
return;
}
String email = workshopLeader.getEmail();
if (email == null || email.trim().isEmpty()) {
log.warn("生产车间负责人 {} 未配置邮箱,跳过审批通过通知", workshopLeader.getUsername());
return;
}
MailSendAddressData mailSendData = qcMapper.getSendMailFromAddress();
if (mailSendData == null) {
@ -2682,9 +2740,22 @@ public class ErfExpApplyServiceImpl extends ServiceImpl<ErfExpApplyMapper, ErfEx
String subject = String.format("【工程试验申请审批通过】%s - %s",
entity.getApplyNo(), entity.getTitle() != null ? entity.getTitle() : "");
String tableBody = buildPlannerNotificationTable(entity, todayStr, expectedFinishDateStr);
List<MailUtil.MailAttachment> attachments = collectErfApplyMailAttachments(entity.getApplyNo());
List<String> successEmailList = new ArrayList<>();
for (UserEmailInfoDto workshopLeader : workshopLeaderList) {
String email = workshopLeader.getEmail();
if (StringUtils.isBlank(email)) {
log.warn("生产车间负责人 {} 未配置邮箱,跳过审批通过通知", workshopLeader.getUsername());
continue;
}
String displayName = StringUtils.isNotBlank(workshopLeader.getUsername())
? workshopLeader.getUsername()
: String.valueOf(workshopLeader.getUserId());
String body = "<html><body>"
+ "<h3>尊敬的 " + workshopLeader.getUsername() + ":</h3>"
+ "<h3>尊敬的 " + displayName + ":</h3>"
+ "<p>您好!以下工程试验单的三类经理审批已全部完成,您作为生产车间负责人请知悉并关注后续排产执行。</p>"
+ "<p>当前流程已进入<strong>计划员排产</strong>环节。</p>"
+ "<hr/>" + tableBody
@ -2692,17 +2763,20 @@ public class ErfExpApplyServiceImpl extends ServiceImpl<ErfExpApplyMapper, ErfEx
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
+ "</p></body></html>";
List<MailUtil.MailAttachment> attachments = collectErfApplyMailAttachments(entity.getApplyNo());
MailUtil.sendMail(subject, body, new String[]{email}, mailSendData, attachments);
successEmailList.add(email);
log.info("已向生产车间负责人 {} ({}) 发送审批通过通知,试验单: {}",
workshopLeader.getUsername(), email, entity.getApplyNo());
displayName, email, entity.getApplyNo());
}
if (!successEmailList.isEmpty()) {
SendMailRecord mailRecord = new SendMailRecord();
mailRecord.setType("工程试验申请生产车间负责人审批通过通知");
mailRecord.setDocumentNo(entity.getApplyNo());
mailRecord.setRecipient(email);
mailRecord.setRecipient(String.join(";", successEmailList));
mailRecord.setSendDate(new Date());
qcMapper.saveSendMailRecord(mailRecord);
}
} catch (Exception e) {
log.error("发送生产车间负责人审批通过邮件失败,试验单: {}, 错误: {}", entity.getApplyNo(), e.getMessage(), e);
}
@ -2788,9 +2862,7 @@ public class ErfExpApplyServiceImpl extends ServiceImpl<ErfExpApplyMapper, ErfEx
}
}
if (StringUtils.isNotBlank(entity.getProjectLeader())) {
SysUserEntity u = sysUserDao.selectOne(new QueryWrapper<SysUserEntity>()
.eq("user_display", entity.getProjectLeader())
.last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY"));
SysUserEntity u = getFirstUserByDisplay(entity.getProjectLeader());
if (u != null) {
return sysUserDao.getUserEmailInfoById(u.getUserId());
}
@ -2813,9 +2885,7 @@ public class ErfExpApplyServiceImpl extends ServiceImpl<ErfExpApplyMapper, ErfEx
if (userByName != null) {
return sysUserDao.getUserEmailInfoById(userByName.getUserId());
}
SysUserEntity userByDisplay = sysUserDao.selectOne(new QueryWrapper<SysUserEntity>()
.eq("user_display", entity.getPjmLeaderName())
.last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY"));
SysUserEntity userByDisplay = getFirstUserByDisplay(entity.getPjmLeaderName());
if (userByDisplay != null) {
return sysUserDao.getUserEmailInfoById(userByDisplay.getUserId());
}
@ -2826,27 +2896,60 @@ public class ErfExpApplyServiceImpl extends ServiceImpl<ErfExpApplyMapper, ErfEx
/**
* 根据试验单上的生产车间负责人字段解析系统用户邮箱
*/
private UserEmailInfoDto resolveWorkshopLeaderEmailInfo(ErfExpApply entity) {
private List<UserEmailInfoDto> resolveWorkshopLeaderEmailInfos(ErfExpApply entity) {
if (entity == null) {
return null;
return Collections.emptyList();
}
if (entity.getWorkshopLeaderUserId() != null) {
return sysUserDao.getUserEmailInfoById(entity.getWorkshopLeaderUserId());
List<UserEmailInfoDto> workshopLeaderList = new ArrayList<>();
Set<Long> userIdSet = new LinkedHashSet<>();
List<Long> workshopLeaderIds = parseUserIdCsv(entity.getWorkshopLeaderUserId(), "生产车间负责人", false);
for (Long workshopLeaderId : workshopLeaderIds) {
UserEmailInfoDto workshopLeader = sysUserDao.getUserEmailInfoById(workshopLeaderId);
if (workshopLeader != null && userIdSet.add(workshopLeader.getUserId())) {
workshopLeaderList.add(workshopLeader);
}
if (StringUtils.isNotBlank(entity.getWorkshopLeaderName())) {
SysUserEntity userByName = sysUserDao.queryByUserName(entity.getWorkshopLeaderName());
if (userByName != null) {
return sysUserDao.getUserEmailInfoById(userByName.getUserId());
}
SysUserEntity userByDisplay = sysUserDao.selectOne(new QueryWrapper<SysUserEntity>()
.eq("user_display", entity.getWorkshopLeaderName())
.last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY"));
if (userByDisplay != null) {
return sysUserDao.getUserEmailInfoById(userByDisplay.getUserId());
for (String workshopLeaderName : parseNameCsv(entity.getWorkshopLeaderName())) {
SysUserEntity userByName = sysUserDao.queryByUserName(workshopLeaderName);
if (userByName == null) {
userByName = getFirstUserByDisplay(workshopLeaderName);
}
if (userByName == null || !userIdSet.add(userByName.getUserId())) {
continue;
}
UserEmailInfoDto workshopLeader = sysUserDao.getUserEmailInfoById(userByName.getUserId());
if (workshopLeader != null) {
workshopLeaderList.add(workshopLeader);
}
}
if (workshopLeaderList.isEmpty() && StringUtils.isNotBlank(entity.getWorkshopLeaderUserId())) {
log.warn("生产车间负责人字段无法解析有效用户,applyNo={}, workshopLeaderUserId={}, workshopLeaderName={}",
entity.getApplyNo(), entity.getWorkshopLeaderUserId(), entity.getWorkshopLeaderName());
}
return workshopLeaderList;
}
/**
* 按显示名查询首个用户按user_id升序避免使用OFFSET语法
*/
private SysUserEntity getFirstUserByDisplay(String userDisplay) {
if (StringUtils.isBlank(userDisplay)) {
return null;
}
QueryWrapper<SysUserEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_display", userDisplay).orderByAsc("user_id");
List<SysUserEntity> userList = sysUserDao.selectList(queryWrapper);
if (userList == null || userList.isEmpty()) {
return null;
}
return userList.get(0);
}
/**
* 排产完成后向仓库角色用户发送邮件通知

Loading…
Cancel
Save