备料计划优化

This commit is contained in:
lihao 2025-09-21 13:55:37 +08:00
parent 4296caf74f
commit d56a5e2ffb
7 changed files with 410 additions and 292 deletions

View File

@ -0,0 +1,195 @@
package nccloud.web.mmpac.pickm.action;
import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.itf.mmpac.pickm.IPickmQueryService;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.util.mmf.framework.base.MMValueCheck;
import nc.vo.mmpac.pickm.entity.AggPickmVO;
import nc.vo.mmpac.pickm.entity.PickmItemVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFDouble;
import nccloud.dto.mmpac.pickm.pub.entity.PickmQueryInfoDTO;
import nccloud.framework.core.json.IJson;
import nccloud.framework.service.ServiceLocator;
import nccloud.framework.web.action.itf.ICommonAction;
import nccloud.framework.web.container.IRequest;
import nccloud.framework.web.json.JsonFactory;
import java.util.ArrayList;
import java.util.List;
public class PickmCheckIsToAction implements ICommonAction {
@Override
public Object doAction(IRequest iRequest) {
String read = iRequest.read();
IJson json = JsonFactory.create();
try {
// 获取请求查询信息
PickmQueryInfoDTO paramDTO = json.fromJson(read, PickmQueryInfoDTO.class);
// 获取主键和类型
String[] cpickmbids = paramDTO.getCpickmbids();
String type = paramDTO.getType(); // 获取类型1是请购单2是生产订单
AggPickmVO[] aggVOs = null;
IPickmQueryService service = ServiceLocator.find(IPickmQueryService.class);
AggPickmVO[] vos = null;
if (MMValueCheck.isNotEmpty(cpickmbids)) {
aggVOs = service.queryAggPickmVObyBid(cpickmbids);
// 传递参数聚合VO是否来自cpickmbids订单类型
vos = processAggVOs(aggVOs, type);
}
// 返回不符合条件的数据
return vos;
} catch (BusinessException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
/**
* 处理聚合VO根据订单类型获取不符合条件的数据
* @param aggVOs 聚合VO数组
* @param type 订单类型1-请购单2-生产订单
* @return 不符合条件的聚合VO数组
*/
public AggPickmVO[] processAggVOs(AggPickmVO[] aggVOs, String type) throws DAOException {
List<AggPickmVO> invalidList = new ArrayList<>();
BaseDAO dao = new BaseDAO(); // 保持DAO实例优化
for (AggPickmVO vo : aggVOs) {
PickmItemVO[] items = (PickmItemVO[]) vo.getChildren(PickmItemVO.class);
if (items != null) {
for (PickmItemVO child : items) {
boolean isValid = true; // 标识是否符合条件符合则不收集
// 物料类型过滤逻辑仅当不是来自cpickmbids时才执行判断
String materalType = child.getVbdef14();
if (null == materalType) {
// 查询物料信息
String sql = "select cmaterialvid from mm_pickm where cpickmid = '" + child.getCpickmid() + "' and dr = 0";
String hmateral = (String) dao.executeQuery(sql, new ColumnProcessor());
// 根据订单类型执行不同的BOM查询逻辑
String bomcode = null;
if ("1".equals(type)) { // 请购单查询逻辑
sql="SELECT bd_defdoc.code FROM bd_bom_b " +
"LEFT JOIN bd_defdoc ON bd_bom_b.vdef1 = bd_defdoc.pk_defdoc " +
"WHERE bd_bom_b.cbomid in (select distinct bd_bom.cbomid from bd_bom bd_bom " +
"where ( bd_bom.pk_org = '"+child.getPk_org()+"' AND bd_bom.hcmaterialid = '"+hmateral+"' " +
"AND bd_bom.hfbomcategory = 1 AND bd_bom.hbcustomized = 'N' ) " +
"and bd_bom.dr = 0 and bd_bom.hbcustomized = 'N' and bd_bom.fbomtype != 3 ) " +
"AND bd_bom_b.dr = 0 and bd_bom_b.cmaterialvid='" + child.getCbmaterialvid() + "'";
bomcode = (String) dao.executeQuery(sql, new ColumnProcessor());
} else if ("2".equals(type)) { // 生产订单查询逻辑
sql="SELECT bd_defdoc.code FROM bd_bom_b " +
"LEFT JOIN bd_defdoc ON bd_bom_b.vdef1 = bd_defdoc.pk_defdoc " +
"WHERE bd_bom_b.cbomid in (select distinct bd_bom.cbomid from bd_bom bd_bom " +
"where ( bd_bom.pk_org = '"+child.getPk_org()+"' AND bd_bom.hcmaterialid = '"+hmateral+"' " +
"AND bd_bom.hfbomcategory = 1 AND bd_bom.hbcustomized = 'N' ) " +
"and bd_bom.dr = 0 and bd_bom.hbcustomized = 'N' and bd_bom.fbomtype != 3 ) " +
"AND bd_bom_b.dr = 0 and bd_bom_b.cmaterialvid='" + child.getCbmaterialvid() + "'";
bomcode = (String) dao.executeQuery(sql, new ColumnProcessor());
}
// 如果初始查询无结果执行二次查询根据类型区分
if (null == bomcode) {
if ("1".equals(type)) { // 请购单二次查询
String secondsql=" SELECT bd_defdoc.code FROM bd_bom_b " +
"LEFT JOIN bd_defdoc ON bd_bom_b.vdef1 = bd_defdoc.pk_defdoc " +
"WHERE bd_bom_b.cbomid in (select bd_bom.cbomid from bd_bom bd_bom " +
"WHERE bd_bom.pk_org = '"+child.getPk_org()+"' and bd_bom.hcmaterialid in " +
"(SELECT bd_bom_b.cmaterialvid FROM bd_bom_b " +
"LEFT JOIN bd_defdoc ON bd_bom_b.vdef1 = bd_defdoc.pk_defdoc " +
"WHERE bd_bom_b.cbomid in (select distinct bd_bom.cbomid from bd_bom bd_bom " +
"where ( bd_bom.pk_org = '"+child.getPk_org()+"' AND bd_bom.hcmaterialid = '"+hmateral+"' " +
"AND bd_bom.hfbomcategory = 1 AND bd_bom.hbcustomized = 'N' ) " +
"and bd_bom.dr = 0 and bd_bom.hbcustomized = 'N' and bd_bom.fbomtype != 3 ) " +
"AND bisvirtual='Y') AND bd_bom.hfbomcategory = 1 AND bd_bom.hbcustomized = 'N' " +
"and bd_bom.dr = 0 and bd_bom.hbcustomized = 'N' and bd_bom.fbomtype != 3 ) " +
"AND bd_bom_b.dr = 0 and bd_bom_b.cmaterialvid='"+child.getCbmaterialvid()+"'";
bomcode = (String) dao.executeQuery(secondsql, new ColumnProcessor());
} else if ("2".equals(type)) { // 生产订单二次查询
String secondsql=" SELECT bd_defdoc.code FROM bd_bom_b " +
"LEFT JOIN bd_defdoc ON bd_bom_b.vdef1 = bd_defdoc.pk_defdoc " +
"WHERE bd_bom_b.cbomid in (select bd_bom.cbomid from bd_bom bd_bom " +
"WHERE bd_bom.pk_org = '"+child.getPk_org()+"' and bd_bom.hcmaterialid in " +
"(SELECT bd_bom_b.cmaterialvid FROM bd_bom_b " +
"LEFT JOIN bd_defdoc ON bd_bom_b.vdef1 = bd_defdoc.pk_defdoc " +
"WHERE bd_bom_b.cbomid in (select distinct bd_bom.cbomid from bd_bom bd_bom " +
"where ( bd_bom.pk_org = '"+child.getPk_org()+"' AND bd_bom.hcmaterialid = '"+hmateral+"' " +
"AND bd_bom.hfbomcategory = 1 AND bd_bom.hbcustomized = 'N' ) " +
"and bd_bom.dr = 0 and bd_bom.hbcustomized = 'N' and bd_bom.fbomtype != 3 ) " +
"AND bisvirtual='Y') AND bd_bom.hfbomcategory = 1 AND bd_bom.hbcustomized = 'N' " +
"and bd_bom.dr = 0 and bd_bom.hbcustomized = 'N' and bd_bom.fbomtype != 3 ) " +
"AND bd_bom_b.dr = 0 and bd_bom_b.cmaterialvid='"+child.getCbmaterialvid()+"'";
bomcode = (String) dao.executeQuery(secondsql, new ColumnProcessor());
}
}
// 判断是否为不符合条件的数据根据类型可能有不同判断标准
if (null != bomcode && "2".equals(bomcode)) {
isValid = false; // 采购件不符合
} else if (!(null != bomcode && "1".equals(bomcode))) {
// 检查物料类型可根据订单类型添加不同判断
sql = "select martype from bd_materialstock where pk_material = '" + child.getCbmaterialvid() + "' and pk_org = '" + child.getPk_org() + "' and dr = 0";
String matType = (String) dao.executeQuery(sql, new ColumnProcessor());
// 请购单和生产订单可能有不同的物料类型过滤标准
if ("1".equals(type)) {
// 请购单非制造件或PR类型不符合
if (null == matType || "PR".equals(matType) || "".equals(matType)) {
isValid = false;
}
} else if ("2".equals(type)) {
// 生产订单可能有更严格的过滤条件
if (null == matType || "PR".equals(matType) || "".equals(matType) || "MO".equals(matType)) {
isValid = false;
}
}
}
} else {
// 有物料类型时的判断
String sql = "SELECT bd_defdoc.code FROM bd_defdoc where bd_defdoc.pk_defdoc = '" + materalType + "'";
String bomcode = (String) dao.executeQuery(sql, new ColumnProcessor());
// 根据订单类型判断不符合条件
if ("1".equals(type)) {
// 请购单采购件或未知类型不符合
if (null == bomcode || "2".equals(bomcode) || "".equals(bomcode)) {
isValid = false;
}
} else if ("2".equals(type)) {
// 生产订单可能有不同的判断标准
if (null == bomcode || "2".equals(bomcode) || "3".equals(bomcode) || "".equals(bomcode)) {
isValid = false;
}
}
}
// 检查是否为项目专用料可根据订单类型调整判断逻辑
if (!child.getBprojectmaterial().booleanValue()) {
// 生产订单可能对项目专用料有更严格要求
if ("2".equals(type) || "1".equals(type)) {
isValid = false;
}
}
// 收集不符合条件的数据
if (!isValid) {
List<PickmItemVO> pickmItemVOList = new ArrayList<>();
pickmItemVOList.add(child);
AggPickmVO newVO = new AggPickmVO();
newVO.setParent(vo.getParent());
newVO.setChildren(PickmItemVO.class, pickmItemVOList.toArray(new PickmItemVO[0]));
invalidList.add(newVO);
}
}
}
}
return invalidList.toArray(new AggPickmVO[0]);
}
}

View File

@ -54,23 +54,24 @@ public class PickmToBuyingreqAction implements ICommonAction {
// 获取主键
String[] cpickmids = paramDTO.getCpickmids();
String[] cpickmbids = paramDTO.getCpickmbids();
// if (MMValueCheck.isEmpty(cpickmids) && (null == cpickmbids || cpickmbids.length == 0)) {
// return null;
// }
AggPickmVO[] aggVOs = null;
IPickmQueryService service = ServiceLocator.find(IPickmQueryService.class);
AggPickmVO[] vos = null;
if (MMValueCheck.isNotEmpty(cpickmbids)) {
aggVOs = service.queryAggPickmVObyBid(cpickmbids);
// 传递true标识来自cpickmbids取消物料过滤
vos = processAggVOs(aggVOs, true);
} else if (MMValueCheck.isNotEmpty(cpickmids)) {
aggVOs = service.queryBillsByPks(cpickmids);
// 传递false标识来自cpickmids保留物料过滤
vos = processAggVOs(aggVOs, false);
}
if (MMValueCheck.isEmpty(aggVOs)) {
/*@res "单据已被修改或删除,请刷新界面重新操作!"*/
ExceptionUtils.wrapBusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("5008100_0", "05008100-0009"));
}
// AggPickmVO[] aggPickmVOS=processAggVOs(aggVOs);
// 转换数据
AggPickmVO[] vos = processAggVOs(aggVOs);
if(vos.length == 0){
throw new BusinessException("未检测到符合生成请购单数据,不能生成!");
}
@ -92,7 +93,6 @@ public class PickmToBuyingreqAction implements ICommonAction {
for (AggPickmVO prayVO : vos) {
PickmItemVO[] items = (PickmItemVO[]) prayVO.getChildren(PickmItemVO.class);
for (int j=0;j<items.length;j++) {
// items[j].getNnum();
pk.add(items[j].getCpickm_bid());
}
}
@ -101,8 +101,7 @@ public class PickmToBuyingreqAction implements ICommonAction {
PraybillVO[] insertVos = maintain.insert(prayVOs);
IPraybillApprove approve= ServiceLocator.find(IPraybillApprove.class);
Object res= PfServiceScmUtil.processBatch("APPROVE", "20", insertVos, null, null);
// approve.approve(insertVos,null,null);
// maintain.
Map<String, Object> returnMap = new HashMap<>();
returnMap.put("data", res);
returnMap.put("success", true);
@ -110,7 +109,6 @@ public class PickmToBuyingreqAction implements ICommonAction {
updetaPmo(pk);
}
if(!updateList.isEmpty()){
// 回写已经下达数量
updetaPmoNum(updateList);
}
return returnMap;
@ -127,34 +125,26 @@ public class PickmToBuyingreqAction implements ICommonAction {
BaseDAO dao = new BaseDAO();
for (Map<String, Object> updateMap : updateList) {
String sql = " update mm_pickm_b set vbdef16 = '"+((UFDouble)updateMap.get("num")).toString()+"' where mm_pickm_b.cpickm_bid ='" + updateMap.get("pk") + "'";
dao.executeUpdate(sql);
}
}
private PraybillVO[] convertToGeneralInVO(AggregatedValueObject[] sourceBillVOs, PfParameterVO srcParaVo)
throws BusinessException {
// 来源交易类型或单据类型需要在单据类型中注册
String srcBillOrTranstype = "55A3";
// 目标交易类型或单据类型需要在单据类型中注册
String destBillOrTranstype = "20";
// classifyMode int型参数调用模式参照PfButtonClickContext中定义代码中调用为接口方式 ClassifyByItfdef
int classifyMode = PfButtonClickContext.ClassifyByItfdef;
PraybillVO[] inVOS = (PraybillVO[]) PFPubService.runChangeData(srcBillOrTranstype, destBillOrTranstype, sourceBillVOs, srcParaVo, classifyMode);
if (MMValueCheck.isEmpty(inVOS)) {
ExceptionUtils.wrapBusinessException("备料计划转换请购单失败");
}
for (PraybillVO inVO : inVOS) {
// 其它入库单的仓库交易类型取自业务参数设置的默认值
PraybillHeaderVO head = inVO.getHVO();
String ctrantypeid = getValueByCondtion("bd_billtype", " pk_billtypeid ", " istransaction = 'Y' and nvl ( islock, 'N' ) = 'N' and parentbilltype = '20' and pk_group = '"
+ InvocationInfoProxy.getInstance().getGroupId() + "' and pk_billtypecode = '" + "20-01" + "' ");
head.setCtrantypeid(ctrantypeid);
// head.setCwarehouseid("");
}
List<PraybillVO> resultList = new ArrayList<>();
Map<Object, List<PraybillVO>> groupMap = new HashMap<>();
@ -165,7 +155,6 @@ public class PickmToBuyingreqAction implements ICommonAction {
for (Map.Entry<Object, List<PraybillVO>> entry : groupMap.entrySet()) {
List<PraybillVO> group = entry.getValue();
// 修改1使用ISuperVO列表收集子对象
List<PraybillItemVO> mergedChildren = new ArrayList<PraybillItemVO>();
for (PraybillVO vo : group) {
for (PraybillItemVO child : vo.getBVO()) {
@ -177,17 +166,15 @@ public class PickmToBuyingreqAction implements ICommonAction {
}
PraybillVO newVO = new PraybillVO();
newVO.setParent(group.get(0).getHVO());
// 修改2转换为ISuperVO数组
newVO.setChildren(PickmItemVO.class, mergedChildren.toArray(new PraybillItemVO[0]));
resultList.add(newVO);
}
return resultList.toArray(new PraybillVO[0]);
// return inVOS;
}
private String getValueByCondtion(String tablename, String fieldname, String contion) throws BusinessException {
BaseDAO dao = new BaseDAO();
String result = "";
StringBuffer sb = new StringBuffer();
sb.append(" SELECT " + fieldname + " FROM " + tablename + " ");
@ -202,159 +189,110 @@ public class PickmToBuyingreqAction implements ICommonAction {
StringBuilder sb = new StringBuilder();
if (arrayList.size() > 1) {
for (int i = 0; i < arrayList.size(); i++) {
sb.append("'").append(arrayList.get(i)).append("'");
if (i < arrayList.size() - 1) {
sb.append(",");
}
}
result = sb.toString();
} else {
result = "'" + (String) arrayList.get(0) + "'";
}
String sql = " update mm_pickm_b set vbdef30='Y' where mm_pickm_b.cpickm_bid in(" + result + ")";
BaseDAO dao = new BaseDAO();
dao.executeUpdate(sql);
}
public AggPickmVO[] processAggVOs(AggPickmVO[] aggVOs) throws DAOException {
// Map<Object, List<AggPickmVO>> groupMap = new HashMap<>();
//
// for (AggPickmVO vo : aggVOs) {
// Object pk_org = vo.getParentVO().getPk_org();
// groupMap.computeIfAbsent(pk_org, k -> new ArrayList<>()).add(vo);
// }
// 增加isFromBid参数标识是否来自cpickmbids查询
public AggPickmVO[] processAggVOs(AggPickmVO[] aggVOs, boolean isFromBid) throws DAOException {
List<AggPickmVO> resultList = new ArrayList<>();
// for (Map.Entry<Object, List<AggPickmVO>> entry : groupMap.entrySet()) {
// List<AggPickmVO> group = entry.getValue();
// 修改1使用ISuperVO列表收集子对象
List<PickmItemVO> mergedChildren = new ArrayList<PickmItemVO>();
for (AggPickmVO vo : aggVOs) {
PickmItemVO[] items = (PickmItemVO[]) vo.getChildren(PickmItemVO.class);
if (items != null) {
for (PickmItemVO child : items) {
// 未下达子表 若物料类型为采购件则备料计划中所有采购件生成一张请购单
// 已下达判断逻辑保持不变
if(null != child.getAttributeValue("vbdef30") && child.getAttributeValue("vbdef30").equals("Y") ){
// 如果已经下达数量 大于等于 需要下达数量 则不可继续下达
if(null==child.getVbdef16() || (new UFDouble(child.getVbdef16()).compareTo(child.getNplanoutnum().sub(null!=child.getNaccoutastnum() ?child.getNaccoutastnum():UFDouble.ZERO_DBL)) >=0)){
if(null==child.getVbdef16() || (new UFDouble(child.getVbdef16()).compareTo(
child.getNplanoutnum().sub(null!=child.getNaccoutastnum() ?
child.getNaccoutastnum():UFDouble.ZERO_DBL)) >=0)){
continue;
}else{
}
}
// 是否转为通用件若为Y不下达请购单
if(null != child.getAttributeValue("vbdef29") && child.getAttributeValue("vbdef29").equals("Y") ){
continue;
}
}
// if(new UFDouble(child.getVbdef16()).compareTo(child.getNplanoutnum().add(child.getNaccoutastnum())) >0){
//
// }else{
//
// }
}
// 物料类型过滤逻辑仅当不是来自cpickmbids时才执行过滤
String materalType = child.getVbdef14();
if(!isFromBid) { // 核心修改增加isFromBid判断
if(null == materalType){
// MR=制造件;
// PR=采购件;
// 1=制造件;
// 2=采购件;
String sql = " select cmaterialvid from mm_pickm where cpickmid='" + child.getCpickmid() + "' and dr=0";
BaseDAO dao = new BaseDAO();
String hmateral = (String) dao.executeQuery(sql, new ColumnProcessor());
sql="SELECT\n" +
"\n" +
" bd_defdoc.code \n" +
"FROM\n" +
" bd_bom_b \n" +
" LEFT JOIN bd_defdoc ON bd_bom_b.vdef1 = bd_defdoc.pk_defdoc\n" +
"WHERE\n" +
" bd_bom_b.cbomid in (select distinct bd_bom.cbomid from bd_bom bd_bom where ( bd_bom.pk_org = '"+child.getPk_org()+"' AND bd_bom.hcmaterialid = '"+hmateral+"' AND bd_bom.hfbomcategory = 1 AND bd_bom.hbcustomized = 'N' ) and bd_bom.dr = 0 and bd_bom.hbcustomized = 'N' and bd_bom.fbomtype != 3 ) \n" +
sql="SELECT bd_defdoc.code FROM bd_bom_b " +
"LEFT JOIN bd_defdoc ON bd_bom_b.vdef1 = bd_defdoc.pk_defdoc " +
"WHERE bd_bom_b.cbomid in (select distinct bd_bom.cbomid from bd_bom bd_bom " +
"where ( bd_bom.pk_org = '"+child.getPk_org()+"' AND bd_bom.hcmaterialid = '"+hmateral+"' " +
"AND bd_bom.hfbomcategory = 1 AND bd_bom.hbcustomized = 'N' ) " +
"and bd_bom.dr = 0 and bd_bom.hbcustomized = 'N' and bd_bom.fbomtype != 3 ) " +
"AND bd_bom_b.dr = 0 and bd_bom_b.cmaterialvid='" + child.getCbmaterialvid() + "'";
String bomcode = (String) dao.executeQuery(sql, new ColumnProcessor());
// MR=制造件;
// PR=采购件;
if(null==bomcode){
String secondsql=" SELECT\n" +
"\n" +
" bd_defdoc.code\n" +
"FROM\n" +
" bd_bom_b \n" +
" LEFT JOIN bd_defdoc ON bd_bom_b.vdef1 = bd_defdoc.pk_defdoc\n" +
"WHERE\n" +
" bd_bom_b.cbomid in (select bd_bom.cbomid from bd_bom bd_bom WHERE bd_bom.pk_org = '"+child.getPk_org()+"' and bd_bom.hcmaterialid in (SELECT\n" +
" bd_bom_b.cmaterialvid \n" +
"FROM\n" +
" bd_bom_b \n" +
" LEFT JOIN bd_defdoc ON bd_bom_b.vdef1 = bd_defdoc.pk_defdoc\n" +
"WHERE\n" +
" bd_bom_b.cbomid in (select distinct bd_bom.cbomid from bd_bom bd_bom where ( bd_bom.pk_org = '"+child.getPk_org()+"' AND bd_bom.hcmaterialid = '"+hmateral+"' AND bd_bom.hfbomcategory = 1 AND bd_bom.hbcustomized = 'N' ) and bd_bom.dr = 0 and bd_bom.hbcustomized = 'N' and bd_bom.fbomtype != 3 ) \n" +
"AND bisvirtual='Y') AND bd_bom.hfbomcategory = 1 AND bd_bom.hbcustomized = 'N' and bd_bom.dr = 0 and bd_bom.hbcustomized = 'N' and bd_bom.fbomtype != 3 ) \n" +
" AND \n" +
" bd_bom_b.dr = 0 and bd_bom_b.cmaterialvid='"+child.getCbmaterialvid()+"'";
String secondsql=" SELECT bd_defdoc.code FROM bd_bom_b " +
"LEFT JOIN bd_defdoc ON bd_bom_b.vdef1 = bd_defdoc.pk_defdoc " +
"WHERE bd_bom_b.cbomid in (select bd_bom.cbomid from bd_bom bd_bom " +
"WHERE bd_bom.pk_org = '"+child.getPk_org()+"' and bd_bom.hcmaterialid in " +
"(SELECT bd_bom_b.cmaterialvid FROM bd_bom_b " +
"LEFT JOIN bd_defdoc ON bd_bom_b.vdef1 = bd_defdoc.pk_defdoc " +
"WHERE bd_bom_b.cbomid in (select distinct bd_bom.cbomid from bd_bom bd_bom " +
"where ( bd_bom.pk_org = '"+child.getPk_org()+"' AND bd_bom.hcmaterialid = '"+hmateral+"' " +
"AND bd_bom.hfbomcategory = 1 AND bd_bom.hbcustomized = 'N' ) " +
"and bd_bom.dr = 0 and bd_bom.hbcustomized = 'N' and bd_bom.fbomtype != 3 ) " +
"AND bisvirtual='Y') AND bd_bom.hfbomcategory = 1 AND bd_bom.hbcustomized = 'N' " +
"and bd_bom.dr = 0 and bd_bom.hbcustomized = 'N' and bd_bom.fbomtype != 3 ) " +
"AND bd_bom_b.dr = 0 and bd_bom_b.cmaterialvid='"+child.getCbmaterialvid()+"'";
bomcode = (String) dao.executeQuery(secondsql, new ColumnProcessor());
}
if(null != bomcode && "2".equals(bomcode) ){
// sql = " select martype from bd_materialstock where pk_material='" + child.getCbmaterialvid() + "' and pk_org='"+child.getPk_org()+"' and dr=0";
// String matType = (String) dao.executeQuery(sql, new ColumnProcessor());
// if(null == matType || "MR".equals(matType) || "".equals(matType)){
// continue;
// }
// 采购件保留
}else if(null != bomcode && "1".equals(bomcode)){
continue;
continue; // 制造件过滤
}else{
sql = " select martype from bd_materialstock where pk_material='" + child.getCbmaterialvid() + "' and pk_org='"+child.getPk_org()+"' and dr=0";
String matType = (String) dao.executeQuery(sql, new ColumnProcessor());
if(null == matType || "MR".equals(matType) || "".equals(matType)){
continue;
continue; // 非采购件过滤
}
}
}else {
String sql="SELECT\n" +
"\n" +
" bd_defdoc.code \n" +
"FROM\n" +
" bd_defdoc where bd_defdoc.bd_defdoc.pk_defdoc='" + materalType + "'";
String sql="SELECT bd_defdoc.code FROM bd_defdoc where bd_defdoc.pk_defdoc='" + materalType + "'";
BaseDAO dao = new BaseDAO();
String bomcode = (String) dao.executeQuery(sql, new ColumnProcessor());
if(null == bomcode || "1".equals(bomcode) || "".equals(bomcode) ){
continue;
continue; // 制造件或未知类型过滤
}
}
} // 物料类型过滤逻辑结束
// 只合并项目专用料数据
if(child.getBprojectmaterial().booleanValue()){
// mergedChildren.add(child);
List<PickmItemVO> pickmItemVOList = new ArrayList<PickmItemVO>();
pickmItemVOList.add(child);
AggPickmVO newVO = new AggPickmVO();
newVO.setParent(vo.getParent());
// 修改2转换为ISuperVO数组
newVO.setChildren(PickmItemVO.class, pickmItemVOList.toArray(new PickmItemVO[0]));
resultList.add(newVO);
}
// CircularlyAccessibleValueObject 实现了 ISuperVO
}
}
}
// if(mergedChildren.size() == 0){
// continue;
// }
// AggPickmVO newVO = new AggPickmVO();
// newVO.setParent(group.get(0).getParentVO());
// // 修改2转换为ISuperVO数组
// newVO.setChildren(PickmItemVO.class, mergedChildren.toArray(new PickmItemVO[0]));
//
// resultList.add(newVO);
// }
return resultList.toArray(new AggPickmVO[0]);
}
}

View File

@ -48,22 +48,24 @@ public class PickmToPmo implements ICommonAction {
// 获取主键
String[] cpickmids = paramDTO.getCpickmids();
String[] cpickmbids = paramDTO.getCpickmbids();
// if (MMValueCheck.isEmpty(cpickmids) && (null == cpickmbids || cpickmbids.length == 0)) {
// return null;
// }
AggPickmVO[] aggVOs = null;
IPickmQueryService service = ServiceLocator.find(IPickmQueryService.class);
AggPickmVO[] vos = null;
if (MMValueCheck.isNotEmpty(cpickmbids)) {
aggVOs = service.queryAggPickmVObyBid(cpickmbids);
// 传递true标识来自cpickmbids取消物料过滤
vos = processAggVOs(aggVOs, true);
} else if (MMValueCheck.isNotEmpty(cpickmids)) {
aggVOs = service.queryBillsByPks(cpickmids);
// 传递false标识来自cpickmids保留物料过滤
vos = processAggVOs(aggVOs, false);
}
if (MMValueCheck.isEmpty(aggVOs)) {
/*@res "单据已被修改或删除,请刷新界面重新操作!"*/
ExceptionUtils.wrapBusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("5008100_0", "05008100-0009"));
}
AggPickmVO[] vos = processAggVOs(aggVOs);
if(vos.length == 0){
throw new BusinessException("未检测到符合生成生产单数据,不能生成!");
}
@ -108,18 +110,14 @@ public class PickmToPmo implements ICommonAction {
throw new RuntimeException(ex);
}
}
// return null;
}
private void updetaPmoNum(List<Map<String, Object>> updateList) throws DAOException {
BaseDAO dao = new BaseDAO();
for (Map<String, Object> updateMap : updateList) {
String sql = " update mm_pickm_b set vbdef16 = '"+((UFDouble)updateMap.get("num")).toString()+"' where mm_pickm_b.cpickm_bid ='" + updateMap.get("pk") + "'";
dao.executeUpdate(sql);
}
}
private void updetaPmo(List<String> arrayList) throws DAOException {
@ -127,20 +125,16 @@ public class PickmToPmo implements ICommonAction {
StringBuilder sb = new StringBuilder();
if (arrayList.size() > 1) {
for (int i = 0; i < arrayList.size(); i++) {
sb.append("'").append(arrayList.get(i)).append("'");
if (i < arrayList.size() - 1) {
sb.append(",");
}
}
result = sb.toString();
} else {
result = "'" + (String) arrayList.get(0) + "'";
}
String sql = " update mm_pickm_b set vbdef30='Y' where mm_pickm_b.cpickm_bid in(" + result + ")";
BaseDAO dao = new BaseDAO();
dao.executeUpdate(sql);
}
@ -164,15 +158,11 @@ public class PickmToPmo implements ICommonAction {
for (PMOAggVO inVO : inVOS) {
// 其它入库单的仓库交易类型取自业务参数设置的默认值
PMOHeadVO head = inVO.getParentVO();
// head.setCtrantypeid("0001A110000000001S1E");
String ctrantypeid = getValueByCondtion("bd_billtype", " pk_billtypeid ", " istransaction = 'Y' and nvl ( islock, 'N' ) = 'N' and parentbilltype = '55A2' and pk_group = '"
+ InvocationInfoProxy.getInstance().getGroupId() + "' and pk_billtypecode = '" + "55A2-Cxx-08" + "' ");
head.setCtrantypeid(ctrantypeid);
for (PMOItemVO itemVO: inVO.getChildrenVO()){
// itemVO.setTplanendtime();
for(AggPickmVO aggPickmVO:sourceBillVOs){
// if(itemVO.getVsrcid().equals(aggPickmVO.getParentVO().getCpickmid())){
if(null!=aggPickmVO.getParentVO().getVfirstbilltype() && aggPickmVO.getParentVO().getVfirstbilltype().equals("55A2") ){
String[] ids = new String[1];
ids[0] = aggPickmVO.getParentVO().getVfirstmoid();
@ -202,20 +192,13 @@ public class PickmToPmo implements ICommonAction {
}
}
}
// }
}
if(null !=itemVO.getCprojectid() && null!=itemVO.getCmaterialvid()){
// OrgVO orgvo = (OrgVO)hy.queryByPrimaryKey(OrgVO.class, );
String cbomid = (String) hy.findColValue("bd_bmrt", "cbomid",
"cprojectid = '"+itemVO.getCprojectid()+"' AND cmaterialid= '"+itemVO.getCmaterialvid()+"' AND dr = '0' AND pk_org= '"+head.getPk_org()+"'");
itemVO.setCbomversionid(cbomid);
}
}
// head.setCwarehouseid("");
}
List<PMOAggVO> resultList = new ArrayList<>();
Map<Object, List<PMOAggVO>> groupMap = new HashMap<>();
@ -227,7 +210,6 @@ public class PickmToPmo implements ICommonAction {
for (Map.Entry<Object, List<PMOAggVO>> entry : groupMap.entrySet()) {
List<PMOAggVO> group = entry.getValue();
// 修改1使用ISuperVO列表收集子对象
List<PMOItemVO> mergedChildren = new ArrayList<PMOItemVO>();
for (PMOAggVO vo : group) {
for (PMOItemVO child : vo.getChildrenVO()) {
@ -239,37 +221,29 @@ public class PickmToPmo implements ICommonAction {
}
PMOAggVO newVO = new PMOAggVO();
newVO.setParent(group.get(0).getParentVO());
// 修改2转换为ISuperVO数组
newVO.setChildren(PickmItemVO.class, mergedChildren.toArray(new PMOItemVO[0]));
resultList.add(newVO);
}
return resultList.toArray(new PMOAggVO[0]);
}
private UFDateTime getnextmonth(UFDateTime date) {
if (date == null) {
throw new IllegalArgumentException("输入的 UFDateTime 不能为 null");
}
// 1. 获取原始时间戳UTC 毫秒数
long originalTime = date.getMillis();
// 2. 使用 UFDateTime 默认时区与原类保持一致创建日历对象
// UFDateTime 内部使用 basezoneCalendar() 时依赖 Calendars.getGMTDefault()此处保持一致
TimeZone defaultTimeZone = Calendars.getGMTDefault(); // 需确保 Calendars 类可访问
TimeZone defaultTimeZone = Calendars.getGMTDefault();
GregorianCalendar calendar = new GregorianCalendar(defaultTimeZone);
calendar.setTimeInMillis(originalTime);
// 3. 将月份加 1日历自动处理 12月次年1月及月份天数不足的情况
calendar.add(java.util.Calendar.MONTH, 1);
// 4. 基于调整后的时间戳创建新的 UFDateTime 对象
long nextMonthTime = calendar.getTimeInMillis();
return new UFDateTime(nextMonthTime);
}
private String getValueByCondtion(String tablename, String fieldname, String contion) throws BusinessException {
BaseDAO dao = new BaseDAO();
String result = "";
StringBuffer sb = new StringBuffer();
sb.append(" SELECT " + fieldname + " FROM " + tablename + " ");
@ -278,129 +252,91 @@ public class PickmToPmo implements ICommonAction {
result = (String) dao.executeQuery(sb.toString(), new ColumnProcessor());
return result;
}
public AggPickmVO[] processAggVOs(AggPickmVO[] aggVOs) throws DAOException {
// Map<Object, List<AggPickmVO>> groupMap = new HashMap<>();
//
// for (AggPickmVO vo : aggVOs) {
// Object pk_org = vo.getParentVO().getPk_org();
// groupMap.computeIfAbsent(pk_org, k -> new ArrayList<>()).add(vo);
// }
// 增加isFromBid参数标识是否来自cpickmbids查询
public AggPickmVO[] processAggVOs(AggPickmVO[] aggVOs, boolean isFromBid) throws DAOException {
List<AggPickmVO> resultList = new ArrayList<>();
// for (Map.Entry<Object, List<AggPickmVO>> entry : groupMap.entrySet()) {
// List<AggPickmVO> group = entry.getValue();
// 修改1使用ISuperVO列表收集子对象
List<PickmItemVO> mergedChildren = new ArrayList<PickmItemVO>();
for (AggPickmVO vo : aggVOs) {
PickmItemVO[] items = (PickmItemVO[]) vo.getChildren(PickmItemVO.class);
if (items != null) {
for (PickmItemVO child : items) {
// 未下达子表 若物料类型为制造件则备料计划中所有制造件件生成一张开立状态的流程生产订单
// 已下达判断逻辑保持不变
if(null != child.getAttributeValue("vbdef30") && child.getAttributeValue("vbdef30").equals("Y") ){
// continue;
if(null==child.getVbdef16() || (new UFDouble(child.getVbdef16()).compareTo(child.getNplanoutnum().sub(null!=child.getNaccoutastnum() ?child.getNaccoutastnum():UFDouble.ZERO_DBL)) >=0)){
if(null==child.getVbdef16() || (new UFDouble(child.getVbdef16()).compareTo(
child.getNplanoutnum().sub(null!=child.getNaccoutastnum() ?
child.getNaccoutastnum():UFDouble.ZERO_DBL)) >=0)){
continue;
}else{
}
}
}
}
String rowno=child.getVrowno();
// 物料类型过滤逻辑仅当不是来自cpickmbids时才执行过滤
String materalType = child.getVbdef14();
if(!isFromBid) { // 核心修改增加isFromBid判断
if(null == materalType){
// 1=制造件;
// 2=采购件;
String sql = " select cmaterialvid from mm_pickm where cpickmid='" + child.getCpickmid() + "' and dr=0";
BaseDAO dao = new BaseDAO();
String hmateral = (String) dao.executeQuery(sql, new ColumnProcessor());
sql="SELECT\n" +
"\n" +
" bd_defdoc.code \n" +
"FROM\n" +
" bd_bom_b \n" +
" LEFT JOIN bd_defdoc ON bd_bom_b.vdef1 = bd_defdoc.pk_defdoc\n" +
"WHERE\n" +
" bd_bom_b.cbomid in (select distinct bd_bom.cbomid from bd_bom bd_bom where ( bd_bom.pk_org = '"+child.getPk_org()+"' AND bd_bom.hcmaterialid = '"+hmateral+"' AND bd_bom.hfbomcategory = 1 AND bd_bom.hbcustomized = 'N' ) and bd_bom.dr = 0 and bd_bom.hbcustomized = 'N' and bd_bom.fbomtype != 3 ) \n" +
sql="SELECT bd_defdoc.code FROM bd_bom_b " +
"LEFT JOIN bd_defdoc ON bd_bom_b.vdef1 = bd_defdoc.pk_defdoc " +
"WHERE bd_bom_b.cbomid in (select distinct bd_bom.cbomid from bd_bom bd_bom " +
"where ( bd_bom.pk_org = '"+child.getPk_org()+"' AND bd_bom.hcmaterialid = '"+hmateral+"' " +
"AND bd_bom.hfbomcategory = 1 AND bd_bom.hbcustomized = 'N' ) " +
"and bd_bom.dr = 0 and bd_bom.hbcustomized = 'N' and bd_bom.fbomtype != 3 ) " +
"AND bd_bom_b.dr = 0 and bd_bom_b.cmaterialvid='" + child.getCbmaterialvid() + "'";
String bomcode = (String) dao.executeQuery(sql, new ColumnProcessor());
// MR=制造件;
// PR=采购件;
if(null==bomcode){
String secondsql=" SELECT\n" +
"\n" +
" bd_defdoc.code\n" +
"FROM\n" +
" bd_bom_b \n" +
" LEFT JOIN bd_defdoc ON bd_bom_b.vdef1 = bd_defdoc.pk_defdoc\n" +
"WHERE\n" +
" bd_bom_b.cbomid in (select bd_bom.cbomid from bd_bom bd_bom WHERE bd_bom.pk_org = '"+child.getPk_org()+"' and bd_bom.hcmaterialid in (SELECT\n" +
" bd_bom_b.cmaterialvid \n" +
"FROM\n" +
" bd_bom_b \n" +
" LEFT JOIN bd_defdoc ON bd_bom_b.vdef1 = bd_defdoc.pk_defdoc\n" +
"WHERE\n" +
" bd_bom_b.cbomid in (select distinct bd_bom.cbomid from bd_bom bd_bom where ( bd_bom.pk_org = '"+child.getPk_org()+"' AND bd_bom.hcmaterialid = '"+hmateral+"' AND bd_bom.hfbomcategory = 1 AND bd_bom.hbcustomized = 'N' ) and bd_bom.dr = 0 and bd_bom.hbcustomized = 'N' and bd_bom.fbomtype != 3 ) \n" +
"AND bisvirtual='Y') AND bd_bom.hfbomcategory = 1 AND bd_bom.hbcustomized = 'N' and bd_bom.dr = 0 and bd_bom.hbcustomized = 'N' and bd_bom.fbomtype != 3 ) \n" +
" AND \n" +
" bd_bom_b.dr = 0 and bd_bom_b.cmaterialvid='"+child.getCbmaterialvid()+"'";
String secondsql=" SELECT bd_defdoc.code FROM bd_bom_b " +
"LEFT JOIN bd_defdoc ON bd_bom_b.vdef1 = bd_defdoc.pk_defdoc " +
"WHERE bd_bom_b.cbomid in (select bd_bom.cbomid from bd_bom bd_bom " +
"WHERE bd_bom.pk_org = '"+child.getPk_org()+"' and bd_bom.hcmaterialid in " +
"(SELECT bd_bom_b.cmaterialvid FROM bd_bom_b " +
"LEFT JOIN bd_defdoc ON bd_bom_b.vdef1 = bd_defdoc.pk_defdoc " +
"WHERE bd_bom_b.cbomid in (select distinct bd_bom.cbomid from bd_bom bd_bom " +
"where ( bd_bom.pk_org = '"+child.getPk_org()+"' AND bd_bom.hcmaterialid = '"+hmateral+"' " +
"AND bd_bom.hfbomcategory = 1 AND bd_bom.hbcustomized = 'N' ) " +
"and bd_bom.dr = 0 and bd_bom.hbcustomized = 'N' and bd_bom.fbomtype != 3 ) " +
"AND bisvirtual='Y') AND bd_bom.hfbomcategory = 1 AND bd_bom.hbcustomized = 'N' " +
"and bd_bom.dr = 0 and bd_bom.hbcustomized = 'N' and bd_bom.fbomtype != 3 ) " +
"AND bd_bom_b.dr = 0 and bd_bom_b.cmaterialvid='"+child.getCbmaterialvid()+"'";
bomcode = (String) dao.executeQuery(secondsql, new ColumnProcessor());
}
if(null != bomcode && "1".equals(bomcode) ){
if(null != bomcode && "1".equals(bomcode) ){
// 制造件保留
}else if(null != bomcode && "2".equals(bomcode)){
continue;
continue; // 采购件过滤
}else{
sql = " select martype from bd_materialstock where pk_material='" + child.getCbmaterialvid() + "' and pk_org='"+child.getPk_org()+"' and dr=0";
String matType = (String) dao.executeQuery(sql, new ColumnProcessor());
if(null == matType || "PR".equals(matType) || "".equals(matType)){
continue;
continue; // 非制造件过滤
}
}
}else {
String sql="SELECT\n" +
"\n" +
" bd_defdoc.code \n" +
"FROM\n" +
" bd_defdoc where bd_defdoc.bd_defdoc.pk_defdoc='" + materalType + "'";
String sql="SELECT bd_defdoc.code FROM bd_defdoc where bd_defdoc.pk_defdoc='" + materalType + "'";
BaseDAO dao = new BaseDAO();
String bomcode = (String) dao.executeQuery(sql, new ColumnProcessor());
if(null == bomcode || "2".equals(bomcode) || "".equals(bomcode) ){
continue;
continue; // 采购件或未知类型过滤
}
}
} // 物料类型过滤逻辑结束
// 只合并项目专用料数据
if(child.getBprojectmaterial().booleanValue()){
List<PickmItemVO> pickmItemVOList = new ArrayList<PickmItemVO>();
pickmItemVOList.add(child);
AggPickmVO newVO = new AggPickmVO();
newVO.setParent(vo.getParent());
// 修改2转换为ISuperVO数组
newVO.setChildren(PickmItemVO.class, pickmItemVOList.toArray(new PickmItemVO[0]));
resultList.add(newVO);
}
// CircularlyAccessibleValueObject 实现了 ISuperVO
}
}
}
// if(resultList.size() == 0){
// continue;
// }
// AggPickmVO newVO = new AggPickmVO();
// newVO.setParent(group.get(0).getParentVO());
// // 修改2转换为ISuperVO数组
// newVO.setChildren(PickmItemVO.class, mergedChildren.toArray(new PickmItemVO[0]));
//
// resultList.add(newVO);
// }
return resultList.toArray(new AggPickmVO[0]);
}
}

View File

@ -92,7 +92,7 @@ public class PickmDeliverAction implements ICommonAction {
}
List<String> pks = new ArrayList();
String errormessage="";
for(AggPickmVO agg : aggVOs) {
for(PickmItemVO item : (PickmItemVO[])agg.getChildrenVO()) {
// 流程生产订单明细表
@ -103,10 +103,11 @@ public class PickmDeliverAction implements ICommonAction {
"\tm.cmoid = '"+id+"' ";
BaseDAO dao = new BaseDAO();
String data =(String) dao.executeQuery(sql, new ColumnProcessor());
data=data.substring(0,10);
UFDate now=new UFDate();
// 领料校验 当前时间必须在计划结束时间前七天
if(null!=data && (now.compareTo(new UFDate(data)) >0 || now.getDateAfter(7).compareTo(new UFDate(data)) <0)){
errormessage=errormessage+"当前时间不在"+item.getVrowno()+"行数据计划结束时间"+data+"前七天 禁止领料\n";
continue;
};
@ -114,7 +115,9 @@ public class PickmDeliverAction implements ICommonAction {
pks.add(item.getCpickm_bid());
}
}
if(errormessage.length()>0){
throw new BusinessException(errormessage);
}
String deliverAppcode = "50080105";
String deliverPagecode = "5008010501";
if (MMValueCheck.isNotEmpty(paramDTO.getAppcode()) && paramDTO.getAppcode().startsWith("5009")) {

View File

@ -262,6 +262,7 @@
<action>mmpac.pickm.convertOtherIn</action>
<action>mmpac.pickm.buyingreq</action>
<action>mmpac.pickm.pom</action>
<action>mmpac.pickm.checkPickm</action>
<action>mmpac.pickm.pickmItemsQuery</action>
<action>mmpac.pickm.pickmByIdsQuery</action>
</actions>

View File

@ -173,6 +173,12 @@
<clazz>nccloud.web.mmpac.pickm.action.PickmToPmo
</clazz>
</action>
<action>
<name>mmpac.pickm.checkPickm</name>
<label>备料计划-流程生产订单</label>
<clazz>nccloud.web.mmpac.pickm.action.PickmCheckIsToAction
</clazz>
</action>
<action>
<name>mmpac.pickm.pushrzmes</name>

View File

@ -28,11 +28,13 @@ import nc.bs.mmpac.pmo.pac0002.rule.check.PMOCheckDeptNotNullRule;
import nc.bs.mmpac.pmo.pac0002.rule.check.PMOCheckItemNotNullRule;
import nc.bs.mmpac.pmo.pac0002.rule.check.PMOCheckItemParentProcedureRule;
import nc.bs.mmpac.pmo.pac0002.rule.check.PMOCheckParentProcedureNoRule;
import nc.bs.trade.business.HYPubBO;
import nc.impl.pubapp.bd.userdef.UserDefSaveRule;
import nc.impl.pubapp.pattern.rule.processer.AroundProcesser;
import nc.itf.mmpac.pmo.pac0002.IPMOMaintainService;
import nc.itf.uap.rbac.IUserManageQuery_C;
import nc.jdbc.framework.generator.SequenceGenerator;
import nc.pub.billcode.itf.IBillcodeManage;
import nc.util.mmf.busi.measure.MeasureHelper;
import nc.util.mmf.busi.service.OrgUnitPubService;
import nc.util.mmf.framework.base.MMArrayUtil;
@ -278,6 +280,43 @@ public class PMOMaintainServiceImpl implements IPMOMaintainService {
}
public PMOAggVO[] fillVOInfo4AID(PMOAggVO[] aggvos) throws BusinessException {
if (!MMArrayUtil.isEmpty(aggvos)){
List<PMOItemVO> xbitemList = new ArrayList();
HYPubBO hybo = new HYPubBO();
String org = hybo.findColValue("org_adminorg", "pk_adminorg", " code = 'C030' ") + "";
for (PMOAggVO vo : aggvos) {
for(PMOItemVO itemVO : vo.getChildrenVO()) {
if(itemVO.getPk_org().equals(org)) {
xbitemList.add(itemVO);
}
}
}
if(xbitemList.size() > 0) {
PMOItemVO[] vos = (PMOItemVO[])xbitemList.toArray(new PMOItemVO[xbitemList.size()]);
IBillcodeManage billcodeManage = (IBillcodeManage)NCLocator.getInstance().lookup(IBillcodeManage.class);
String[] billcodes = null;
try {
billcodes = billcodeManage.getBatchBillCodes_RequiresNew("55A2-2", vos[0].getPk_group(), vos[0].getPk_org(), vos[0],1);
} catch (BusinessException ex) {
ExceptionUtils.wrappException(ex);
}
for (PMOItemVO vo : vos) {
vo.setVbatchcode(billcodes[0]);
}
for (PMOAggVO vo : aggvos) {
for(PMOItemVO itemVO : vo.getChildrenVO()) {
for (PMOItemVO xb : vos) {
if(itemVO.getCmoid().equals(xb.getCmoid())) {
itemVO.setVbatchcode(billcodes[0]);
}
}
}
}
}
}
return MMArrayUtil.isEmpty(aggvos) ? null : (new PMOBPUtil()).fillVOInfo4AID(aggvos);
}