销售出库和流程生产订单的公司控制调整
This commit is contained in:
parent
2fffd8820a
commit
5f4d39777d
|
@ -1,17 +1,17 @@
|
|||
package nccloud.resources.ic.ic.saleout;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import nc.bs.businessevent.BdUpdateEvent;
|
||||
import nc.bs.businessevent.BusinessEvent;
|
||||
import nc.bs.businessevent.IBusinessEvent;
|
||||
import nc.bs.businessevent.IBusinessListener;
|
||||
import nc.bs.dao.DAOException;
|
||||
import nc.bs.framework.common.NCLocator;
|
||||
import nc.bs.ic.general.businessevent.ICGeneralCommonEvent;
|
||||
import nc.bs.trade.business.HYSuperDMO;
|
||||
import nc.itf.uap.IUAPQueryBS;
|
||||
import nc.jdbc.framework.processor.ColumnProcessor;
|
||||
import nc.jdbc.framework.processor.MapProcessor;
|
||||
import nc.vo.bd.defdoc.DefdocVO;
|
||||
import nc.vo.ic.general.define.ICBillBodyVO;
|
||||
import nc.vo.ic.m4c.entity.SaleOutHeadVO;
|
||||
import nc.vo.ic.m4c.entity.SaleOutVO;
|
||||
|
@ -20,7 +20,12 @@ import nc.vo.pub.lang.UFDouble;
|
|||
import nc.vo.pubapp.AppContext;
|
||||
import nc.vo.tmpub.util.ModuleEnum;
|
||||
import nc.vo.tmpub.util.ModuleUtil;
|
||||
import nccloud.baseapp.core.log.NCCForUAPLogger;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -30,158 +35,182 @@ import java.time.LocalDateTime;
|
|||
*/
|
||||
public class saveBeforeCheck implements IBusinessListener {
|
||||
|
||||
@Override
|
||||
public void doAction(IBusinessEvent event) throws BusinessException {
|
||||
@Override
|
||||
public void doAction(IBusinessEvent event) throws BusinessException {
|
||||
|
||||
String pk_group = AppContext.getInstance().getPkGroup();
|
||||
if (ModuleUtil.isEnableByGroup(pk_group, ModuleEnum.SSCRP, false)) {
|
||||
if (event != null) {
|
||||
Map<String, SaleOutVO[]> map = this.getBills(event);
|
||||
SaleOutVO[] obills = map.get("obj");
|
||||
// 判断是否是需要控制的业务单元
|
||||
SaleOutHeadVO parentVO = obills[0].getHead();
|
||||
String pkstockorgStr = getPk_stockorg(parentVO.getPk_org());
|
||||
if (pkstockorgStr == null || pkstockorgStr.equals("")) {
|
||||
return;
|
||||
}
|
||||
ICBillBodyVO[] childrenVO = obills[0].getChildrenVO();
|
||||
for (int i = 0; i < childrenVO.length; ++i) {
|
||||
ICBillBodyVO vo = childrenVO[i];
|
||||
Map<String, Object> valMap = getSaleorderPK(vo.getCsourcebillbid());
|
||||
if (valMap == null || valMap.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// 历史数据不考虑
|
||||
String storedDateStr = (String) valMap.get("creationtime");
|
||||
String targetDateStr = "2024-12-31 00:00:00";
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
LocalDateTime storedDate = LocalDateTime.parse(storedDateStr, formatter);
|
||||
LocalDateTime targetDate = LocalDateTime.parse(targetDateStr, formatter);
|
||||
if (storedDate.isBefore(targetDate)) {
|
||||
return;
|
||||
}
|
||||
// 销售发票表头pk_billtypecode=30-Cxx-12
|
||||
if (valMap.get("pk_billtypecode").equals("30-Cxx-12")
|
||||
|| valMap.get("pk_billtypecode").equals("30-Cxx-02")
|
||||
|| valMap.get("pk_billtypecode").equals("30-Cxx-08")
|
||||
|| valMap.get("pk_billtypecode").equals("30-Cxx-13")) {
|
||||
return;
|
||||
}
|
||||
// 销售发票表头vdef21=是
|
||||
if (valMap.get("vdef20") == null || !valMap.get("vdef20").equals("Y")) {
|
||||
throw new BusinessException("销售出库单明细" + (i + 1) + ",销售发票验证不通过,无法保存!");
|
||||
}
|
||||
if (valMap.get("sqty") == null) {
|
||||
throw new BusinessException("销售出库单明细" + (i + 1) + ",累计发货申请数量为0,无法保存!");
|
||||
} else {
|
||||
try {
|
||||
double sQty = Double.parseDouble((String) valMap.get("sqty"));// 累计发货申请数量
|
||||
UFDouble bdnumUF = vo.getNshouldassistnum();// 本单应发数量
|
||||
double bdnum = 0;
|
||||
if (bdnumUF != null) {
|
||||
bdnum = bdnumUF.getDouble();
|
||||
}
|
||||
// 应发数量判断
|
||||
Object ntotaloutnumsObj = valMap.get("ntotaloutnums");
|
||||
String ntotaloutnums = (ntotaloutnumsObj != null) ? ntotaloutnumsObj.toString() : "";
|
||||
double ntotaloutnum = (ntotaloutnums.isEmpty()) ? 0 : Double.parseDouble(ntotaloutnums);// 累计出库主数量
|
||||
String pk_group = AppContext.getInstance().getPkGroup();
|
||||
if (ModuleUtil.isEnableByGroup(pk_group, ModuleEnum.SSCRP, false)) {
|
||||
if (event != null) {
|
||||
Map<String, SaleOutVO[]> map = this.getBills(event);
|
||||
SaleOutVO[] obills = map.get("obj");
|
||||
// 判断是否是需要控制的业务单元
|
||||
SaleOutHeadVO parentVO = obills[0].getHead();
|
||||
String pkstockorgStr = getPk_stockorg(parentVO.getPk_org());
|
||||
if (pkstockorgStr == null || pkstockorgStr.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ICBillBodyVO[] childrenVO = obills[0].getChildrenVO();
|
||||
for (int i = 0; i < childrenVO.length; ++i) {
|
||||
ICBillBodyVO vo = childrenVO[i];
|
||||
Map<String, Object> valMap = getSaleorderPK(vo.getCsourcebillbid());
|
||||
if (valMap == null || valMap.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// 历史数据不考虑
|
||||
String storedDateStr = (String) valMap.get("creationtime");
|
||||
String targetDateStr = "2024-12-31 00:00:00";
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
LocalDateTime storedDate = LocalDateTime.parse(storedDateStr, formatter);
|
||||
LocalDateTime targetDate = LocalDateTime.parse(targetDateStr, formatter);
|
||||
if (storedDate.isBefore(targetDate)) {
|
||||
return;
|
||||
}
|
||||
// 销售发票表头pk_billtypecode=30-Cxx-12
|
||||
if (valMap.get("pk_billtypecode").equals("30-Cxx-12")
|
||||
|| valMap.get("pk_billtypecode").equals("30-Cxx-02")
|
||||
|| valMap.get("pk_billtypecode").equals("30-Cxx-08")
|
||||
|| valMap.get("pk_billtypecode").equals("30-Cxx-13")) {
|
||||
return;
|
||||
}
|
||||
// 销售发票表头vdef21=是
|
||||
if (valMap.get("vdef20") == null || !valMap.get("vdef20").equals("Y")) {
|
||||
throw new BusinessException("销售出库单明细" + (i + 1) + ",销售发票验证不通过,无法保存!");
|
||||
}
|
||||
if (valMap.get("sqty") == null) {
|
||||
throw new BusinessException("销售出库单明细" + (i + 1) + ",累计发货申请数量为0,无法保存!");
|
||||
} else {
|
||||
try {
|
||||
double sQty = Double.parseDouble((String) valMap.get("sqty"));// 累计发货申请数量
|
||||
UFDouble bdnumUF = vo.getNshouldassistnum();// 本单应发数量
|
||||
double bdnum = 0;
|
||||
if (bdnumUF != null) {
|
||||
bdnum = bdnumUF.getDouble();
|
||||
}
|
||||
// 应发数量判断
|
||||
Object ntotaloutnumsObj = valMap.get("ntotaloutnums");
|
||||
String ntotaloutnums = (ntotaloutnumsObj != null) ? ntotaloutnumsObj.toString() : "";
|
||||
double ntotaloutnum = (ntotaloutnums.isEmpty()) ? 0 : Double.parseDouble(ntotaloutnums);// 累计出库主数量
|
||||
|
||||
if (sQty < (ntotaloutnum + bdnum)) {
|
||||
throw new BusinessException("销售出库单明细" + (i + 1) + ",累计出库应发数量'" + (ntotaloutnum + bdnum)
|
||||
+ "'大于销售订单累计发货申请数量'" + sQty + "',无法保存!");
|
||||
}
|
||||
// 实发数量判断
|
||||
UFDouble bdsfnumUF = vo.getNassistnum();// 本单实发数量
|
||||
double bdsfnum = 0;
|
||||
if (bdsfnumUF != null) {
|
||||
bdsfnum = bdsfnumUF.getDouble();
|
||||
}
|
||||
Object nassistnumObj = valMap.get("nassistnum");
|
||||
String nassistnums = (nassistnumObj != null) ? nassistnumObj.toString() : "";
|
||||
double nassistnum = (nassistnums.isEmpty()) ? 0 : Double.parseDouble(nassistnums);// 累计出库主数量
|
||||
if (sQty < (nassistnum + bdsfnum)) {
|
||||
throw new BusinessException("销售出库单明细" + (i + 1) + ",累计出库实发数量'" + (nassistnum + bdsfnum)
|
||||
+ "'大于销售订单累计发货申请数量'" + sQty + "',无法保存!");
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
throw new BusinessException("累计发货申请数量、累计出库数量转化数值失败" + e);
|
||||
}
|
||||
}
|
||||
if (sQty < (ntotaloutnum + bdnum)) {
|
||||
throw new BusinessException("销售出库单明细" + (i + 1) + ",累计出库应发数量'" + (ntotaloutnum + bdnum)
|
||||
+ "'大于销售订单累计发货申请数量'" + sQty + "',无法保存!");
|
||||
}
|
||||
// 实发数量判断
|
||||
UFDouble bdsfnumUF = vo.getNassistnum();// 本单实发数量
|
||||
double bdsfnum = 0;
|
||||
if (bdsfnumUF != null) {
|
||||
bdsfnum = bdsfnumUF.getDouble();
|
||||
}
|
||||
Object nassistnumObj = valMap.get("nassistnum");
|
||||
String nassistnums = (nassistnumObj != null) ? nassistnumObj.toString() : "";
|
||||
double nassistnum = (nassistnums.isEmpty()) ? 0 : Double.parseDouble(nassistnums);// 累计出库主数量
|
||||
if (sQty < (nassistnum + bdsfnum)) {
|
||||
throw new BusinessException("销售出库单明细" + (i + 1) + ",累计出库实发数量'" + (nassistnum + bdsfnum)
|
||||
+ "'大于销售订单累计发货申请数量'" + sQty + "',无法保存!");
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
throw new BusinessException("累计发货申请数量、累计出库数量转化数值失败" + e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> getSaleorderPK(String csourcebillbidStr) throws BusinessException {
|
||||
IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class);
|
||||
String sql = " SELECT s.creationtime,bt.pk_billtypecode,sb.csaleorderbid,sb.vbdef2 AS sQty,\n" + "s.vdef11,\n"
|
||||
+ "si.vdef20,\n" + "sbv.nassistnum,\n" + "sbv.ntotaloutnums\n" + "FROM so_saleinvoice_b sib\n"
|
||||
+ "INNER JOIN so_saleinvoice si ON si.csaleinvoiceid = sib.csaleinvoiceid\n"
|
||||
+ "INNER JOIN so_saleorder_b sb ON sb.csaleorderbid = sib.csrcbid\n"
|
||||
+ "left join (SELECT SUM(b.nshouldassistnum) AS ntotaloutnums,sum(nassistnum) as nassistnum,c.csaleorderbid\n"
|
||||
+ "FROM so_saleorder_b c\n" + "INNER JOIN so_saleinvoice_b a ON c.csaleorderbid = a.csrcbid\n"
|
||||
+ "INNER JOIN ic_saleout_b b ON b.csourcebillbid = a.csaleinvoicebid\n" + "where a.dr=0 and b.dr=0 \n"
|
||||
+ "GROUP BY c.csaleorderbid) sbv on sbv.csaleorderbid=sb.csaleorderbid\n"
|
||||
+ "INNER JOIN so_saleorder s ON s.csaleorderid = sb.csaleorderid\n"
|
||||
+ "INNER JOIN bd_billtype bt on bt.pk_billtypeid=s.ctrantypeid\n"
|
||||
+ "INNER JOIN so_saleorder_exe se ON sb.csaleorderbid = se.csaleorderbid\n"
|
||||
+ "WHERE sib.csaleinvoicebid = '" + csourcebillbidStr + "' ";
|
||||
Map<String, Object> valList = (Map<String, Object>) queryBS.executeQuery(sql, new MapProcessor());
|
||||
return valList;
|
||||
}
|
||||
private Map<String, Object> getSaleorderPK(String csourcebillbidStr) throws BusinessException {
|
||||
IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class);
|
||||
String sql = " SELECT s.creationtime,bt.pk_billtypecode,sb.csaleorderbid,sb.vbdef2 AS sQty,\n" + "s.vdef11,\n"
|
||||
+ "si.vdef20,\n" + "sbv.nassistnum,\n" + "sbv.ntotaloutnums\n" + "FROM so_saleinvoice_b sib\n"
|
||||
+ "INNER JOIN so_saleinvoice si ON si.csaleinvoiceid = sib.csaleinvoiceid\n"
|
||||
+ "INNER JOIN so_saleorder_b sb ON sb.csaleorderbid = sib.csrcbid\n"
|
||||
+ "left join (SELECT SUM(b.nshouldassistnum) AS ntotaloutnums,sum(nassistnum) as nassistnum,c.csaleorderbid\n"
|
||||
+ "FROM so_saleorder_b c\n" + "INNER JOIN so_saleinvoice_b a ON c.csaleorderbid = a.csrcbid\n"
|
||||
+ "INNER JOIN ic_saleout_b b ON b.csourcebillbid = a.csaleinvoicebid\n" + "where a.dr=0 and b.dr=0 \n"
|
||||
+ "GROUP BY c.csaleorderbid) sbv on sbv.csaleorderbid=sb.csaleorderbid\n"
|
||||
+ "INNER JOIN so_saleorder s ON s.csaleorderid = sb.csaleorderid\n"
|
||||
+ "INNER JOIN bd_billtype bt on bt.pk_billtypeid=s.ctrantypeid\n"
|
||||
+ "INNER JOIN so_saleorder_exe se ON sb.csaleorderbid = se.csaleorderbid\n"
|
||||
+ "WHERE sib.csaleinvoicebid = '" + csourcebillbidStr + "' ";
|
||||
Map<String, Object> valList = (Map<String, Object>) queryBS.executeQuery(sql, new MapProcessor());
|
||||
return valList;
|
||||
}
|
||||
|
||||
public IUAPQueryBS getQueryService() {
|
||||
return NCLocator.getInstance().lookup(IUAPQueryBS.class);
|
||||
}
|
||||
public IUAPQueryBS getQueryService() {
|
||||
return NCLocator.getInstance().lookup(IUAPQueryBS.class);
|
||||
}
|
||||
|
||||
private Map<String, SaleOutVO[]> getBills(IBusinessEvent event) throws BusinessException {
|
||||
Object object = null;
|
||||
Object old = null;
|
||||
Map<String, SaleOutVO[]> retMap = new HashMap<>();
|
||||
// 类型判断和赋值
|
||||
if (event instanceof BusinessEvent) {
|
||||
BusinessEvent bills = (BusinessEvent) event;
|
||||
object = bills.getObject();
|
||||
} else if (event instanceof BdUpdateEvent) {
|
||||
BdUpdateEvent e = (BdUpdateEvent) event;
|
||||
object = e.getNewObject();
|
||||
old = e.getOldObject();
|
||||
} else if (event instanceof ICGeneralCommonEvent) {
|
||||
ICGeneralCommonEvent e = (ICGeneralCommonEvent) event;
|
||||
object = e.getNewObjs();
|
||||
old = e.getOldObjs();
|
||||
} else {
|
||||
throw new BusinessException("未找到单据类型");
|
||||
}
|
||||
// 将 object 和 old 转换为 SaleOutVO[] 并添加到 retMap
|
||||
retMap.put("new", toSaleOutVOArray(object));
|
||||
retMap.put("old", toSaleOutVOArray(old));
|
||||
// 根据 new 或 old 来设置 "obj"
|
||||
retMap.put("obj", retMap.get("new") != null ? retMap.get("new") : retMap.get("old"));
|
||||
return retMap;
|
||||
}
|
||||
private Map<String, SaleOutVO[]> getBills(IBusinessEvent event) throws BusinessException {
|
||||
Object object = null;
|
||||
Object old = null;
|
||||
Map<String, SaleOutVO[]> retMap = new HashMap<>();
|
||||
// 类型判断和赋值
|
||||
if (event instanceof BusinessEvent) {
|
||||
BusinessEvent bills = (BusinessEvent) event;
|
||||
object = bills.getObject();
|
||||
} else if (event instanceof BdUpdateEvent) {
|
||||
BdUpdateEvent e = (BdUpdateEvent) event;
|
||||
object = e.getNewObject();
|
||||
old = e.getOldObject();
|
||||
} else if (event instanceof ICGeneralCommonEvent) {
|
||||
ICGeneralCommonEvent e = (ICGeneralCommonEvent) event;
|
||||
object = e.getNewObjs();
|
||||
old = e.getOldObjs();
|
||||
} else {
|
||||
throw new BusinessException("未找到单据类型");
|
||||
}
|
||||
// 将 object 和 old 转换为 SaleOutVO[] 并添加到 retMap
|
||||
retMap.put("new", toSaleOutVOArray(object));
|
||||
retMap.put("old", toSaleOutVOArray(old));
|
||||
// 根据 new 或 old 来设置 "obj"
|
||||
retMap.put("obj", retMap.get("new") != null ? retMap.get("new") : retMap.get("old"));
|
||||
return retMap;
|
||||
}
|
||||
|
||||
// 辅助方法:将对象转换为 SaleOutVO 数组
|
||||
private SaleOutVO[] toSaleOutVOArray(Object object) {
|
||||
if (object == null) {
|
||||
return null;
|
||||
}
|
||||
if (object.getClass().isArray()) {
|
||||
return (SaleOutVO[]) object;
|
||||
} else {
|
||||
return new SaleOutVO[] { (SaleOutVO) object };
|
||||
}
|
||||
}
|
||||
// 辅助方法:将对象转换为 SaleOutVO 数组
|
||||
private SaleOutVO[] toSaleOutVOArray(Object object) {
|
||||
if (object == null) {
|
||||
return null;
|
||||
}
|
||||
if (object.getClass().isArray()) {
|
||||
return (SaleOutVO[]) object;
|
||||
} else {
|
||||
return new SaleOutVO[]{(SaleOutVO) object};
|
||||
}
|
||||
}
|
||||
|
||||
private String getPk_stockorg(String pk_stockorg) throws BusinessException {
|
||||
String sql = " select pk_stockorg from org_stockorg where code in ('C018','C029','C033','C039','C020','C019') and pk_stockorg='"
|
||||
+ pk_stockorg + "' ";
|
||||
String saleorderPK = (String) getQueryService().executeQuery(sql, new ColumnProcessor());
|
||||
return saleorderPK;
|
||||
}
|
||||
private String getPk_stockorg(String pk_stockorg) throws BusinessException {
|
||||
Map<String, String> defMap = checkOrgCtrl();
|
||||
if (defMap.isEmpty() || "".equals(defMap.getOrDefault("so_out", ""))) {
|
||||
return "";
|
||||
}
|
||||
String orgStr = defMap.getOrDefault("so_out", "");
|
||||
// 将数组转换为字符串,并添加单引号
|
||||
String newOrgStr = orgStr.replace(",", "','");
|
||||
String sql = " select pk_stockorg from org_stockorg where code in ('" + newOrgStr + "') and pk_stockorg='"
|
||||
+ pk_stockorg + "' ";
|
||||
NCCForUAPLogger.debug("so_out-getPk_stockorg-sql:" + sql);
|
||||
String saleorderPK = (String) getQueryService().executeQuery(sql, new ColumnProcessor());
|
||||
return saleorderPK;
|
||||
}
|
||||
|
||||
private Map<String, String> checkOrgCtrl() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
String strWhere = " pk_defdoclist in (select pk_defdoclist from bd_defdoclist where code='org-ctrl' and dr=0 ) and dr=0";
|
||||
try {
|
||||
DefdocVO[] defdocVOs = (DefdocVO[]) new HYSuperDMO().queryByWhereClause(DefdocVO.class, strWhere);
|
||||
if (defdocVOs != null && defdocVOs.length > 0) {
|
||||
for (DefdocVO defdocVO : defdocVOs) {
|
||||
map.put(defdocVO.getCode().trim(), defdocVO.getMemo());
|
||||
}
|
||||
}
|
||||
} catch (DAOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,111 +1,141 @@
|
|||
package nc.bs.mmpac.pmo.pac0002.bp.rule;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import nc.bs.dao.DAOException;
|
||||
import nc.bs.framework.common.NCLocator;
|
||||
import nc.bs.trade.business.HYSuperDMO;
|
||||
import nc.impl.pubapp.pattern.rule.IRule;
|
||||
import nc.itf.uap.IUAPQueryBS;
|
||||
import nc.jdbc.framework.processor.ColumnProcessor;
|
||||
import nc.jdbc.framework.processor.MapProcessor;
|
||||
import nc.vo.bd.defdoc.DefdocVO;
|
||||
import nc.vo.mmpac.pmo.pac0002.entity.PMOAggVO;
|
||||
import nc.vo.mmpac.pmo.pac0002.entity.PMOHeadVO;
|
||||
import nc.vo.mmpac.pmo.pac0002.entity.PMOItemVO;
|
||||
import nc.vo.pub.BusinessException;
|
||||
import nc.vo.so.m30.entity.SaleOrderBVO;
|
||||
import nccloud.baseapp.core.log.NCCForUAPLogger;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 流程生成订单保存时验证销售订单累计排产状态,并验收首付款比例 zhangxinah 适配2312
|
||||
*/
|
||||
public class saveBeforeCheckRule implements IRule<PMOAggVO> {
|
||||
|
||||
@Override
|
||||
public void process(PMOAggVO[] vos) {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
List<SaleOrderBVO> list = new ArrayList<SaleOrderBVO>();
|
||||
for (PMOAggVO vo : vos) {
|
||||
// 判断是否是需要控制的业务单元
|
||||
PMOHeadVO pmoHeadVO = vo.getParentVO();
|
||||
String pkstockorgStr = getPk_stockorg(pmoHeadVO.getPk_org());
|
||||
if (pkstockorgStr == null || pkstockorgStr.equals("")) {
|
||||
return;
|
||||
}
|
||||
PMOItemVO[] iSuperVOs = vo.getChildrenVO();
|
||||
for (int i = 0; i < iSuperVOs.length; i++) {
|
||||
PMOItemVO itemvo = iSuperVOs[i];
|
||||
// 判断是否类型是否为30
|
||||
if (itemvo.getVsrctype() == null || !itemvo.getVsrctype().equals("30")) {
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public void process(PMOAggVO[] vos) {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
List<SaleOrderBVO> list = new ArrayList<SaleOrderBVO>();
|
||||
for (PMOAggVO vo : vos) {
|
||||
// 判断是否是需要控制的业务单元
|
||||
PMOHeadVO pmoHeadVO = vo.getParentVO();
|
||||
String pkstockorgStr = getPk_stockorg(pmoHeadVO.getPk_org());
|
||||
if (pkstockorgStr == null || pkstockorgStr.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
PMOItemVO[] iSuperVOs = vo.getChildrenVO();
|
||||
for (int i = 0; i < iSuperVOs.length; i++) {
|
||||
PMOItemVO itemvo = iSuperVOs[i];
|
||||
// 判断是否类型是否为30
|
||||
if (itemvo.getVsrctype() == null || !itemvo.getVsrctype().equals("30")) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Object> valMap = getVbdef6(itemvo.getVsrcbid());
|
||||
if (valMap == null || valMap.isEmpty()) {
|
||||
throw new BusinessException("无法关联到销售订单,无法保存!");
|
||||
}
|
||||
// 销售发票表头pk_billtypecode=30-Cxx-12
|
||||
if (valMap.get("pk_billtypecode").equals("30-Cxx-12")
|
||||
|| valMap.get("pk_billtypecode").equals("30-Cxx-02")
|
||||
|| valMap.get("pk_billtypecode").equals("30-Cxx-08")
|
||||
|| valMap.get("pk_billtypecode").equals("30-Cxx-13")) {
|
||||
return;
|
||||
}
|
||||
// 历史数据不考虑
|
||||
String storedDateStr = (String) valMap.get("creationtime");
|
||||
String targetDateStr = "2024-12-27 00:00:00";
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
LocalDateTime storedDate = LocalDateTime.parse(storedDateStr, formatter);
|
||||
LocalDateTime targetDate = LocalDateTime.parse(targetDateStr, formatter);
|
||||
if (storedDate.isBefore(targetDate)) {
|
||||
return;
|
||||
}
|
||||
if (valMap.get("vbdef12") == null) {
|
||||
throw new BusinessException("生产订单明细" + (i + 1) + ",累计排产申请数量为0,无法保存!");
|
||||
} else {
|
||||
try {
|
||||
double sQty = Double.parseDouble((String) valMap.get("vbdef12"));// 累计排产申请数量
|
||||
Object ntotaloutnumsObj = valMap.get("nastnum");
|
||||
String ntotaloutnums = (ntotaloutnumsObj != null) ? ntotaloutnumsObj.toString() : "";
|
||||
double ntotaloutnum = (ntotaloutnums.isEmpty()) ? 0 : Double.parseDouble(ntotaloutnums);// 累计生产数量
|
||||
double bdnum = itemvo.getNastnum().getDouble();
|
||||
if (sQty < (ntotaloutnum + bdnum)) {
|
||||
throw new BusinessException("生产订单明细" + (i + 1) + ",累计生产数量'" + (ntotaloutnum + bdnum)
|
||||
+ "'大于销售订单累计排产申请数量'" + sQty + "',无法保存!");
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
throw new BusinessException("累计排产申请数量转化数值失败" + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (BusinessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
Map<String, Object> valMap = getVbdef6(itemvo.getVsrcbid());
|
||||
if (valMap == null || valMap.isEmpty()) {
|
||||
throw new BusinessException("无法关联到销售订单,无法保存!");
|
||||
}
|
||||
// 销售发票表头pk_billtypecode=30-Cxx-12
|
||||
if (valMap.get("pk_billtypecode").equals("30-Cxx-12")
|
||||
|| valMap.get("pk_billtypecode").equals("30-Cxx-02")
|
||||
|| valMap.get("pk_billtypecode").equals("30-Cxx-08")
|
||||
|| valMap.get("pk_billtypecode").equals("30-Cxx-13")) {
|
||||
return;
|
||||
}
|
||||
// 历史数据不考虑
|
||||
String storedDateStr = (String) valMap.get("creationtime");
|
||||
String targetDateStr = "2024-12-27 00:00:00";
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
LocalDateTime storedDate = LocalDateTime.parse(storedDateStr, formatter);
|
||||
LocalDateTime targetDate = LocalDateTime.parse(targetDateStr, formatter);
|
||||
if (storedDate.isBefore(targetDate)) {
|
||||
return;
|
||||
}
|
||||
if (valMap.get("vbdef12") == null) {
|
||||
throw new BusinessException("生产订单明细" + (i + 1) + ",累计排产申请数量为0,无法保存!");
|
||||
} else {
|
||||
try {
|
||||
double sQty = Double.parseDouble((String) valMap.get("vbdef12"));// 累计排产申请数量
|
||||
Object ntotaloutnumsObj = valMap.get("nastnum");
|
||||
String ntotaloutnums = (ntotaloutnumsObj != null) ? ntotaloutnumsObj.toString() : "";
|
||||
double ntotaloutnum = (ntotaloutnums.isEmpty()) ? 0 : Double.parseDouble(ntotaloutnums);// 累计生产数量
|
||||
double bdnum = itemvo.getNastnum().getDouble();
|
||||
if (sQty < (ntotaloutnum + bdnum)) {
|
||||
throw new BusinessException("生产订单明细" + (i + 1) + ",累计生产数量'" + (ntotaloutnum + bdnum)
|
||||
+ "'大于销售订单累计排产申请数量'" + sQty + "',无法保存!");
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
throw new BusinessException("累计排产申请数量转化数值失败" + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (BusinessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> getVbdef6(String vsrcbidStr) throws BusinessException {
|
||||
IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class);
|
||||
String sql = " SELECT bt.pk_billtypecode,s.creationtime,b.vbdef12,d.nastnum FROM so_saleorder_b b\n"
|
||||
+ "INNER JOIN so_saleorder s ON s.csaleorderid = b.csaleorderid\n"
|
||||
+ "left join (select mm_mo.Vsrcbid,sum(nastnum) as nastnum \n" + "from mm_mo\n" + "where mm_mo.dr=0\n"
|
||||
+ "group by mm_mo.Vsrcbid) d on b.csaleorderbid=d.Vsrcbid\n"
|
||||
+ "INNER JOIN bd_billtype bt on bt.pk_billtypeid=s.ctrantypeid\n" + "where b.csaleorderbid='"
|
||||
+ vsrcbidStr + "' ";
|
||||
Map<String, Object> valList = (Map<String, Object>) queryBS.executeQuery(sql, new MapProcessor());
|
||||
return valList;
|
||||
}
|
||||
private Map<String, Object> getVbdef6(String vsrcbidStr) throws BusinessException {
|
||||
IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class);
|
||||
String sql = " SELECT bt.pk_billtypecode,s.creationtime,b.vbdef12,d.nastnum FROM so_saleorder_b b\n"
|
||||
+ "INNER JOIN so_saleorder s ON s.csaleorderid = b.csaleorderid\n"
|
||||
+ "left join (select mm_mo.Vsrcbid,sum(nastnum) as nastnum \n" + "from mm_mo\n" + "where mm_mo.dr=0\n"
|
||||
+ "group by mm_mo.Vsrcbid) d on b.csaleorderbid=d.Vsrcbid\n"
|
||||
+ "INNER JOIN bd_billtype bt on bt.pk_billtypeid=s.ctrantypeid\n" + "where b.csaleorderbid='"
|
||||
+ vsrcbidStr + "' ";
|
||||
Map<String, Object> valList = (Map<String, Object>) queryBS.executeQuery(sql, new MapProcessor());
|
||||
return valList;
|
||||
}
|
||||
|
||||
private String getPk_stockorg(String pk_stockorg) throws BusinessException {
|
||||
String sql = " select pk_stockorg from org_stockorg where code in ('C018','C029','C033','C039','C020','C019') and pk_stockorg='"
|
||||
+ pk_stockorg + "' ";
|
||||
String saleorderPK = (String) getQueryService().executeQuery(sql, new ColumnProcessor());
|
||||
return saleorderPK;
|
||||
}
|
||||
private String getPk_stockorg(String pk_stockorg) throws BusinessException {
|
||||
Map<String, String> defMap = checkOrgCtrl();
|
||||
if (defMap.isEmpty() || "".equals(defMap.getOrDefault("pmo", ""))) {
|
||||
return "";
|
||||
}
|
||||
String orgStr = defMap.getOrDefault("pmo", "");
|
||||
// 将数组转换为字符串,并添加单引号
|
||||
String newOrgStr = orgStr.replace(",", "','");
|
||||
String sql = " select pk_stockorg from org_stockorg where code in ('" + newOrgStr + "') and pk_stockorg='"
|
||||
+ pk_stockorg + "' ";
|
||||
// NCCForUAPLogger.debug("pmo-getPk_stockorg-sql:" + sql);
|
||||
String saleorderPK = (String) getQueryService().executeQuery(sql, new ColumnProcessor());
|
||||
return saleorderPK;
|
||||
}
|
||||
|
||||
public IUAPQueryBS getQueryService() {
|
||||
return NCLocator.getInstance().lookup(IUAPQueryBS.class);
|
||||
}
|
||||
private Map<String, String> checkOrgCtrl() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
String strWhere = " pk_defdoclist in (select pk_defdoclist from bd_defdoclist where code='org-ctrl' and dr=0 ) and dr=0";
|
||||
try {
|
||||
DefdocVO[] defdocVOs = (DefdocVO[]) new HYSuperDMO().queryByWhereClause(DefdocVO.class, strWhere);
|
||||
if (defdocVOs != null && defdocVOs.length > 0) {
|
||||
for (DefdocVO defdocVO : defdocVOs) {
|
||||
map.put(defdocVO.getCode().trim(), defdocVO.getMemo());
|
||||
}
|
||||
}
|
||||
} catch (DAOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public IUAPQueryBS getQueryService() {
|
||||
return NCLocator.getInstance().lookup(IUAPQueryBS.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue