|
|
@@ -1231,9 +1231,9 @@ public class MESServiceImpl implements MESService {
|
|
|
if (baseDao.checkIf("makematerial","nvl(mm_cp_user,0)=0 and nvl(mm_qty,0)>0 and mm_maid="+data[5])){
|
|
|
Object canmadeqty = baseDao.getFieldDataByCondition("make", "(select min(case when NVL(mm_havegetqty,0)-NVL(mm_scrapqty,0)>=mm_qty then ma_qty else floor((nvl(mm_havegetqty, 0)-nvl(mm_scrapqty,0))*1.0/mm_oneuseqty)end) from makematerial where mm_maid=ma_id and nvl(mm_materialstatus,' ')=' ' and mm_oneuseqty>0 and mm_oneuseqty*ma_qty<=mm_qty+0.1 and nvl(mm_cp_user,0)=0)","ma_code='" + makeCode + "'");
|
|
|
//备料齐套数量
|
|
|
- map.put("canmadeqty",canmadeqty);
|
|
|
+ map.put("canmadeqty",Double.parseDouble(StringUtil.nvl(canmadeqty,"0")));
|
|
|
}else {
|
|
|
- map.put("canmadeqty",data[2]);
|
|
|
+ map.put("canmadeqty",Double.parseDouble(StringUtil.nvl(data[2],"0")));
|
|
|
}
|
|
|
//工单数量
|
|
|
map.put("qty",data[2]);
|
|
|
@@ -1726,6 +1726,9 @@ public class MESServiceImpl implements MESService {
|
|
|
String msclass = "生产报废单";
|
|
|
Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?", new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
|
|
|
String msId = StringUtil.nvl(data.get("scrapid"), "");
|
|
|
+ if (baseDao.checkIf("MakeScrap","ms_statuscode='CONFIRMED' and ms_id="+msId)){
|
|
|
+ return ApiResponse.failRsp("10075",requestId,"生产报废单已确认!");
|
|
|
+ }
|
|
|
baseDao.updateByCondition("MakeScrapdetail", "md_status=99", "md_msid=" + msId);
|
|
|
List<Object[]> objects = baseDao.getFieldsDatasByCondition("MakeScrapdetail left join make on ma_code=md_mmcode ", new String[]{
|
|
|
"ma_id", "md_mmdetno", "md_qty", "md_prodcode"}, " md_msid=" + msId);
|
|
|
@@ -1745,7 +1748,7 @@ public class MESServiceImpl implements MESService {
|
|
|
int apId = baseDao.getSeqId("APPLICATION_SEQ");
|
|
|
apCode = baseDao.sGetMaxNumber("Application", 2);
|
|
|
Object dpcode = baseDao.getFieldDataByCondition("MakeScrapDetail", "min(md_department)", "md_msid=" + msId);
|
|
|
- baseDao.execute("insert into Application (ap_id,ap_code,ap_kind,ap_date,ap_statuscode,ap_status,ap_pleamanname,ap_pleamanid,ap_recorder,ap_recorderid,ap_recorddate,ap_departcode,ap_departname,ap_source,ap_sourceid,ap_printstatuscode,ap_printstatus,ap_remark,ap_bfcode_user) values " +
|
|
|
+ baseDao.execute("insert into Application (ap_id,ap_code,ap_kind,ap_date,ap_statuscode,ap_status,ap_pleamanname,ap_pleamanid,ap_recorder,ap_recorderid,ap_recorddate,ap_departcode,ap_departname,ap_source,ap_sourceid,ap_printstatuscode,ap_printstatus,ap_remark,ap_bfcode_user) " +
|
|
|
" select " + apId + ",'" + apCode + "','超损请购',sysdate,'ENTERING','在录入','" + employee.getEm_name() + "'," + employee.getEm_id() + ",'" + employee.getEm_name() + "'," + employee.getEm_id() + ",sysdate,'" + dpcode + "',dp_name,'" + msclass + "',ms_id,'UNPRINT','未打印','MES生产报废单确认生成',ms_code from MakeScrap,department where dp_code='" + dpcode + "' and ms_id=" + msId);
|
|
|
baseDao.execute("insert into applicationdetail (ad_id,ad_apid,ad_code,ad_detno,ad_prodcode,ad_qty,ad_use,ad_statuscode,ad_status,ad_source,ad_sourcecode,ad_remark,ad_zzcode_user,ad_zzxh_user,ad_sacode,ad_sadetno) " +
|
|
|
"select APPLICATIONDETAIL_SEQ.nextval," + apId + ",'" + apCode + "',md_detno,md_prodcode,md_qty,md_reason,'ENTERING','在录入','" + msclass + "',md_code,'MES生产报废单审核生成',md_mmcode,md_mmdetno,ma_salecode,ma_saledetno from MakeScrapdetail left join make on md_mmcode=ma_code where md_msid=" + msId);
|
|
|
@@ -1756,6 +1759,160 @@ public class MESServiceImpl implements MESService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ApiResult<String> confirmSendNotify(HttpServletRequest request) {
|
|
|
+ String requestId = request.getHeader("RequestId");
|
|
|
+ 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("10075", requestId, "存在待审批的销售变更单,不能进行转出操作!行号:" + dets);
|
|
|
+ }
|
|
|
+ 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("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_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,"物料不能为空!");
|
|
|
+ }
|
|
|
+ if (!baseDao.checkIf("SendNotifyDetail","snd_prodcode='"+prodCode+"' and snd_id="+sndId)){
|
|
|
+ return ApiResponse.failRsp("10079", requestId, "明细行物料不存在,请核对!");
|
|
|
+ }
|
|
|
+ if ("".equals(whCode)){
|
|
|
+ return ApiResponse.failRsp("10063",requestId,"仓库不能为空!");
|
|
|
+ }
|
|
|
+ int count = baseDao.getCount("select count(1) from customtabledetail left join customtable on cd_ctid=ct_id where ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whCode + "'");
|
|
|
+ if (count<=0){
|
|
|
+ return ApiResponse.failRsp("10064",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
|
|
|
+ }
|
|
|
+ Object[] wh = baseDao.getFieldsDataByCondition("customtabledetail left join customtable on cd_ctid=ct_id left join Warehouse on cd_varchar50_3=wh_code", "cd_varchar50_3,wh_description", "ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whCode + "'");
|
|
|
+ if (tqty<=0){
|
|
|
+ return ApiResponse.failRsp("10063",requestId,"数量需要大于0!");
|
|
|
+ }
|
|
|
+ if (baseDao.checkIf("SendNotifyDetail","nvl(snd_yqty,0)+"+tqty+">nvl(snd_outqty,0) and snd_id="+sndId)){
|
|
|
+ return ApiResponse.failRsp("10063",requestId,"数量+已转出货数不能大于通知单数量!");
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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", 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 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_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 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 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);
|
|
|
+ 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("10082",requestId,"生成失败!");
|
|
|
+ } else
|
|
|
+ return ApiResponse.failRsp("10081",requestId,"参数异常!");
|
|
|
+ }
|
|
|
+
|
|
|
private Map<String, JSONArray> getData(HttpServletRequest request){
|
|
|
Map<String, JSONArray> map = new HashMap<>();
|
|
|
try {
|
|
|
@@ -1787,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)){
|