|
@@ -33,6 +33,7 @@ import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
import com.rongwei.rwcommon.vo.CriteriaQuery;
|
|
|
import com.rongwei.rwcommon.vo.MailDo;
|
|
|
import com.rongwei.safecommon.fegin.CXAdminFeginClient;
|
|
|
+import com.rongwei.safecommon.fegin.CXCommonFeginClient;
|
|
|
import com.rongwei.safecommon.utils.CXCommonUtils;
|
|
|
import com.rongwei.wfserver.wfcommon.sys.service.impl.ProcessServiceImpl;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
@@ -46,6 +47,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
@@ -124,6 +126,8 @@ public class ApsProcessOperationProcessEquServiceImpl extends ServiceImpl<ApsPro
|
|
|
private ApsDeliveryOffsetService apsDeliveryOffsetService;
|
|
|
@Autowired
|
|
|
private ApsDeliveryOffsetDao apsDeliveryOffsetDao;
|
|
|
+ @Resource
|
|
|
+ private CXCommonFeginClient cxCommonFeginClient;
|
|
|
|
|
|
// /**
|
|
|
// * 更新工序的待加工批次号信息
|
|
@@ -3100,7 +3104,7 @@ public class ApsProcessOperationProcessEquServiceImpl extends ServiceImpl<ApsPro
|
|
|
if (Arrays.asList("部分取消", "已完工").contains(productCardVo.getStatus())) {
|
|
|
ProductCardAndLatestScheduleEndDateVo latestScheduleEndDateVo = cardIdAndScheduleEndDateList3.stream().filter(item -> item.getCardId().equals(productCardVo.getId())).findFirst().orElse(null);
|
|
|
if (latestScheduleEndDateVo != null) {
|
|
|
- DateTime latestScheduleEndDate = latestScheduleEndDateVo.getLatestScheduleEndDate();
|
|
|
+ Date latestScheduleEndDate = latestScheduleEndDateVo.getLatestScheduleEndDate();
|
|
|
apsDeliveryOffsetDo.setActualenddate(latestScheduleEndDate);
|
|
|
}
|
|
|
} else {
|
|
@@ -3122,26 +3126,26 @@ public class ApsProcessOperationProcessEquServiceImpl extends ServiceImpl<ApsPro
|
|
|
String[] split = productCardVo.getPromiseDate().split("~");
|
|
|
DateTime promiseStartDate = DateUtil.parseDate(split[0] + " 00:00:00");
|
|
|
DateTime promiseEndDate = DateUtil.parseDate(split[1] + " 23:59:59");
|
|
|
- if (Arrays.asList("待开工", "加工中","部分取消", "已完工").contains(productCardVo.getStatus())) {
|
|
|
+ if (Arrays.asList("待开工", "加工中", "部分取消", "已完工").contains(productCardVo.getStatus())) {
|
|
|
DateTime endDate = null;
|
|
|
- if (Arrays.asList("待开工", "加工中").contains(productCardVo.getStatus())){
|
|
|
- endDate = apsDeliveryOffsetDo.getPlanenddate();
|
|
|
- }else {
|
|
|
- endDate = apsDeliveryOffsetDo.getActualenddate();
|
|
|
+ if (Arrays.asList("待开工", "加工中").contains(productCardVo.getStatus())) {
|
|
|
+ endDate = DateTime.of(apsDeliveryOffsetDo.getPlanenddate());
|
|
|
+ } else {
|
|
|
+ endDate = DateTime.of(apsDeliveryOffsetDo.getActualenddate());
|
|
|
}
|
|
|
if (endDate != null) {
|
|
|
//如果料卷计划完工时间的日期<坯料计划承诺交货期起,则=料卷计划完工时间的日期-坯料计划承诺交货期起
|
|
|
if (endDate.before(promiseStartDate)) {
|
|
|
- int offsetDay = (int)DateUtil.between(promiseStartDate, endDate, DateUnit.DAY, false);
|
|
|
+ int offsetDay = (int) DateUtil.between(promiseStartDate, endDate, DateUnit.DAY, false);
|
|
|
apsDeliveryOffsetDo.setDeliveryoffset(offsetDay);
|
|
|
// 如果料卷计划完工时间的日期>坯料计划承诺交货期止,则=料卷计划完工时间的日期-坯料计划承诺交货期止
|
|
|
} else if (endDate.after(promiseEndDate)) {
|
|
|
- int offsetDay = (int)DateUtil.between(promiseEndDate, endDate, DateUnit.DAY, false);
|
|
|
+ int offsetDay = (int) DateUtil.between(promiseEndDate, endDate, DateUnit.DAY, false);
|
|
|
apsDeliveryOffsetDo.setDeliveryoffset(offsetDay);
|
|
|
} else {
|
|
|
apsDeliveryOffsetDo.setDeliveryoffset(null);
|
|
|
}
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
apsDeliveryOffsetDo.setDeliveryoffset(null);
|
|
|
}
|
|
|
} else {
|
|
@@ -3152,28 +3156,122 @@ public class ApsProcessOperationProcessEquServiceImpl extends ServiceImpl<ApsPro
|
|
|
|
|
|
|
|
|
if (!apsProcessOperationProcessEquDos.isEmpty()) {
|
|
|
- apsProcessOperationProcessEquService.updateBatchById(apsProcessOperationProcessEquDos);
|
|
|
+ for (ApsProcessOperationProcessEquDo apsProcessOperationProcessEquDo : apsProcessOperationProcessEquDos) {
|
|
|
+ apsProcessOperationProcessEquService.update(new LambdaUpdateWrapper<ApsProcessOperationProcessEquDo>()
|
|
|
+ .set(ApsProcessOperationProcessEquDo::getTimeoffset, apsProcessOperationProcessEquDo.getTimeoffset())
|
|
|
+ .eq(ApsProcessOperationProcessEquDo::getId, apsProcessOperationProcessEquDo.getId()));
|
|
|
+ }
|
|
|
}
|
|
|
if (!needUpdateOrInsertList.isEmpty()) {
|
|
|
apsDeliveryOffsetService.saveOrUpdateBatch(needUpdateOrInsertList);
|
|
|
}
|
|
|
//反查需要删除的数据
|
|
|
List<String> needDelIdList = this.baseMapper.selectAllNeedDelIds();
|
|
|
- if (!needDelIdList.isEmpty()){
|
|
|
+ if (!needDelIdList.isEmpty()) {
|
|
|
this.baseMapper.myDeleteByIds(needDelIdList);
|
|
|
}
|
|
|
if (req.getNeedSendMessage()) {
|
|
|
- //过滤需要发送消息的数据
|
|
|
- List<ApsDeliveryOffsetDo> needSendMessageList = needUpdateOrInsertList.stream().filter(item -> Arrays.asList("待开工", "加工中").contains(item.getStatus()) && item.getDeliveryoffset() > 0).collect(Collectors.toList());
|
|
|
- if (!needSendMessageList.isEmpty()){
|
|
|
- for (ApsDeliveryOffsetDo apsDeliveryOffsetDo : needSendMessageList) {
|
|
|
- ProductCardVo productCardVo = list.stream().filter(item -> item.getId().equals(apsDeliveryOffsetDo.getId())).findFirst().orElse(null);
|
|
|
+ //发送消息和邮件
|
|
|
+ sendMessageAndEmail(needUpdateOrInsertList, list);
|
|
|
+ }
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
|
|
|
+ private void sendMessageAndEmail(List<ApsDeliveryOffsetDo> needUpdateOrInsertList, List<ProductCardVo> list) {
|
|
|
+ //过滤需要发送消息的数据
|
|
|
+ List<ApsDeliveryOffsetDo> needSendMessageList = needUpdateOrInsertList.stream().filter(item ->
|
|
|
+ Arrays.asList("待开工", "加工中").contains(item.getStatus())
|
|
|
+ && item.getDeliveryoffset() != null
|
|
|
+ && item.getDeliveryoffset() > 0).collect(Collectors.toList());
|
|
|
+ if (!needSendMessageList.isEmpty()) {
|
|
|
+ //查询每个工厂的 生产计划主任(role071)、车间调度组长(cjddzz)
|
|
|
+ List<TenantIdAndUserIdsVo> tenantIdAndUserIdsVoList = this.baseMapper.selectNeedPushMessageUsers();
|
|
|
+ Map<String, List<String>> tenantIdAndUserIdListMap = new HashMap<>();
|
|
|
+ Map<String, String> tenantIdAndEmailsListMap = new HashMap<>();
|
|
|
+ for (TenantIdAndUserIdsVo tenantIdAndUserIdsVo : tenantIdAndUserIdsVoList) {
|
|
|
+ List<String> userList = new LinkedList<>();
|
|
|
+ if (StringUtils.isNotBlank(tenantIdAndUserIdsVo.getUserIds())) {
|
|
|
+ userList = new LinkedList<>(Arrays.asList(tenantIdAndUserIdsVo.getUserIds().split(",")));
|
|
|
+ }
|
|
|
+ tenantIdAndUserIdListMap.putIfAbsent(tenantIdAndUserIdsVo.getTenantId(), userList);
|
|
|
+ tenantIdAndEmailsListMap.putIfAbsent(tenantIdAndUserIdsVo.getTenantId(), tenantIdAndUserIdsVo.getEmails());
|
|
|
+ }
|
|
|
+ //<工厂ID,<订单号,批次号集合>>
|
|
|
+ Map<String, Map<String, List<String>>> resMap = new HashMap<>();
|
|
|
+ for (ApsDeliveryOffsetDo apsDeliveryOffsetDo : needSendMessageList) {
|
|
|
+ ProductCardVo productCardVo = list.stream().filter(item -> item.getId().equals(apsDeliveryOffsetDo.getId())).findFirst().orElse(null);
|
|
|
+ if (productCardVo == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //订单号 优先使用客户订单号
|
|
|
+ String orderNo = productCardVo.getCustomOrderNo();
|
|
|
+ if (StringUtils.isBlank(orderNo)) {
|
|
|
+ orderNo = productCardVo.getOrderNo();
|
|
|
+ if (StringUtils.isBlank(orderNo)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //批次号
|
|
|
+ String blankBatchNumber = productCardVo.getBlankBatchNumber();
|
|
|
+ if (StringUtils.isBlank(blankBatchNumber)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String tenantId = productCardVo.getTenantId();
|
|
|
+ if (resMap.containsKey(tenantId)) {
|
|
|
+ Map<String, List<String>> orderMap = resMap.get(tenantId);
|
|
|
+ if (orderMap.containsKey(orderNo)) {
|
|
|
+ List<String> blankNumberList = orderMap.get(orderNo);
|
|
|
+ blankNumberList.add(blankBatchNumber);
|
|
|
+ } else {
|
|
|
+ orderMap.put(orderNo, new LinkedList<>(Collections.singletonList(blankBatchNumber)));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Map<String, List<String>> orderMap = new HashMap<>();
|
|
|
+ orderMap.put(orderNo, new LinkedList<>(Collections.singletonList(blankBatchNumber)));
|
|
|
+ resMap.put(tenantId, orderMap);
|
|
|
}
|
|
|
}
|
|
|
+ //按照工厂发送消息
|
|
|
+ for (String key : resMap.keySet()) {
|
|
|
+ Map<String, List<String>> orderMap = resMap.get(key);
|
|
|
+ List<String> messageList = new LinkedList<>();
|
|
|
+ for (String orderNo : orderMap.keySet()) {
|
|
|
+ List<String> numberList = orderMap.get(orderNo);
|
|
|
+ String message = "订单号:【" + orderNo + "】,料卷批次号:【" + String.join(",", numberList) + "】";
|
|
|
+ messageList.add(message);
|
|
|
+ }
|
|
|
+ if (messageList.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //获取此工厂需要发送通知的人的ID
|
|
|
+ List<String> userIdList = tenantIdAndUserIdListMap.getOrDefault(key, null);
|
|
|
+ if (userIdList.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //系统通知(移动端和PC端个人工作台)
|
|
|
+ CXCommonUtils.sendNotify("料卷延期",
|
|
|
+ "以下料卷预计延期,请及时调整计划:\r\n" + String.join("\r\n", messageList),
|
|
|
+ null,
|
|
|
+ userIdList,
|
|
|
+ null,
|
|
|
+ PROCESSDELAY_REMIND,
|
|
|
+ false);
|
|
|
|
|
|
+ //获取需要邮件的邮箱
|
|
|
+ String emails = tenantIdAndEmailsListMap.getOrDefault(key, null);
|
|
|
+ if (StringUtils.isBlank(emails)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //邮件提醒
|
|
|
+ MailDo mailDo = new MailDo();
|
|
|
+ mailDo.setReceiveEmail(emails.split(","));
|
|
|
+ mailDo.setNeedTransReceive(false);
|
|
|
+ mailDo.setCcEmail(new String[]{});
|
|
|
+ mailDo.setSubject("料卷延期");
|
|
|
+ mailDo.setContent("以下料卷预计延期,请及时调整计划:<br>" + String.join("<br>", messageList));
|
|
|
+ cxCommonFeginClient.sendHtmlMail(mailDo);
|
|
|
+ }
|
|
|
}
|
|
|
- return R.ok();
|
|
|
}
|
|
|
}
|
|
|
|