|
|
@@ -1762,62 +1762,56 @@ public class MESServiceImpl implements MESService {
|
|
|
@Override
|
|
|
public ApiResult<String> confirmSendNotify(HttpServletRequest request) {
|
|
|
String requestId = request.getHeader("RequestId");
|
|
|
- Map<String, JSONArray> data = getData(request);
|
|
|
- if (data!=null&&!data.isEmpty()){
|
|
|
- int snId=0;
|
|
|
- JSONArray main = data.get("main");
|
|
|
- if (main != null&&main.size()>0) {
|
|
|
- JSONObject object = JSON.parseObject(StringUtil.nvl(main.get(0), "{}"));
|
|
|
- snId = Integer.parseInt(StringUtil.nvl(object.get("snId"), "0"));
|
|
|
- if (!baseDao.checkIf("SendNotify", "sn_id=" + snId)) {
|
|
|
- return ApiResponse.failRsp("10071", requestId, "出货通知单不存在,无法确认!");
|
|
|
- }
|
|
|
- if (!baseDao.checkIf("SendNotify", "sn_statuscode='AUDITED' and sn_id=" + snId)) {
|
|
|
- return ApiResponse.failRsp("10072", requestId, "出货通知单不是已审核状态,无法确认!");
|
|
|
- }
|
|
|
- if (baseDao.checkIf("SendNotify", "sn_sendstatus='已出库' and sn_id=" + snId)) {
|
|
|
- return ApiResponse.failRsp("10073", requestId, "出货通知单已出货,无需重新确认生成!");
|
|
|
- }
|
|
|
- if (baseDao.checkIf("ProdIODetail", "pd_piclass='出货单' and pd_snid=" + snId)) {
|
|
|
- return ApiResponse.failRsp("10074", requestId, "出货通知单已转出货单,无需重新确认生成!");
|
|
|
- }
|
|
|
- // 存在未审批变更单
|
|
|
- String dets = baseDao.getJdbcTemplate().queryForObject("select wm_concat(snd_pdno) from sendnotifydetail where snd_snid=" + snId + " and exists (select 1 from SaleChangeDetail left join SaleChange on sc_id=scd_scid where scd_sacode=snd_ordercode and scd_sddetno=snd_orderdetno and sc_statuscode<>'AUDITED' )", String.class);
|
|
|
- if (dets != null) {
|
|
|
- return ApiResponse.failRsp("10075", requestId, "存在待审批的销售变更单,不能进行转出操作!行号:" + dets);
|
|
|
- }
|
|
|
- dets = baseDao.getJdbcTemplate().queryForObject("select wm_concat(snd_pdno) from sendnotifydetail where snd_snid=" + snId + " and exists (select 1 from SendNotifyChange left join SendNotifyChangeDetail on sc_id=scd_scid where sc_sncode=snd_code and scd_snddetno=snd_pdno and sc_statuscode<>'AUDITED')", String.class);
|
|
|
- if (dets != null) {
|
|
|
- return ApiResponse.failRsp("10076", requestId, "存在待审批的通知变更单,不能进行转出操作!行号:" + dets);
|
|
|
- }
|
|
|
- if (baseDao.isDBSetting("Sale", "zeroOutWhenHung")) {
|
|
|
- dets = baseDao.getJdbcTemplate().queryForObject("select distinct wm_concat('通知单号:'||sn_code||'客户:'||sn_custcode) from sendnotify left join SendNotifyDetail on snd_snid=sn_id where nvl(sn_custcode, ' ')<>' ' and snd_snid=" + snId + " and sn_custcode in (select cu_code from customer where cu_status='挂起') and not exists (select 1 from saledetail where sd_code=snd_ordercode and sd_detno=snd_orderdetno and nvl(sd_price,0)=0)", String.class);
|
|
|
+ List<Map<Object, Object>> maps = getJsonsData(request);
|
|
|
+ if (maps!=null&&!maps.isEmpty()){
|
|
|
+ List<Map<String, Object>> hashMaps = new ArrayList<>();
|
|
|
+ List<Key> keys = new ArrayList<>();
|
|
|
+ for (Map<Object, Object> map:maps) {
|
|
|
+ int sndId = Integer.parseInt(StringUtil.nvl(map.get("sndId"), "0"));
|
|
|
+ if (sndId>0){
|
|
|
+ int snId = Integer.parseInt(StringUtil.nvl(baseDao.getFieldDataByCondition("SendNotifyDetail", "snd_snid", "snd_id=" + sndId), "0"));
|
|
|
+ if (!baseDao.checkIf("SendNotifyDetail","snd_id="+sndId)){
|
|
|
+ return ApiResponse.failRsp("10079", requestId, "明细行不存在,请核对!");
|
|
|
+ }
|
|
|
+ if (!baseDao.checkIf("SendNotify", "sn_id=" + snId)) {
|
|
|
+ return ApiResponse.failRsp("10071", requestId, "出货通知单不存在,无法确认!");
|
|
|
+ }
|
|
|
+ if (!baseDao.checkIf("SendNotify", "sn_statuscode='AUDITED' and sn_id=" + snId)) {
|
|
|
+ return ApiResponse.failRsp("10072", requestId, "出货通知单不是已审核状态,无法确认!");
|
|
|
+ }
|
|
|
+ if (baseDao.checkIf("SendNotify", "sn_sendstatus='已出库' and sn_id=" + snId)) {
|
|
|
+ return ApiResponse.failRsp("10073", requestId, "出货通知单已出货,无需重新确认生成!");
|
|
|
+ }
|
|
|
+ if (baseDao.checkIf("ProdIODetail", "pd_piclass='出货单' and pd_orderid=" + sndId)) {
|
|
|
+ return ApiResponse.failRsp("10074", requestId, "出货通知单已转出货单,无需重新确认生成!");
|
|
|
+ }
|
|
|
+ // 存在未审批变更单
|
|
|
+ String dets = baseDao.getJdbcTemplate().queryForObject("select wm_concat(snd_pdno) from sendnotifydetail where snd_id=" + sndId + " and exists (select 1 from SaleChangeDetail left join SaleChange on sc_id=scd_scid where scd_sacode=snd_ordercode and scd_sddetno=snd_orderdetno and sc_statuscode<>'AUDITED' )", String.class);
|
|
|
if (dets != null) {
|
|
|
- return ApiResponse.failRsp("10077", requestId, "通知单客户已挂起,不能进行转出操作!" + dets);
|
|
|
+ return ApiResponse.failRsp("10075", requestId, "存在待审批的销售变更单,不能进行转出操作!行号:" + dets);
|
|
|
}
|
|
|
- } else {
|
|
|
- dets = baseDao.getJdbcTemplate().queryForObject("select distinct wm_concat('通知单号:'||sn_code||'客户:'||sn_custcode) from sendnotify left join SendNotifyDetail on snd_snid=sn_id where nvl(sn_custcode, ' ')<>' ' and snd_snid=" + snId + " and sn_custcode in (select cu_code from customer where cu_status='挂起')", String.class);
|
|
|
+ dets = baseDao.getJdbcTemplate().queryForObject("select wm_concat(snd_pdno) from sendnotifydetail where snd_id=" + sndId + " and exists (select 1 from SendNotifyChange left join SendNotifyChangeDetail on sc_id=scd_scid where sc_sncode=snd_code and scd_snddetno=snd_pdno and sc_statuscode<>'AUDITED')", String.class);
|
|
|
if (dets != null) {
|
|
|
- return ApiResponse.failRsp("10078", requestId, "通知单客户已挂起,不能进行转出操作!" + dets);
|
|
|
+ return ApiResponse.failRsp("10076", requestId, "存在待审批的通知变更单,不能进行转出操作!行号:" + dets);
|
|
|
}
|
|
|
- }
|
|
|
- dets = baseDao.getJdbcTemplate().queryForObject("select wm_concat(snd_pdno) from SendNotifyDetail where nvl(snd_statuscode, ' ')<>'AUDITED' and snd_snid=" + snId, String.class);
|
|
|
- if (dets != null) {
|
|
|
- return ApiResponse.failRsp("10079", requestId, "明细行状态不等于已审核,不能进行转出操作!" + dets);
|
|
|
- }
|
|
|
- }
|
|
|
- JSONArray detail = data.get("detail");
|
|
|
- if (detail != null&&detail.size()>0&&snId>0) {
|
|
|
- List<Map<Object, Object>> maps = new ArrayList<>();
|
|
|
- for (int i = 0; i <detail.size(); i++) {
|
|
|
- JSONObject parseObject = JSON.parseObject(StringUtil.nvl(detail.get(i), "{}"));
|
|
|
- int sndId = Integer.parseInt(StringUtil.nvl(parseObject.get("sndId"), "0"));
|
|
|
- double tqty = Double.parseDouble(StringUtil.nvl(parseObject.get("tqty"), "0"));
|
|
|
- String prodCode = StringUtil.nvl(parseObject.get("prodCode"), "");
|
|
|
- String whCode = StringUtil.nvl(parseObject.get("whCode"), "");
|
|
|
- if (!baseDao.checkIf("SendNotifyDetail","snd_id="+sndId)){
|
|
|
- return ApiResponse.failRsp("10079", requestId, "明细行不存在,请核对!");
|
|
|
+ if (baseDao.isDBSetting("Sale", "zeroOutWhenHung")) {
|
|
|
+ dets = baseDao.getJdbcTemplate().queryForObject("select distinct wm_concat('通知单号:'||sn_code||'客户:'||sn_custcode) from sendnotify left join SendNotifyDetail on snd_snid=sn_id where nvl(sn_custcode, ' ')<>' ' and snd_id=" + sndId + " and sn_custcode in (select cu_code from customer where cu_status='挂起') and not exists (select 1 from saledetail where sd_code=snd_ordercode and sd_detno=snd_orderdetno and nvl(sd_price,0)=0)", String.class);
|
|
|
+ if (dets != null) {
|
|
|
+ return ApiResponse.failRsp("10077", requestId, "通知单客户已挂起,不能进行转出操作!" + dets);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ dets = baseDao.getJdbcTemplate().queryForObject("select distinct wm_concat('通知单号:'||sn_code||'客户:'||sn_custcode) from sendnotify left join SendNotifyDetail on snd_snid=sn_id where nvl(sn_custcode, ' ')<>' ' and snd_id=" + sndId + " and sn_custcode in (select cu_code from customer where cu_status='挂起')", String.class);
|
|
|
+ if (dets != null) {
|
|
|
+ return ApiResponse.failRsp("10078", requestId, "通知单客户已挂起,不能进行转出操作!" + dets);
|
|
|
+ }
|
|
|
}
|
|
|
+ dets = baseDao.getJdbcTemplate().queryForObject("select wm_concat(snd_pdno) from SendNotifyDetail where nvl(snd_statuscode, ' ')<>'AUDITED' and snd_id=" + sndId, String.class);
|
|
|
+ if (dets != null) {
|
|
|
+ return ApiResponse.failRsp("10079", requestId, "明细行状态不等于已审核,不能进行转出操作!" + dets);
|
|
|
+ }
|
|
|
+ double tqty = Double.parseDouble(StringUtil.nvl(map.get("tqty"), "0"));
|
|
|
+ String prodCode = StringUtil.nvl(map.get("prodCode"), "");
|
|
|
+ String whCode = StringUtil.nvl(map.get("whCode"), "");
|
|
|
if ("".equals(prodCode)){
|
|
|
return ApiResponse.failRsp("10063",requestId,"物料不能为空!");
|
|
|
}
|
|
|
@@ -1838,75 +1832,84 @@ public class MESServiceImpl implements MESService {
|
|
|
if (baseDao.checkIf("SendNotifyDetail","nvl(snd_yqty,0)+"+tqty+">nvl(snd_outqty,0) and snd_id="+sndId)){
|
|
|
return ApiResponse.failRsp("10063",requestId,"数量+已转出货数不能大于通知单数量!");
|
|
|
}
|
|
|
- Map<Object, Object> map = new HashMap<>();
|
|
|
- map.put("snd_id",sndId);
|
|
|
- map.put("snd_tqty",tqty);
|
|
|
- map.put("snd_warehousecode",wh[0]);
|
|
|
- map.put("snd_warehouse",wh[1]);
|
|
|
- maps.add(map);
|
|
|
+ List<Map<String, Object>> mapList = baseDao.queryForList("select "+tqty+" snd_tqty,'"+wh[0]+"' snd_warehousecode,'"+wh[1]+"' snd_warehouse,sn_code,sn_custcode,snd_prodcode,sn_currency,sn_rate,sn_paymentscode,sn_shcustcode,sn_arcustcode,snd_id,sn_id from SendNotify left join SendNotifyDetail on sn_id=snd_snid left join Product on snd_prodcode=pr_code where snd_id=" + sndId);
|
|
|
+ hashMaps.addAll(mapList);
|
|
|
}
|
|
|
- Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?", new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
|
|
|
- //生成出货单
|
|
|
- Key key = transferRepository.transfer("ProdInOut!Sale", snId, employee);
|
|
|
+ }
|
|
|
+ List<Map<Object, Object>> mapList = BaseUtil.parseGridStoreToMaps(StringUtil.nvl(baseDao.changeKeyToLowerCase(hashMaps), "[{}]"));
|
|
|
+ Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?", new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
|
|
|
+ Map<Object, List<Map<Object, Object>>> groups = BaseUtil.groupsMap(mapList, new Object[] {"sn_custcode","sn_shcustcode","sn_currency","sn_arcustcode","sn_paymentscode"});
|
|
|
+ // 按客户分组的转入操作
|
|
|
+ Set<Object> mapSet = groups.keySet();
|
|
|
+ List<Map<Object, Object>> items;
|
|
|
+ for (Object s : mapSet) {
|
|
|
+ items = groups.get(s);
|
|
|
+ // 转入通知单主记录
|
|
|
+ Integer sn_id = baseDao.getFieldValue("SendNotifyDetail", "snd_snid", "snd_id=" + items.get(0).get("snd_id"),
|
|
|
+ Integer.class);
|
|
|
+ Key key = transferRepository.transfer("ProdInOut!Sale", sn_id, employee);
|
|
|
if (key != null) {
|
|
|
+ keys.add(key);
|
|
|
int pi_id = key.getId();
|
|
|
- // 转入出货单明细
|
|
|
- transferRepository.transfer("ProdInOut!Sale", maps, key, employee);
|
|
|
+ // 转入明细
|
|
|
+ transferRepository.transfer("ProdInOut!Sale", items, key, employee);
|
|
|
// 地址
|
|
|
baseDao.execute(
|
|
|
"update ProdInOut set pi_address=(select cu_add1 from customer where pi_cardcode=cu_code) where pi_id=? and nvl(pi_address,' ')=' '",
|
|
|
pi_id);
|
|
|
- baseDao.execute(
|
|
|
- "update ProdIODetail set (pd_whcode,pd_whname)=(select pr_whcode,wh_description from product left join warehouse on pr_whcode=wh_code where pd_prodcode=pr_code) where pd_piid=? and nvl(pd_whcode,' ')=' '",
|
|
|
- pi_id);
|
|
|
- baseDao.execute(
|
|
|
- "update prodinout set (pi_whcode,pi_whname)=(select pd_whcode,pd_whname from prodiodetail where pd_piid=pi_id and nvl(pd_whcode,' ')<>' ' and rownum<2) where nvl(pi_whcode,' ')=' ' and pi_id=?",
|
|
|
- pi_id);
|
|
|
baseDao.execute("update prodinout set (pi_purposename,pi_expresscode,pi_fax)=(select max(ca_person),max(ca_phone),max(ca_fax) from CustomerAddress left join customer on ca_cuid=cu_id where cu_code=pi_cardcode and ca_address=pi_address) where pi_id="
|
|
|
+ pi_id);
|
|
|
baseDao.execute(
|
|
|
- "update ProdInOut set pi_rate=nvl((select cm_crrate from currencysmonth where cm_yearmonth=to_char(pi_date,'yyyymm') and cm_crname=pi_currency),1) where pi_id=? and nvl(pi_currency,' ')<>' '",
|
|
|
+ "update prodinout set (pi_whcode,pi_whname)=(select pd_whcode,pd_whname from prodiodetail where pd_piid=pi_id and nvl(pd_whcode,' ')<>' ' and rownum<2) where nvl(pi_whcode,' ')=' ' and pi_id=?",
|
|
|
pi_id);
|
|
|
baseDao.execute(
|
|
|
- "update ProdInOut set pi_total=(SELECT round(sum(nvl(pd_sendprice,0)*(nvl(pd_inqty,0)+nvl(pd_outqty,0))),2) FROM ProdIODetail WHERE pd_piid=pi_id) where pi_id=?",
|
|
|
+ "update ProdIODetail set pd_taxtotal=round(pd_sendprice*(nvl(pd_inqty,0)+nvl(pd_outqty,0)),2), pd_nettotal=round(pd_netprice*(nvl(pd_inqty,0)+nvl(pd_outqty,0)),2) WHERE pd_piid=?",
|
|
|
pi_id);
|
|
|
+ baseDao.execute("update ProdIODetail set pd_ordertotal=round(pd_outqty*pd_sendprice,2) where pd_piid=?", pi_id);
|
|
|
baseDao.updateByCondition(
|
|
|
"ProdIODetail",
|
|
|
"pd_netprice=round(pd_sendprice/(1+pd_taxrate/100),8),pd_nettotal=round(pd_sendprice*pd_outqty/(1+nvl(pd_taxrate,0)/100),2)",
|
|
|
"pd_piid=" + pi_id);
|
|
|
baseDao.execute(
|
|
|
- "update ProdIODetail set pd_taxtotal=round(pd_sendprice*(nvl(pd_inqty,0)+nvl(pd_outqty,0)),2), pd_nettotal=round(pd_netprice*(nvl(pd_inqty,0)+nvl(pd_outqty,0)),2) WHERE pd_piid=?",
|
|
|
+ "update ProdInOut set pi_total=(SELECT round(sum(nvl(pd_sendprice,0)*(nvl(pd_inqty,0)+nvl(pd_outqty,0))),2) FROM ProdIODetail WHERE pd_piid=pi_id) where pi_id=?",
|
|
|
pi_id);
|
|
|
baseDao.updateByCondition("ProdInOut", "pi_totalupper=L2U(nvl(pi_total,0))", "pi_id=" + pi_id);
|
|
|
- // 修改出货通知单状态
|
|
|
- String statuscode = null, status = null;
|
|
|
- int count = baseDao.getCountByCondition("SendNotifyDetail", "snd_snid=" + snId);
|
|
|
- int yCount = baseDao.getCountByCondition("SendNotifyDetail", "snd_snid=" + snId + " and nvl(snd_yqty,0)=nvl(snd_outqty,0) and nvl(snd_yqty,0)>=0");
|
|
|
- int xCount = baseDao.getCountByCondition("SendNotifyDetail", "snd_snid=" + snId + " and nvl(snd_yqty,0)=0");
|
|
|
- statuscode = "PARTOUT";
|
|
|
- status = "部分出库";
|
|
|
- if (xCount == count) {
|
|
|
- statuscode = "";
|
|
|
- status = "";
|
|
|
- }
|
|
|
- if (yCount == count) {
|
|
|
- statuscode = "TURNOUT";
|
|
|
- status = "已出库";
|
|
|
- }
|
|
|
- baseDao.updateByCondition("SendNotify", "SN_SENDSTATUSCODE='" + statuscode + "',SN_SENDSTATUS='" + status + "'", "sn_id=" + snId);
|
|
|
- //过账出货单
|
|
|
- String s = postProdInOut(pi_id, "ProdInOut!Sale", employee);
|
|
|
- if (s!=null&&!"".equals(s)){
|
|
|
- return ApiResponse.successRsp("0", requestId, "出货单:" + key.getCode() + ",过账失败,请在ERP重新过账!");
|
|
|
- }
|
|
|
- // 记录操作
|
|
|
- baseDao.execute("INSERT INTO MessageLog(ml_id,ml_date,ml_man,ml_content,ml_result,ml_search) VALUES (MessageLog_seq.nextval,sysdate,'mes','确认操作','确认成功','SendNotify|sn_id=" + snId + "')");
|
|
|
return ApiResponse.successRsp("0", requestId, "出货单:" + key.getCode() + ",请在ERP查看!");
|
|
|
} else
|
|
|
return ApiResponse.failRsp("10080", requestId, "生成失败!");
|
|
|
+ }
|
|
|
+ // 修改出货通知单状态
|
|
|
+ Map<Object, List<Map<Object, Object>>> listMap = BaseUtil.groupsMap(mapList, new Object[]{"sn_id"});
|
|
|
+ // 按客户分组的转入操作
|
|
|
+ Set<Object> mSet = listMap.keySet();
|
|
|
+ for (Object obj : mSet) {
|
|
|
+ String statuscode = null, status = null;
|
|
|
+ int count = baseDao.getCountByCondition("SendNotifyDetail", "snd_snid=" + obj);
|
|
|
+ int yCount = baseDao.getCountByCondition("SendNotifyDetail", "snd_snid=" + obj + " and nvl(snd_yqty,0)=nvl(snd_outqty,0) and nvl(snd_yqty,0)>=0");
|
|
|
+ int xCount = baseDao.getCountByCondition("SendNotifyDetail", "snd_snid=" + obj + " and nvl(snd_yqty,0)=0");
|
|
|
+ statuscode = "PARTOUT";
|
|
|
+ status = "部分出库";
|
|
|
+ if (xCount == count) {
|
|
|
+ statuscode = "";
|
|
|
+ status = "";
|
|
|
+ }
|
|
|
+ if (yCount == count) {
|
|
|
+ statuscode = "TURNOUT";
|
|
|
+ status = "已出库";
|
|
|
+ }
|
|
|
+ baseDao.updateByCondition("SendNotify", "SN_SENDSTATUSCODE='" + statuscode + "',SN_SENDSTATUS='" + status + "'", "sn_id=" + obj);
|
|
|
+ }
|
|
|
+ if (keys!=null&&!keys.isEmpty()) {
|
|
|
+ String code="";
|
|
|
+ for (Key key:keys) {
|
|
|
+ //过账出货单
|
|
|
+ String s = postProdInOut(key.getId(), "ProdInOut!Sale", employee);
|
|
|
+ code=code+key.getCode()+",";
|
|
|
+ }
|
|
|
+ return ApiResponse.successRsp("0", requestId, "出货单:" + code + ",请在ERP查看!");
|
|
|
}else
|
|
|
- return ApiResponse.failRsp("10081",requestId,"参数异常!");
|
|
|
- }else
|
|
|
+ return ApiResponse.failRsp("10082",requestId,"生成失败!");
|
|
|
+ } else
|
|
|
return ApiResponse.failRsp("10081",requestId,"参数异常!");
|
|
|
}
|
|
|
|
|
|
@@ -1941,6 +1944,16 @@ public class MESServiceImpl implements MESService {
|
|
|
}
|
|
|
return jsonObject;
|
|
|
}
|
|
|
+ private List<Map<Object, Object>> getJsonsData(HttpServletRequest request){
|
|
|
+ try {
|
|
|
+ String data = PSHttpUtils.readRaw(request.getInputStream());
|
|
|
+ return BaseUtil.parseGridStoreToMaps(data);
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.info("参数解析异常信息:"+e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
private ApiResult<String> checkMESCode(String requestId,String mesNo,String piclass){
|
|
|
if ("".equals(mesNo)){
|