merge:信保未回款预警task
This commit is contained in:
parent
4f39e70dbc
commit
632d9e21c2
@ -0,0 +1,170 @@
|
|||||||
|
package com.yem.wm.es.exportpresent.task;
|
||||||
|
|
||||||
|
import com.yem.rf.utils.RFUtils;
|
||||||
|
import com.yem.tws.common1.DateUtils;
|
||||||
|
import com.yem.wm.es.shippingdetails.util.PaymentControlUtil;
|
||||||
|
import com.yem.wm.utils.DynamicObjectUtil;
|
||||||
|
import com.yem.wm.utils.YEM;
|
||||||
|
import kd.bos.context.RequestContext;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
|
import kd.bos.exception.KDException;
|
||||||
|
import kd.bos.orm.query.QFilter;
|
||||||
|
import kd.bos.schedule.executor.AbstractTask;
|
||||||
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||||
|
import org.apache.commons.compress.utils.Lists;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 寄单放单申请收汇方式,增加销售员(根据携带当前行合同上的销售员)、应回款日期(提单日+收款天数),应回款日期不为空时,每10天给销售员发送一次消息提醒:合同:***,寄单放单单号:***,应回款日期为:***,请知悉!
|
||||||
|
* @Date: 2024/12/19 10:24
|
||||||
|
* @Created: by ZZSLL
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ExportPresentWarningTask extends AbstractTask {
|
||||||
|
@Override
|
||||||
|
public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
|
||||||
|
|
||||||
|
// boolean isSendMessage = isTenDaysAfter();
|
||||||
|
|
||||||
|
QFilter qFilter = RFUtils.getBaseQFilter();
|
||||||
|
qFilter.and(new QFilter("yem_isladingbill", "=", "A"));
|
||||||
|
String selectfields = DynamicObjectUtil.getSelectfields("yem_es_exportpresent");
|
||||||
|
selectfields = DynamicObjectUtil.getEntrySelectfields(selectfields, "yem_es_exportpresent", "yem_es_exportpre_erw");
|
||||||
|
DynamicObject[] load = BusinessDataServiceHelper.load("yem_es_exportpresent", selectfields, qFilter.toArray());
|
||||||
|
// 订舱单号-提单日期
|
||||||
|
Map<String, Date> ladingDateMap = new HashMap<>();
|
||||||
|
// 合同号-是否合同回款完成
|
||||||
|
Map<String, Boolean> isClaimFinishedMap = new HashMap<>();
|
||||||
|
for (DynamicObject d : load) {
|
||||||
|
DynamicObjectCollection c = d.getDynamicObjectCollection("yem_es_exportpre_erw");
|
||||||
|
for (DynamicObject subD : c) {
|
||||||
|
String shipmentnum = subD.getString("yem_shipmentnum_c");
|
||||||
|
ladingDateMap.put(shipmentnum, null);
|
||||||
|
String contractnum = subD.getString("yem_contractnum_c");
|
||||||
|
|
||||||
|
isClaimFinishedMap.put(contractnum, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Object, DynamicObject> salesorders = BusinessDataServiceHelper.loadFromCache("yem_es_salesorder", "id, billno", new QFilter[]{new QFilter("billno", "in", isClaimFinishedMap.keySet())});
|
||||||
|
Map<String, Long> salesorderNo = new HashMap<>();
|
||||||
|
for (Map.Entry<Object, DynamicObject> salesorderEntry : salesorders.entrySet()) {
|
||||||
|
Long orderId = (Long) salesorderEntry.getKey();
|
||||||
|
DynamicObject order = salesorderEntry.getValue();
|
||||||
|
salesorderNo.put(order.getString("billno"), orderId);
|
||||||
|
}
|
||||||
|
Map<Object, DynamicObject> stOrder = BusinessDataServiceHelper.loadFromCache("yem_es_storagetrans", "id, billno, yem_es_salescontrac_s.yem_rapamt, yem_es_salescontrac_s.yem_contractnumbers_p, yem_es_salescontrac_s.yem_ispre", new QFilter[]{new QFilter("yem_es_salescontrac_s.yem_contractnumbers_p", "in", salesorderNo.keySet())});
|
||||||
|
// 合同号-收汇金额合计
|
||||||
|
Map<String, BigDecimal> receiveAmt = new HashMap<>();
|
||||||
|
for (DynamicObject stBill : stOrder.values()) {
|
||||||
|
DynamicObjectCollection collection = stBill.getDynamicObjectCollection("yem_es_salescontrac_s");
|
||||||
|
for (DynamicObject d : collection) {
|
||||||
|
boolean ispre = d.getBoolean("yem_ispre");
|
||||||
|
if (ispre) {
|
||||||
|
BigDecimal rapamt = d.getBigDecimal("yem_rapamt");
|
||||||
|
String contractnumbers = d.getString("yem_contractnumbers_p");
|
||||||
|
BigDecimal calc;
|
||||||
|
if (receiveAmt.containsKey(contractnumbers)) {
|
||||||
|
calc = receiveAmt.get(contractnumbers).add(rapamt);
|
||||||
|
} else {
|
||||||
|
calc = rapamt;
|
||||||
|
}
|
||||||
|
receiveAmt.put(contractnumbers, calc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, Long> salesorderEntry : salesorderNo.entrySet()) {
|
||||||
|
String billno = salesorderEntry.getKey();
|
||||||
|
DynamicObject salesorder = salesorders.get(salesorderEntry.getValue());
|
||||||
|
if (salesorder == null) continue;
|
||||||
|
BigDecimal climeAmt = PaymentControlUtil.getContractClimeAmt(salesorder, "F");
|
||||||
|
if (receiveAmt.containsKey(billno)) {
|
||||||
|
BigDecimal receive = receiveAmt.get(billno);
|
||||||
|
if (receive.compareTo(climeAmt) < 0 && isClaimFinishedMap.containsKey(billno)) {
|
||||||
|
isClaimFinishedMap.put(billno, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询提单日期
|
||||||
|
Map<Object, DynamicObject> st = BusinessDataServiceHelper.loadFromCache("yem_es_storagetrans", "id, billno, yem_tddate", new QFilter[]{new QFilter("billno", "in", ladingDateMap.keySet())});
|
||||||
|
for (DynamicObject value : st.values()) {
|
||||||
|
String billno = value.getString("billno");
|
||||||
|
Date tddate = value.getDate("yem_tddate");
|
||||||
|
ladingDateMap.put(billno, tddate);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Long, List<String>> message = new HashMap<>();
|
||||||
|
for (DynamicObject d : load) {
|
||||||
|
DynamicObjectCollection c = d.getDynamicObjectCollection("yem_es_exportpre_erw");
|
||||||
|
for (DynamicObject subD : c) {
|
||||||
|
String stno = subD.getString("yem_shipmentnum_c");
|
||||||
|
if (ladingDateMap.containsKey(stno)) {
|
||||||
|
Date date = ladingDateMap.get(stno);
|
||||||
|
if (YEM.isEmpty(date)) continue;
|
||||||
|
// 计算应回款日期 = 天数 + 提单日期
|
||||||
|
int forward = subD.getInt("yem_forward");
|
||||||
|
Date added = DateUtils.addDays(date, forward);
|
||||||
|
subD.set("yem_shdreceivedate", added);
|
||||||
|
String contractnum = subD.getString("yem_contractnum_c");
|
||||||
|
// if (isSendMessage) {
|
||||||
|
// 以认领完成
|
||||||
|
if (isClaimFinishedMap.containsKey(contractnum) && isClaimFinishedMap.get(contractnum)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
DynamicObject operator = subD.getDynamicObject("yem_operator_e");
|
||||||
|
if (operator == null) continue;
|
||||||
|
long sendUser = operator.getLong("id");
|
||||||
|
List<String> list;
|
||||||
|
if (message.containsKey(sendUser)) {
|
||||||
|
list = message.get(sendUser);
|
||||||
|
} else {
|
||||||
|
list = new ArrayList<>();
|
||||||
|
}
|
||||||
|
list.add(String.format("合同:%s,寄单放单单号:%s,应回款日期为:%s,请知悉!\n\r", contractnum, d.getString("billno"), DateUtils.getData(added, "yyyy-MM-dd")));
|
||||||
|
message.put(sendUser, list);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<String> phone = new HashSet<>();
|
||||||
|
phone.add("15771670073");
|
||||||
|
ArrayList<Long> devUserIds = Lists.newArrayList();
|
||||||
|
// 发给开发测试
|
||||||
|
DynamicObject[] users = BusinessDataServiceHelper.load("bos_user", "id, name, phone", new QFilter[]{new QFilter("phone", "in", phone)});
|
||||||
|
for (DynamicObject user : users) {
|
||||||
|
devUserIds.add(user.getLong("id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<Long, List<String>> sendMsg : message.entrySet()) {
|
||||||
|
Long userid = sendMsg.getKey();
|
||||||
|
List<String> messageContent = sendMsg.getValue();
|
||||||
|
ArrayList<Long> sendUserId = Lists.newArrayList();
|
||||||
|
sendUserId.add(userid);//销售员
|
||||||
|
sendUserId.addAll(devUserIds);
|
||||||
|
|
||||||
|
YEM.sendMessage(sendUserId, "预警消息", "回款预警", String.join("", messageContent), "预警消息");
|
||||||
|
}
|
||||||
|
|
||||||
|
SaveServiceHelper.save(load);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前日期是否是给定日期的十天后
|
||||||
|
*
|
||||||
|
* @return Boolean
|
||||||
|
*/
|
||||||
|
public static boolean isTenDaysAfter() {
|
||||||
|
// 起始日期
|
||||||
|
LocalDate startDate = LocalDate.of(2024, 12, 1);
|
||||||
|
long daysBetween = java.time.temporal.ChronoUnit.DAYS.between(startDate, LocalDate.now());
|
||||||
|
// 是否是起始日期10天后或,10*n天后
|
||||||
|
return daysBetween >= 0 && daysBetween % 10 == 0;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user