生产报告源码
This commit is contained in:
parent
3679368e1c
commit
fa093b84ad
|
@ -0,0 +1,569 @@
|
|||
package nccloud.openapi.mmpac.wr;
|
||||
|
||||
import nc.bs.dao.BaseDAO;
|
||||
import nc.bs.framework.common.NCLocator;
|
||||
import nc.bs.logging.Log;
|
||||
import nc.bs.uif2.validation.ValidationFailure;
|
||||
import nc.util.mmf.framework.base.MMArrayUtil;
|
||||
import nc.util.mmf.framework.base.MMCollectionUtil;
|
||||
import nc.util.mmf.framework.base.MMNumberUtil;
|
||||
import nc.util.mmf.framework.base.MMValueCheck;
|
||||
import nc.vo.mmpac.wr.entity.AggWrVO;
|
||||
import nc.vo.mmpac.wr.entity.WrItemVO;
|
||||
import nc.vo.mmpac.wr.entity.WrQualityVO;
|
||||
import nc.vo.mmpac.wr.entity.WrSerialNoVO;
|
||||
import nc.vo.mmpac.wr.entity.WrVO;
|
||||
import nc.vo.mmpac.wr.enumeration.WrBillStatusEnum;
|
||||
import nc.vo.pub.BusinessException;
|
||||
import nc.vo.pub.VOStatus;
|
||||
import nc.vo.pub.billtype.BilltypeVO;
|
||||
import nc.vo.pub.lang.UFDate;
|
||||
import nc.vo.pubapp.AppContext;
|
||||
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
|
||||
import nccloud.api.mmpac.wr.IAPIWrMaintain;
|
||||
import nccloud.api.rest.utils.NCCRestUtils;
|
||||
import nccloud.api.rest.utils.ResultMessageUtil;
|
||||
import nccloud.openapi.scmpub.pub.TransferCodeToPKTool;
|
||||
import nccloud.ws.rest.resource.AbstractNCCRestResource;
|
||||
import org.json.JSONString;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Path("mmpac/wr")
|
||||
public class WrResource extends AbstractNCCRestResource {
|
||||
|
||||
private static String HEADTABLE = "mm_wr";
|
||||
|
||||
private static String BODYTABLE = "mm_wr_product";
|
||||
|
||||
private static String QUALITYTABLE = "mm_wr_quality";
|
||||
|
||||
private static String SERIALNOTABLE = "mm_wr_serialno";
|
||||
|
||||
private static String PICKNOTABLE = "mm_wr_pick";
|
||||
|
||||
private static String GNUM_QUALITY = "ngqualitynum";
|
||||
private static String GNUM_REWORK = "ngreworknum";
|
||||
private static String GNUM_REJECT = "ngrejectnum";
|
||||
private static String GASTNUM_QUALITY = "ngqualityastnum";
|
||||
private static String GASTNUM_REWORK = "ngreworkastnum";
|
||||
private static String GASTNUM_REJECT = "ngrejectastnum";
|
||||
private static List<String> HeadUnUpdateFiled = Arrays.asList(WrVO.PK_WR, WrVO.PK_GROUP, WrVO.CWKID,
|
||||
WrVO.FBILLSTATUS, WrVO.VBILLCODE, WrVO.PK_ORG, WrVO.PK_ORG_V);
|
||||
private static List<String> BodyUnUpdateFiled = Arrays.asList(WrItemVO.PK_WR, "cbunitid", "pk_group", "pk_org",
|
||||
"pk_org_v", "pk_wr_product", "bbhasfbill", "bbhaspicked", "bbinstock", "bbisempass", "cbempass_bid",
|
||||
"cbempass_brow", "cbempasscode", "cbempassid", "cbfirstmobid", "cbfirstmoid", "cbsrctranstype", "cbsrcmoid",
|
||||
"cbsrcmobid", "cbfirstranstype", "cbmaterialid", "cbmainmaterialid", "fbsourcetype", "nbaldempinastnum",
|
||||
"nbaldempinnum", "nbcheckastnum", "nbchecknum", "nbempassastnum", "nbempassnum", "nbsldcheckastnum",
|
||||
"nbsldchecknum", "nbsldinastnum", "nbsldinnum", "vbbatchid", "vbfirstcode", "vbfirstid", "vbfirstmocode",
|
||||
"vbfirstmorowno", "vbfirstranstype", "vbfirstrowid", "vbfirstrowno", "vbfirsttype", "vbidentify",
|
||||
"vbinbatchid", "vbmainidentify", "vbmainmorowno", "vbmobillcode", "vbmoparentbillcode", "vbmorowno",
|
||||
"vbparentmorowno", "vbsalebillcode", "vbsalebillid", "vbsrccode", "vbsrcid", "vbsrcmocode", "vbsrcmorowno",
|
||||
"vbsrcrowid", "vbsrcrowno", "vbmainbomcode", "vbsrctranstype", "bbhasbckfled", "bbhaspicked", "bbsetmark");
|
||||
|
||||
@POST
|
||||
@Path("saveAndApprove")
|
||||
@Consumes({ "application/json" })
|
||||
@Produces({ "application/json" })
|
||||
public JSONString saveAndApprove(List<Map<String, Object>> paramList) {
|
||||
if (MMValueCheck.isEmpty(paramList)) {
|
||||
return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1");
|
||||
}
|
||||
List<AggWrVO> voList = new ArrayList<AggWrVO>();
|
||||
try {
|
||||
for (Map<String, Object> paramMap : paramList) {
|
||||
if (!paramMap.containsKey(HEADTABLE) || !paramMap.containsKey(BODYTABLE)) {
|
||||
return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1");
|
||||
}
|
||||
Map<String, Object> headInfo = (Map<String, Object>) paramMap.get(HEADTABLE);
|
||||
List<Map<String, Object>> itemInfos = new ArrayList<Map<String, Object>>();
|
||||
if (paramMap.get(BODYTABLE) instanceof List) {
|
||||
itemInfos = (List<Map<String, Object>>) paramMap.get(BODYTABLE);
|
||||
} else {
|
||||
Map<String, Object> bodyInfo = (Map<String, Object>) paramMap.get(BODYTABLE);
|
||||
itemInfos.add(bodyInfo);
|
||||
}
|
||||
AggWrVO vo = new AggWrVO();
|
||||
WrVO head = new WrVO();
|
||||
head.setPk_group(AppContext.getInstance().getPkGroup());
|
||||
head.setStatus(VOStatus.NEW);
|
||||
for (String key : headInfo.keySet()) {
|
||||
head.setAttributeValue(key, headInfo.get(key));
|
||||
}
|
||||
vo.setParentVO(head);
|
||||
List<WrItemVO> items = new ArrayList<WrItemVO>();
|
||||
String paramdata = NCCRestUtils.toJSONString(itemInfos).toJSONString();
|
||||
Log.getInstance("mm-mes").info("mes到生产报告参数:" + paramdata);
|
||||
for (Map<String, Object> itemMap : itemInfos) {
|
||||
WrItemVO item = new WrItemVO();
|
||||
item.setStatus(VOStatus.NEW);
|
||||
boolean hasGNumFlag = false;
|
||||
for (String key : itemMap.keySet()) {
|
||||
if (QUALITYTABLE.equals(key)) {
|
||||
List<Map<String, Object>> qualityInfos = (List<Map<String, Object>>) itemMap
|
||||
.get(QUALITYTABLE);
|
||||
List<WrQualityVO> qualitys = this.getWrQualitys(qualityInfos);
|
||||
item.setQualityvos(qualitys.toArray(new WrQualityVO[0]));
|
||||
} else if (SERIALNOTABLE.equals(key)) {
|
||||
List<Map<String, Object>> snInfos = (List<Map<String, Object>>) itemMap.get(SERIALNOTABLE);
|
||||
List<WrSerialNoVO> snVOs = this.getWrSerialNos(snInfos);
|
||||
item.setSerialnovos(snVOs.toArray(new WrSerialNoVO[0]));
|
||||
} else if (PICKNOTABLE.equals(key)) {
|
||||
continue;
|
||||
} else if (this.isGNumFilds(key)) {
|
||||
hasGNumFlag = true;
|
||||
} else {
|
||||
item.setAttributeValue(key, itemMap.get(key));
|
||||
}
|
||||
}
|
||||
if (hasGNumFlag) {
|
||||
List<WrQualityVO> qualitys = this.getWrQualitysByGnum(itemMap, item);
|
||||
item.setQualityvos(qualitys.toArray(new WrQualityVO[0]));
|
||||
}
|
||||
items.add(item);
|
||||
}
|
||||
vo.setChildren(WrItemVO.class, items.toArray(new WrItemVO[0]));
|
||||
voList.add(vo);
|
||||
IAPIWrMaintain server = NCLocator.getInstance().lookup(IAPIWrMaintain.class);
|
||||
AggWrVO[] aggvos = server.saveAndApprove(voList.toArray(new AggWrVO[0]));
|
||||
boolean successFlag = true;
|
||||
StringBuilder errMsg = new StringBuilder();
|
||||
if (MMArrayUtil.isNotEmpty(aggvos)) {
|
||||
for (AggWrVO aggvo : aggvos) {
|
||||
List<ValidationFailure> validateList = aggvo.getParentVO().getExcpMsgList();
|
||||
if (MMCollectionUtil.isNotEmpty(validateList)) {
|
||||
successFlag = false;
|
||||
errMsg.append(aggvo.getParentVO().getVbillcode());
|
||||
errMsg.append(":");
|
||||
for (ValidationFailure validate : validateList) {
|
||||
errMsg.append(validate.getMessage());
|
||||
errMsg.append(";");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (successFlag) {
|
||||
return ResultMessageUtil.toJSON(aggvos, "生产报告保存成功");
|
||||
} else {
|
||||
ExceptionUtils.wrappBusinessException(errMsg.toString());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return ResultMessageUtil.exceptionToJSON(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<WrQualityVO> getWrQualitysByGnum(Map<String, Object> itemMap, WrItemVO item) {
|
||||
List<WrQualityVO> qualityVOs = new ArrayList<WrQualityVO>();
|
||||
// 合格数量1
|
||||
if (itemMap.containsKey(WrResource.GNUM_QUALITY) || itemMap.containsKey(WrResource.GASTNUM_QUALITY)) {
|
||||
WrQualityVO qVO = new WrQualityVO();
|
||||
qVO.setFgprocessmethod(1);
|
||||
if (itemMap.containsKey(WrResource.GNUM_QUALITY)) {
|
||||
qVO.setAttributeValue(WrQualityVO.NGNUM, itemMap.get(WrResource.GNUM_QUALITY));
|
||||
}
|
||||
if (itemMap.containsKey(WrResource.GASTNUM_QUALITY)) {
|
||||
qVO.setAttributeValue(WrQualityVO.NGASTNUM, itemMap.get(WrResource.GASTNUM_QUALITY));
|
||||
}
|
||||
if (MMNumberUtil.isGtZero(qVO.getNgnum()) || MMNumberUtil.isGtZero(qVO.getNgastnum())) {
|
||||
qualityVOs.add(qVO);
|
||||
}
|
||||
}
|
||||
// 报废数量2
|
||||
if (itemMap.containsKey(WrResource.GNUM_REJECT) || itemMap.containsKey(WrResource.GASTNUM_REJECT)) {
|
||||
WrQualityVO qVO = new WrQualityVO();
|
||||
qVO.setFgprocessmethod(2);
|
||||
if (itemMap.containsKey(WrResource.GNUM_REJECT)) {
|
||||
qVO.setAttributeValue(WrQualityVO.NGNUM, itemMap.get(WrResource.GNUM_REJECT));
|
||||
}
|
||||
if (itemMap.containsKey(WrResource.GASTNUM_REJECT)) {
|
||||
qVO.setAttributeValue(WrQualityVO.NGASTNUM, itemMap.get(WrResource.GASTNUM_REJECT));
|
||||
}
|
||||
if (MMNumberUtil.isGtZero(qVO.getNgnum()) || MMNumberUtil.isGtZero(qVO.getNgastnum())) {
|
||||
qualityVOs.add(qVO);
|
||||
}
|
||||
}
|
||||
// 返工数量3
|
||||
if (itemMap.containsKey(WrResource.GNUM_REWORK) || itemMap.containsKey(WrResource.GASTNUM_REWORK)) {
|
||||
WrQualityVO qVO = new WrQualityVO();
|
||||
qVO.setFgprocessmethod(3);
|
||||
if (itemMap.containsKey(WrResource.GNUM_REWORK)) {
|
||||
qVO.setAttributeValue(WrQualityVO.NGNUM, itemMap.get(WrResource.GNUM_REWORK));
|
||||
}
|
||||
if (itemMap.containsKey(WrResource.GASTNUM_REWORK)) {
|
||||
qVO.setAttributeValue(WrQualityVO.NGASTNUM, itemMap.get(WrResource.GASTNUM_REWORK));
|
||||
}
|
||||
if (MMNumberUtil.isGtZero(qVO.getNgnum()) || MMNumberUtil.isGtZero(qVO.getNgastnum())) {
|
||||
qualityVOs.add(qVO);
|
||||
}
|
||||
}
|
||||
return qualityVOs;
|
||||
}
|
||||
|
||||
private boolean isGNumFilds(String key) {
|
||||
if (WrResource.GNUM_QUALITY.equals(key)) {
|
||||
return true;
|
||||
} else if (WrResource.GASTNUM_QUALITY.equals(key)) {
|
||||
return true;
|
||||
} else if (WrResource.GNUM_REJECT.equals(key)) {
|
||||
return true;
|
||||
} else if (WrResource.GASTNUM_REJECT.equals(key)) {
|
||||
return true;
|
||||
} else if (WrResource.GNUM_REWORK.equals(key)) {
|
||||
return true;
|
||||
} else if (WrResource.GASTNUM_REWORK.equals(key)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private List<WrSerialNoVO> getWrSerialNos(List<Map<String, Object>> snInfos) {
|
||||
List<WrSerialNoVO> snVOs = new ArrayList<WrSerialNoVO>();
|
||||
for (Map<String, Object> snInfo : snInfos) {
|
||||
WrSerialNoVO snVO = new WrSerialNoVO();
|
||||
for (String key : snInfo.keySet()) {
|
||||
snVO.setAttributeValue(key, snInfo.get(key));
|
||||
}
|
||||
snVOs.add(snVO);
|
||||
}
|
||||
return snVOs;
|
||||
}
|
||||
|
||||
private List<WrQualityVO> getWrQualitys(List<Map<String, Object>> qualityInfos) {
|
||||
List<WrQualityVO> qualityVOs = new ArrayList<WrQualityVO>();
|
||||
for (Map<String, Object> qualityInfo : qualityInfos) {
|
||||
WrQualityVO qualityVO = new WrQualityVO();
|
||||
for (String key : qualityInfo.keySet()) {
|
||||
qualityVO.setAttributeValue(key, qualityInfo.get(key));
|
||||
}
|
||||
qualityVOs.add(qualityVO);
|
||||
}
|
||||
return qualityVOs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModule() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("deleteByMesIDs")
|
||||
@Consumes({ "application/json" })
|
||||
@Produces({ "application/json" })
|
||||
public JSONString deleteByMesIDs(String[] mesIDs) {
|
||||
if (MMValueCheck.isEmpty(mesIDs)) {
|
||||
return ResultMessageUtil.exceptionToJSON("传入数据异常", "1");
|
||||
}
|
||||
try {
|
||||
IAPIWrMaintain server = NCLocator.getInstance().lookup(IAPIWrMaintain.class);
|
||||
server.deleteWrByMesID(mesIDs);
|
||||
return ResultMessageUtil.toJSON(null, "生产报告删除成功");
|
||||
|
||||
} catch (Exception e) {
|
||||
return ResultMessageUtil.exceptionToJSON(e);
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("newsave")
|
||||
@Consumes({ "application/json" })
|
||||
@Produces({ "application/json" })
|
||||
public JSONString newsave(Map<String, Object> paramsMap) {
|
||||
List<Map<String, Object>> paramList = (List<Map<String, Object>>) paramsMap.get("data");
|
||||
if (MMValueCheck.isEmpty(paramList)) {
|
||||
return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1");
|
||||
}
|
||||
List<AggWrVO> voList = new ArrayList<AggWrVO>();
|
||||
try {
|
||||
for (Map<String, Object> paramMap : paramList) {
|
||||
if (!paramMap.containsKey(HEADTABLE) || !paramMap.containsKey(BODYTABLE)) {
|
||||
return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1");
|
||||
}
|
||||
Map<String, Object> headInfo = (Map<String, Object>) paramMap.get(HEADTABLE);
|
||||
List<Map<String, Object>> itemInfos = new ArrayList<Map<String, Object>>();
|
||||
if (paramMap.get(BODYTABLE) instanceof List) {
|
||||
itemInfos = (List<Map<String, Object>>) paramMap.get(BODYTABLE);
|
||||
} else {
|
||||
Map<String, Object> bodyInfo = (Map<String, Object>) paramMap.get(BODYTABLE);
|
||||
itemInfos.add(bodyInfo);
|
||||
}
|
||||
AggWrVO vo = new AggWrVO();
|
||||
WrVO head = new WrVO();
|
||||
head.setPk_group(AppContext.getInstance().getPkGroup());
|
||||
for (String key : headInfo.keySet()) {
|
||||
if (MMValueCheck.isEmpty(headInfo.get(key))) {
|
||||
continue;
|
||||
}
|
||||
head.setAttributeValue(key, headInfo.get(key));
|
||||
}
|
||||
vo.setParentVO(head);
|
||||
List<WrItemVO> items = new ArrayList<WrItemVO>();
|
||||
String paramdata = NCCRestUtils.toJSONString(itemInfos).toJSONString();
|
||||
Log.getInstance("mm-mes").info("mes到生产报告参数:" + paramdata);
|
||||
for (Map<String, Object> itemMap : itemInfos) {
|
||||
WrItemVO item = new WrItemVO();
|
||||
boolean hasGNumFlag = false;
|
||||
for (String key : itemMap.keySet()) {
|
||||
|
||||
if (QUALITYTABLE.equals(key)) {
|
||||
List<Map<String, Object>> qualityInfos = (List<Map<String, Object>>) itemMap
|
||||
.get(QUALITYTABLE);
|
||||
List<WrQualityVO> qualitys = this.getWrQualitys(qualityInfos);
|
||||
item.setQualityvos(qualitys.toArray(new WrQualityVO[0]));
|
||||
} else if (SERIALNOTABLE.equals(key)) {
|
||||
List<Map<String, Object>> snInfos = (List<Map<String, Object>>) itemMap.get(SERIALNOTABLE);
|
||||
List<WrSerialNoVO> snVOs = this.getWrSerialNos(snInfos);
|
||||
item.setSerialnovos(snVOs.toArray(new WrSerialNoVO[0]));
|
||||
} else if (PICKNOTABLE.equals(key)) {
|
||||
continue;
|
||||
} else if (this.isGNumFilds(key)) {
|
||||
hasGNumFlag = true;
|
||||
} else {
|
||||
if (MMValueCheck.isEmpty(itemMap.get(key))) {
|
||||
continue;
|
||||
}
|
||||
item.setAttributeValue(key, itemMap.get(key));
|
||||
}
|
||||
}
|
||||
if (hasGNumFlag) {
|
||||
List<WrQualityVO> qualitys = this.getWrQualitysByGnum(itemMap, item);
|
||||
item.setQualityvos(qualitys.toArray(new WrQualityVO[0]));
|
||||
}
|
||||
items.add(item);
|
||||
}
|
||||
vo.setChildren(WrItemVO.class, items.toArray(new WrItemVO[0]));
|
||||
voList.add(vo);
|
||||
IAPIWrMaintain server = NCLocator.getInstance().lookup(IAPIWrMaintain.class);
|
||||
// List<AggWrVO> aggWrVOS = TransferCodeToPKTool.transferAggVO(voList);
|
||||
// //翻译报告类型
|
||||
// List<BilltypeVO> collection = (List<BilltypeVO>) new BaseDAO().retrieveByClause(BilltypeVO.class, " pk_billtypecode='" + aggWrVOS.get(0).getParentVO().getVtrantypecode()+"'");
|
||||
// aggWrVOS.get(0).getParentVO().setVtrantypeid(collection.get(0).getPk_billtypeid());
|
||||
// aggWrVOS.get(0).getParentVO().setDbilldate(new UFDate());
|
||||
// AggWrVO[] aggvos = server.newsave(aggWrVOS.toArray(new AggWrVO[0]));
|
||||
AggWrVO[] aggvos = server.newsave(voList.toArray(new AggWrVO[0]));
|
||||
boolean successFlag = true;
|
||||
StringBuilder errMsg = new StringBuilder();
|
||||
if (MMArrayUtil.isNotEmpty(aggvos)) {
|
||||
for (AggWrVO aggvo : aggvos) {
|
||||
List<ValidationFailure> validateList = aggvo.getParentVO().getExcpMsgList();
|
||||
if (MMCollectionUtil.isNotEmpty(validateList)) {
|
||||
successFlag = false;
|
||||
errMsg.append(aggvo.getParentVO().getVbillcode());
|
||||
errMsg.append(":");
|
||||
for (ValidationFailure validate : validateList) {
|
||||
errMsg.append(validate.getMessage());
|
||||
errMsg.append(";");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (successFlag) {
|
||||
return ResultMessageUtil.toJSON(aggvos, "生产报告保存成功");
|
||||
} else {
|
||||
ExceptionUtils.wrappBusinessException(errMsg.toString());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return ResultMessageUtil.exceptionToJSON(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("update")
|
||||
@Consumes({ "application/json" })
|
||||
@Produces({ "application/json" })
|
||||
public JSONString update(Map<String, Object> paramsMap) throws BusinessException {
|
||||
List<Map<String, Object>> paramList = (List<Map<String, Object>>) paramsMap.get("data");
|
||||
if (MMValueCheck.isEmpty(paramList)) {
|
||||
return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1");
|
||||
}
|
||||
List<AggWrVO> voList = new ArrayList<AggWrVO>();
|
||||
IAPIWrMaintain server = NCLocator.getInstance().lookup(IAPIWrMaintain.class);
|
||||
|
||||
List<String> aggIds = new ArrayList<>();
|
||||
for (Map<String, Object> paramMap : paramList) {
|
||||
if (!paramMap.containsKey(HEADTABLE) || !paramMap.containsKey(BODYTABLE)) {
|
||||
return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含表头信息和表体信息", "1");
|
||||
}
|
||||
Map<String, Object> headInfo = (Map<String, Object>) paramMap.get(HEADTABLE);
|
||||
if (MMValueCheck.isNotEmpty(headInfo.get("pk_wr"))) {
|
||||
aggIds.add(headInfo.get("pk_wr").toString());
|
||||
}
|
||||
}
|
||||
if (MMValueCheck.isEmpty(aggIds)) {
|
||||
return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含生产报告表头主键", "1");
|
||||
}
|
||||
AggWrVO[] aggWrVOSByIds = server.findAggWrVOSByIds(aggIds.toArray(new String[0]));
|
||||
Map<String, AggWrVO> voMap = new HashMap<>();
|
||||
for (AggWrVO aggWrVO : aggWrVOSByIds) {
|
||||
voMap.put(aggWrVO.getParentVO().getPk_wr(), aggWrVO);
|
||||
}
|
||||
|
||||
try {
|
||||
// 根据传递阐参数修改生产报告数据
|
||||
for (Map<String, Object> paramMap : paramList) {
|
||||
|
||||
Map<String, Object> headInfo = (Map<String, Object>) paramMap.get(HEADTABLE);
|
||||
List<Map<String, Object>> itemInfos = new ArrayList<Map<String, Object>>();
|
||||
if (paramMap.get(BODYTABLE) instanceof List) {
|
||||
itemInfos = (List<Map<String, Object>>) paramMap.get(BODYTABLE);
|
||||
} else {
|
||||
Map<String, Object> bodyInfo = (Map<String, Object>) paramMap.get(BODYTABLE);
|
||||
itemInfos.add(bodyInfo);
|
||||
}
|
||||
AggWrVO vo = voMap.get(headInfo.get("pk_wr").toString());
|
||||
if (MMValueCheck.isEmpty(vo)) {
|
||||
return ResultMessageUtil
|
||||
.exceptionToJSON("单据号:" + headInfo.get("vbillcode") + "生产报告在数据库中不存在或者已经被删除!", "1");
|
||||
}
|
||||
WrVO head = vo.getParentVO();
|
||||
if (!(WrBillStatusEnum.I_FREEDOM.intValue() == head.getFbillstatus())) {
|
||||
return ResultMessageUtil.exceptionToJSON("非自由态的生产报告不允许修改!", "1");
|
||||
}
|
||||
|
||||
// 处理表头数据
|
||||
head.setStatus(VOStatus.UPDATED);
|
||||
for (String key : headInfo.keySet()) {
|
||||
if (MMValueCheck.isEmpty(headInfo.get(key))) {
|
||||
continue;
|
||||
}
|
||||
if (HeadUnUpdateFiled.contains(key)
|
||||
&& !head.getAttributeValue(key).toString().equals(headInfo.get(key))) {
|
||||
return ResultMessageUtil.exceptionToJSON("表头属性:" + key + "不允许修改", "1");
|
||||
}
|
||||
head.setAttributeValue(key, headInfo.get(key));
|
||||
}
|
||||
vo.setParentVO(head);
|
||||
|
||||
// 处理表体数据和孙表数据
|
||||
Map<String, WrItemVO> wrItemVOMap = new HashMap<>();
|
||||
if (MMValueCheck.isNotEmpty(vo.getChildrenVO())) {
|
||||
for (WrItemVO wrItemVO : vo.getChildrenVO()) {
|
||||
wrItemVOMap.put(wrItemVO.getPk_wr_product(), wrItemVO);
|
||||
}
|
||||
}
|
||||
List<WrItemVO> items = new ArrayList<WrItemVO>();
|
||||
String paramdata = NCCRestUtils.toJSONString(itemInfos).toJSONString();
|
||||
Log.getInstance("mm-mes").info("mes到生产报告参数:" + paramdata);
|
||||
for (Map<String, Object> itemMap : itemInfos) {
|
||||
WrItemVO item = wrItemVOMap.get(itemMap.get("pk_wr_product"));
|
||||
if (MMValueCheck.isEmpty(item)) {
|
||||
continue;
|
||||
}
|
||||
item.setStatus(VOStatus.UPDATED);
|
||||
boolean hasGNumFlag = false;
|
||||
for (String key : itemMap.keySet()) {
|
||||
|
||||
if (QUALITYTABLE.equals(key)) {
|
||||
List<Map<String, Object>> qualityInfos = (List<Map<String, Object>>) itemMap
|
||||
.get(QUALITYTABLE);
|
||||
List<WrQualityVO> qualitys = this.getWrQualitys(qualityInfos);
|
||||
item.setQualityvos(qualitys.toArray(new WrQualityVO[0]));
|
||||
} else if (SERIALNOTABLE.equals(key)) {
|
||||
List<Map<String, Object>> snInfos = (List<Map<String, Object>>) itemMap.get(SERIALNOTABLE);
|
||||
List<WrSerialNoVO> snVOs = this.getWrSerialNos(snInfos);
|
||||
item.setSerialnovos(snVOs.toArray(new WrSerialNoVO[0]));
|
||||
} else if (PICKNOTABLE.equals(key)) {
|
||||
continue;
|
||||
} else if (this.isGNumFilds(key)) {
|
||||
hasGNumFlag = true;
|
||||
} else {
|
||||
if (MMValueCheck.isEmpty(itemMap.get(key))) {
|
||||
continue;
|
||||
}
|
||||
if (BodyUnUpdateFiled.contains(key) && MMValueCheck.isNotEmpty(item.getAttributeValue(key))
|
||||
&& !item.getAttributeValue(key).toString().equals(itemMap.get(key).toString())) {
|
||||
return ResultMessageUtil.exceptionToJSON("表体属性:" + key + "不允许修改", "1");
|
||||
}
|
||||
item.setAttributeValue(key, itemMap.get(key));
|
||||
}
|
||||
}
|
||||
if (hasGNumFlag) {
|
||||
List<WrQualityVO> qualitys = this.getWrQualitysByGnum(itemMap, item);
|
||||
item.setQualityvos(qualitys.toArray(new WrQualityVO[0]));
|
||||
}
|
||||
items.add(item);
|
||||
}
|
||||
vo.setChildren(WrItemVO.class, items.toArray(new WrItemVO[0]));
|
||||
voList.add(vo);
|
||||
}
|
||||
|
||||
AggWrVO[] aggvos = server.update(voList.toArray(new AggWrVO[0]));
|
||||
boolean successFlag = true;
|
||||
StringBuilder errMsg = new StringBuilder();
|
||||
if (MMArrayUtil.isNotEmpty(aggvos)) {
|
||||
for (AggWrVO aggvo : aggvos) {
|
||||
List<ValidationFailure> validateList = aggvo.getParentVO().getExcpMsgList();
|
||||
if (MMCollectionUtil.isNotEmpty(validateList)) {
|
||||
successFlag = false;
|
||||
errMsg.append(aggvo.getParentVO().getVbillcode());
|
||||
errMsg.append(":");
|
||||
for (ValidationFailure validate : validateList) {
|
||||
errMsg.append(validate.getMessage());
|
||||
errMsg.append(";");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (successFlag) {
|
||||
return ResultMessageUtil.toJSON(aggvos, "生产报告修改成功");
|
||||
} else {
|
||||
ExceptionUtils.wrappBusinessException(errMsg.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return ResultMessageUtil.exceptionToJSON(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("delete")
|
||||
@Consumes({ "application/json" })
|
||||
@Produces({ "application/json" })
|
||||
public JSONString delete(Map<String, Object> paramMap) throws BusinessException {
|
||||
if (MMValueCheck.isEmpty(paramMap)) {
|
||||
return ResultMessageUtil.exceptionToJSON("传入数据异常", "1");
|
||||
}
|
||||
Set<String> aggwrIds = new HashSet<>();
|
||||
Map<String, String> idTsMap = new HashMap<>();
|
||||
if (!paramMap.containsKey("aggWrPk")) {
|
||||
return ResultMessageUtil.exceptionToJSON("传入数据异常,参数要包含生产报告主键", "10000");
|
||||
}
|
||||
aggwrIds.addAll((Collection<? extends String>) paramMap.get("aggWrPk"));
|
||||
|
||||
try {
|
||||
IAPIWrMaintain server = NCLocator.getInstance().lookup(IAPIWrMaintain.class);
|
||||
AggWrVO[] aggWrVOSByIds = server.findAggWrVOSByIds(aggwrIds.toArray(new String[0]));
|
||||
|
||||
List<AggWrVO> deleteVos = new ArrayList<>();
|
||||
for (AggWrVO aggWrVOSById : aggWrVOSByIds) {
|
||||
if (!(WrBillStatusEnum.I_FREEDOM.intValue() == aggWrVOSById.getParentVO().getFbillstatus())) {
|
||||
continue;
|
||||
}
|
||||
deleteVos.add(aggWrVOSById);
|
||||
}
|
||||
if (MMValueCheck.isEmpty(deleteVos)) {
|
||||
return ResultMessageUtil.exceptionToJSON("生产报告状态为审批通过,不允许删除!", "1");
|
||||
}
|
||||
server.delete(deleteVos.toArray(new AggWrVO[0]));
|
||||
return ResultMessageUtil.toJSON(new String[0], "生产报告删除成功");
|
||||
} catch (Exception e) {
|
||||
return ResultMessageUtil.exceptionToJSON(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue