diff --git a/so/META-INF/ClosesoUpdateBL.rest b/so/META-INF/ClosesoUpdateBL.rest new file mode 100644 index 0000000..56b3de4 --- /dev/null +++ b/so/META-INF/ClosesoUpdateBL.rest @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/so/META-INF/Updateinformer.rest b/so/META-INF/Updateinformer.rest new file mode 100644 index 0000000..49bf735 --- /dev/null +++ b/so/META-INF/Updateinformer.rest @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/so/META-INF/bipDelete.rest b/so/META-INF/bipDelete.rest new file mode 100644 index 0000000..b4fca4d --- /dev/null +++ b/so/META-INF/bipDelete.rest @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/so/META-INF/saleUpdateLJfh.rest b/so/META-INF/saleUpdateLJfh.rest new file mode 100644 index 0000000..e32f48a --- /dev/null +++ b/so/META-INF/saleUpdateLJfh.rest @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/so/META-INF/saleUpdateLJpc.rest b/so/META-INF/saleUpdateLJpc.rest new file mode 100644 index 0000000..1896cc0 --- /dev/null +++ b/so/META-INF/saleUpdateLJpc.rest @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/so/META-INF/saleorder_saleinvoice.rest b/so/META-INF/saleorder_saleinvoice.rest new file mode 100644 index 0000000..622cd8d --- /dev/null +++ b/so/META-INF/saleorder_saleinvoice.rest @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/so/META-INF/sobill.rest b/so/META-INF/sobill.rest new file mode 100644 index 0000000..e740ad8 --- /dev/null +++ b/so/META-INF/sobill.rest @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/so/META-INF/updateSendQty.rest b/so/META-INF/updateSendQty.rest new file mode 100644 index 0000000..931f0b7 --- /dev/null +++ b/so/META-INF/updateSendQty.rest @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/so/src/public/nccloud/api/so/so/UpCdate/Updateinformer.java b/so/src/public/nccloud/api/so/so/UpCdate/Updateinformer.java new file mode 100644 index 0000000..80b7d55 --- /dev/null +++ b/so/src/public/nccloud/api/so/so/UpCdate/Updateinformer.java @@ -0,0 +1,303 @@ +package nccloud.api.so.so.UpCdate; +import nc.jdbc.framework.processor.MapListProcessor; +import org.springframework.util.ObjectUtils; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import nc.bs.dao.BaseDAO; +import nc.bs.framework.common.NCLocator; +import nc.itf.uap.IUAPQueryBS; +import nc.jdbc.framework.JdbcSession; +import nc.jdbc.framework.PersistenceManager; +import nc.jdbc.framework.exception.DbException; +import nc.jdbc.framework.processor.ArrayListProcessor; +import nc.jdbc.framework.processor.ColumnProcessor; +import nc.vo.pub.BusinessException; +import nccloud.api.rest.utils.ResultMessageUtil; +import nccloud.ws.rest.resource.AbstractNCCRestResource; +import org.json.JSONString; +import org.apache.http.client.methods.CloseableHttpResponse; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import nc.itf.cm.productcostcollect.IProductCostCollectService; +@Path("so/so/UpCdate") +public class Updateinformer extends AbstractNCCRestResource { + + @Override + public String getModule() { + return "so"; + } + + // ڴ洢ֹάıֶκֶ˵ + private Map requiredFields; + + // 췽ʼֶμ˵ + public Updateinformer() { + // ʼֶбֶ˵ + requiredFields = new HashMap<>(); + requiredFields.put("pk_org", "ҵԪ"); + requiredFields.put("array.vbillcode", "ݱ"); + requiredFields.put("array.crowno", "к"); + requiredFields.put("array.sendQty", ""); + } + + @POST + @Path("/Updateinformer") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString Updateinformer(JSONString json) { + JSONObject returnJson = new JSONObject(); + try { + + JSONObject object = JSON.parseObject(json.toJSONString()); + if (object == null) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException("JSONString:null")); + } + // Уֶ +// String tipsStr = checkRequiredFields(object); +// if (!tipsStr.equals("")) { +// return ResultMessageUtil.exceptionToJSON(new NullPointerException(tipsStr)); +// } + Object obj = object.getOrDefault("array", ""); + if (obj.equals("")) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException("array:null")); + } + + ArrayList arrayList = new ArrayList<>(); + if (obj instanceof JSONArray) { + JSONArray jsonArray = (JSONArray) obj; + arrayList = new ArrayList<>(jsonArray.toJavaList(Object.class)); + } +// StringBuilder sqlStr = new StringBuilder(); + List sqlStr = new ArrayList(); + ArrayList pk_list=null; + + +// for (int i = 0; i < arrayList.size(); i++) { +// Map dataMap = (Map) arrayList.get(i); +// pk_list.add((String) dataMap.get("pk_informer")); +// } + String result = ""; + StringBuilder sb = new StringBuilder(); + if (arrayList.size() > 1) { + for (int i = 0; i < arrayList.size(); i++) { + Map dataMap = (Map) arrayList.get(i); + + sb.append("'").append(dataMap.get("pk_informer")).append("'"); + if (i < arrayList.size() - 1) { + sb.append(","); + } + } + + result = sb.toString(); + }else { + Map dataMap = (Map) arrayList.get(0); + + result= "'"+(String) dataMap.get("pk_informer")+"'"; + + } + String sqlser="select pk_informer from cmp_informer where pk_informer in("+result+")"; +// ArrayList results = (ArrayList) getQueryService().executeQuery(sqlser, new ArrayListProcessor()); + List> results = (List>) getQueryService().executeQuery(sqlser, new MapListProcessor()); +// if (results != null || results.size()!=arrayList.size()) { +// vbillcodes.add(dataMap.get("pk_informer")); +// }else { +// returnJson.put("state", '0'); +// returnJson.put("msg", "ʧ,"+dataMap.get("pk_informer")+""); +// return (JSONString) returnJson; +// } + ArrayList result2 = new ArrayList<>(); + System.out.println(results.getClass()); + for (int i = 0; i < results.size(); i++) { + Map aa=results.get(i); + result2.add((String) aa.get("pk_informer")); + } + ArrayList vbillcodes = new ArrayList<>(); + for (int i = 0; i < arrayList.size(); i++) { + Map dataMap = (Map) arrayList.get(i); + Object pkInformer = dataMap.get("pk_informer"); + Object status = dataMap.get("status"); + + if (pkInformer == null || status == null) { + continue; // null ֵ + } + //жַڲresultsѯ + //resultsֵΪstring + + String pk_informer= (String) dataMap.get("pk_informer"); + if (result2.contains(pk_informer)) { + vbillcodes.add(dataMap.get("pk_informer")); + + sqlStr.add("UPDATE cmp_informer SET def01 = '" + dataMap.get("status") + "' where pk_informer='"+dataMap.get("pk_informer") + + "';"); + } + } + returnJson.put("codeList", vbillcodes); + + int succState = executeUpdate(sqlStr); + + returnJson.put("state", '1'); + if (succState == 0) { + returnJson.put("msg", "ʧ"); + }else { + returnJson.put("msg", "ɹ,޸"+succState+""); + + } + return ResultMessageUtil.toJSON(returnJson); + } catch (DbException e) { + throw new RuntimeException(e); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** + * updateSqlsΪҪִеsql䡣Ӱ + */ + public int executeUpdate(List updateSqls) throws DbException { + if (updateSqls == null) { + return 0; + } + + int ret = 0; + PersistenceManager manager = null; + JdbcSession session = null; + Connection connection = null; + + try { + manager = PersistenceManager.getInstance(); + session = manager.getJdbcSession(); + connection = session.getConnection(); // ȡʵʵݿ + + // ʼ + connection.setAutoCommit(false); // Զύֶ + + // ִ + for (String sql : updateSqls) { + session.addBatch(sql); + } + + // ִ + ret = session.executeBatch(); + + // ύ + connection.commit(); // ɹύ + + } catch (DbException e) { + if (connection != null) { + try { + // 쳣ع + connection.rollback(); + } catch (SQLException rollbackEx) { + // ¼ع쳣ϸϢ + throw new DbException("Error during transaction rollback", rollbackEx) { + @Override + public boolean isDataIntegrityViolation() { + return false; + } + + @Override + public boolean isBadSQLGrammar() { + return false; + } + }; + } + } + throw e; // ԭʼ쳣׳ + } catch (SQLException e) { + throw new RuntimeException(e); + } finally { + if (connection != null) { + try { + // ָԶύģʽȷӰ + connection.setAutoCommit(true); + } catch (SQLException e) { + // ԻָԶύʱ쳣 + } + } + if (manager != null) { + manager.release(); + } + } + + return ret; + } + + // תMap + public static String checkRequiredFields(JSONObject data) throws Exception { + String returnStr = ""; + // 2. ֶ pk_org + String pkOrg = (String) data.getOrDefault("pk_org", ""); + if (pkOrg.isEmpty()) { + return "ֶpk_orgȱʧΪ!"; + } + // 3. ȡ array ֶ + Object array = data.getOrDefault("array", null); + if (array == null || !(array instanceof JSONArray) || ((JSONArray) array).isEmpty()) { + return "arrayΪջ򲻴!"; + } + ArrayList arrayList = new ArrayList<>(); + if (array instanceof JSONArray) { + JSONArray jsonArray = (JSONArray) array; + arrayList = new ArrayList<>(jsonArray.toJavaList(Object.class)); + } + // 5. ÿ󣬼ֶ + for (int i = 0; i < arrayList.size(); i++) { + Map item = (Map) arrayList.get(i); + // ֶ 'crowno' + if (item.getOrDefault("crowno", "").toString().isEmpty()) { + return " " + (i + 1) + " ȱٱֶcrowno!"; + } + // ֶ 'vbillcode' + if (item.getOrDefault("vbillcode", "").toString().isEmpty()) { + return " " + (i + 1) + " ȱٱֶvbillcode!"; + } + // ֶ 'sendQty' + if (item.getOrDefault("sendQty", "").toString().isEmpty()) { + return " " + (i + 1) + " ȱٱֶsendQty!"; + } + } + return returnStr; + } + + + /* + *ʱ䣺2024-11-28 + *ãѯ + *ֵ + *ֵmap + */ + private String getSaleorderBPK(String pk_org, String vbillcode, String crowno) throws BusinessException { + String sql = " select b.csaleorderbid from so_saleorder h \n" + + "left join so_saleorder_b b on h.csaleorderid=b.csaleorderid\n" + + "left join org_salesorg o on h.pk_org=o.pk_salesorg\n" + + "where h.vbillcode='" + vbillcode + "' and o.code='" + pk_org + "' and b.crowno='" + crowno + "' "; + String saleorderBPK = (String) getQueryService().executeQuery(sql, new ColumnProcessor()); + return saleorderBPK; + } + + /* + *ʱ䣺2024-11-28 + *ãѯ + *ֵ + *ֵmap + */ + private int updateSaleBSQty(String sql) throws BusinessException { + BaseDAO baseDAO = new BaseDAO(); + int succInt = baseDAO.executeUpdate(sql); + return succInt; + } + + public IUAPQueryBS getQueryService() { + return NCLocator.getInstance().lookup(IUAPQueryBS.class); + } + +} diff --git a/so/src/public/nccloud/api/so/so/UpCloses/ClosesoUpdateBL.java b/so/src/public/nccloud/api/so/so/UpCloses/ClosesoUpdateBL.java new file mode 100644 index 0000000..8714804 --- /dev/null +++ b/so/src/public/nccloud/api/so/so/UpCloses/ClosesoUpdateBL.java @@ -0,0 +1,306 @@ +package nccloud.api.so.so.UpCloses; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.HashSet; +import java.util.Set; +import java.util.TimeZone; +import java.util.Arrays; + + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import nc.bs.framework.common.NCLocator; +import nc.impl.pubapp.pattern.data.bill.BillQuery; +import nc.itf.uap.IUAPQueryBS; +import nc.jdbc.framework.processor.ArrayListProcessor; + + +import nc.vo.mmpac.pickm.entity.AggPickmVO; +import nc.vo.pub.BusinessException; +import nc.vo.pub.lang.UFDateTime; +import nc.vo.so.m30.entity.SaleOrderViewVO; +import nccloud.api.rest.utils.ResultMessageUtil; +import nccloud.dto.mmpac.pickm.pub.entity.PickmDeleteInfo; +import nccloud.pubitf.so.saleorderclose.utils.SaleOrderCloseUtils; +import nccloud.util.so.TransBillUtil; + + +import nccloud.ws.rest.resource.AbstractNCCRestResource; +import org.json.JSONString; +import nc.bs.dao.BaseDAO; + +import nccloud.pubitf.so.saleorderclose.service.IQuerySaleOrderCloseService; + +import nc.itf.mmpac.pickm.IPickmMaintainService; + + +@Path("so/so/UpCloses") +public class ClosesoUpdateBL extends AbstractNCCRestResource { + + @Override + public String getModule() { + return "so"; + } + + // ڴ洢ֹάıֶκֶ˵ + private Map requiredFields; + + // 췽ʼֶμ˵ + public ClosesoUpdateBL() { + // ʼֶбֶ˵ + requiredFields = new HashMap<>(); + requiredFields.put("pk_org", "ҵԪ"); + requiredFields.put("array.vbillcode", "ݱ"); + requiredFields.put("array.crowno", "к"); + requiredFields.put("array.sendQty", ""); + } + + @POST + @Path("/ClosesoUpdateBL") + @Consumes({"application/json"}) + @Produces({"application/json"}) +/** + * ر۶ + * ÷һJSONַΪ룬֤еݣȻݲ͹رӦ۶ + * + * @param json ۶ϢͲ͵JSONַ + * @return һJSONַʾ + */ +public JSONString ClosesoUpdateBL(JSONString json) { + JSONObject errojson = new JSONObject(); + Set vbillcodes = new HashSet<>(); + // map 9-᣻ 10-᣻ 11-ֹ 8Ч(ȡ) + Map operationMap = new HashMap<>(); + + try { + ArrayList bidsList = new ArrayList<>(); + operationMap.put("9", ""); + operationMap.put("10", ""); + operationMap.put("11", "ֹ"); + operationMap.put("8", "Ч"); + // JSONַΪJSONObject + JSONObject jObject = JSON.parseObject(json.toJSONString()); + if (jObject == null) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException("JSONString:null")); + } + String operation = (String) jObject.getOrDefault("operation", ""); + String pk_org = null; + + // ӽJSONлȡҪֶ + JSONArray array = jObject.getJSONArray("array"); + + // ѭ array ȡֵ + String updateSql = null; + String def1=operationMap.get(operation.toString()); + if (def1 == null){ + return ResultMessageUtil.exceptionToJSON(new NullPointerException("Ͳ")); + } + for (int i = 0; i < array.size(); i++) { + Map item = (Map) array.get(i); + String vctcode = (String) item.getOrDefault("vctcode", ""); + updateSql = " UPDATE so_saleorder h" + + " SET h.vdef7 = '" + operationMap.get(operation.toString()) + "' " + + " WHERE EXISTS (" + + " SELECT 1" + + " FROM so_saleorder_b b" + + " left join bd_defdoc hbd on hbd.pk_defdoc=b.vbdef1 "+ + " WHERE b.csaleorderid = h.csaleorderid" + + " AND hbd.code = '" + vctcode + "' " + + " );"; + // ֤operationֶǷ + if (vctcode == null) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException("vctcode:null")); + } + // ֯ID۶ȡ۶Ψһʶ + String sql = " select h.csaleorderid,b.csaleorderbid,h.ts,hbd.code as vbillcode,o.code as pk_org from so_saleorder h " + + "left join so_saleorder_b b on h.csaleorderid=b.csaleorderid " + + "left join org_salesorg o on h.pk_org=o.pk_salesorg " + +" left join bd_defdoc hbd on hbd.pk_defdoc=b.vbdef1 "+ + + "where hbd.code='" + vctcode + "' "; + List result = (List) getQueryService().executeQuery(sql, new ArrayListProcessor()); + if (result == null || result.size() == 0) { + errojson.put("status", "0"); + errojson.put("message", "ѯ޴˺ͬ"); + errojson.put("codeList", null); + + // رʾɹJSONַ + return ResultMessageUtil.toJSON(errojson); + } + + // ѭresultȡcsaleorderbidts"1001A11000000B0OJ2HI,2024-12-02 10:16:10"ʽbidsList + for (Object[] row : result) { + String csaleorderbid = (String) row[1]; + String ts = (String) row[2]; + bidsList.add(csaleorderbid + "," + ts); + String vbillcode = (String) row[3]; + if (vbillcode != null) { + pk_org=(String)row[4]; + vbillcodes.add(vbillcode); + } + } + } + // ʹ ArrayList 洢 PickmDeleteInfo + ArrayList pickmDeleteInfoList = new ArrayList<>(); + for (String vbillcode : vbillcodes) { +// String vsql = "select cpickmid,ts from mm_pickm where vbillcode='" + vbillcode + "'"; + String vsql = "select mm.cpickmid,mm.ts,hbd.code as vbillcode,mm.pk_org,hbd.code as vctcode from mm_pickm mm " + + " left join org_salesorg o on mm.pk_org=o.pk_salesorg " + + " left join bd_defdoc hbd on hbd.pk_defdoc=mm.vdef6" + + " where hbd.code='"+vbillcode+"'"; + + List vresult = (List) getQueryService().executeQuery(vsql, new ArrayListProcessor()); + for (Object[] row : vresult) { + String csaleorderbid = (String) row[0]; + String ts = (String) row[1]; + // PickmDeleteInfo + PickmDeleteInfo info = new PickmDeleteInfo(); + info.setPks(csaleorderbid); + info.setTs(new UFDateTime(ts, TimeZone.getTimeZone("Asia/Shanghai"))); + // PickmDeleteInfo ӵб + pickmDeleteInfoList.add(info); + } + } + +// ArrayList תΪ + PickmDeleteInfo[] pickmDeleteInfos = pickmDeleteInfoList.toArray(new PickmDeleteInfo[0]); + + + + IPickmMaintainService context = (IPickmMaintainService) NCLocator.getInstance().lookup(IPickmMaintainService.class.getName()); + AggPickmVO[] aggVOs = getAggPickmVOs(pickmDeleteInfos); + String ret2 = ""; + +// 9-᣻ 10-᣻ 11-ֹ 8Ч(ȡ) + + String ret; + // ݲִӦķ񷽷 + if (operation.equals("9")) { + // ִйرղ + // pickmDeleteInfoListΪִִret2 = Arrays.toString(context.finishPickm(aggVOs)); + if (aggVOs.length>0){ + ret2 = Arrays.toString(context.finishPickm(aggVOs)); + + } + } else if (operation.equals("8")) { + // ִп + if (aggVOs.length>0){ + ret2 = Arrays.toString(context.unfinishPickm(aggVOs)); + + } + } else if (operation.equals("11")) { + // ִп + if (aggVOs.length>0) { + ret2 = Arrays.toString(context.unfinishPickm(aggVOs)); + } + } + + + int succState = updateSaleBSQty(updateSql.toString()); + + // ɹôJSONcodeΪ0ʾɹ + errojson.put("status", "1"); + errojson.put("message", "۶״̬޸"+succState+""+ret2); + errojson.put("codeList", vbillcodes); + + // رʾɹJSONַ + return ResultMessageUtil.toJSON(errojson); + + } catch (Exception e) { + errojson.put("status", "0"); + errojson.put("message", e.getMessage()); + errojson.put("codeList", vbillcodes); + // رʾʧܵJSONַ + return ResultMessageUtil.toJSON(errojson); + } +} + /** + * ɾϢȡӦAggPickmVO + * ˷ڸPickmDeleteInfoеϢѯAggPickmVO + * ȡɾϢеʱȻѯӦAggPickmVO + * ʱϢӵѯĶ + * + * @param deleteinfo ɾϢ飬ڻȡɾ¼ʱ + * @return زѯAggPickmVO飬δҵܷnull + */ + private AggPickmVO[] getAggPickmVOs(PickmDeleteInfo[] deleteinfo) { + // ʼһַ飬ڴ洢ɾϢ + String[] pks = new String[deleteinfo.length]; + // ʼһHashMapڴ洢ͶӦʱ + Map map = new HashMap(); + + // ɾϢ飬ȡʱ洢Ӧݽṹ + for(int i = 0; i < deleteinfo.length; ++i) { + String pk = deleteinfo[i].getPks(); + pks[i] = pk; + map.put(pk, deleteinfo[i].getTs()); + } + + // һBillQueryڲѯAggPickmVOĶ + BillQuery query = new BillQuery(AggPickmVO.class); + // ʹȡѯӦAggPickmVO + AggPickmVO[] aggVOs = (AggPickmVO[])query.query(pks); + + // ѯAggPickmVO鲻Ϊգ飬ʱϢӵÿ + if (aggVOs != null && aggVOs.length > 0) { + for(int j = 0; j < aggVOs.length; ++j) { + String key = aggVOs[j].getParentVO().getCpickmid(); + aggVOs[j].getParentVO().setAttributeValue("ts", map.get(key)); + } + } + + // زѯAggPickmVO + return aggVOs; + } + /** + * ݸҵID͹رԭѯ۶ͼϢ + * + * @param bidts ҵIDʱַ飬ڲѯض۶ + * @param vclosereason ۶Ĺرԭڹ˲ѯùر״̬ + * @return SaleOrderViewVO[] һ۶ͼ飬ѯ۶Ϣ + * @throws BusinessException ѯзʱ׳쳣 + */ + public static SaleOrderViewVO[] queryViewByBIDs(String[] bidts, String vclosereason) throws BusinessException { + // һӳ䣬ڴ洢ҵIDʱַȡʱϢ + Map bid_ts = new HashMap(); + // ʹù෽ҵIDʱַȡҵIDͶӦʱϢ + String[] bids = TransBillUtil.splitBidts(bidts, bid_ts); + + // ͨλȡѯ۶ر״̬ķʵ + IQuerySaleOrderCloseService service = (IQuerySaleOrderCloseService)NCLocator.getInstance().lookup(IQuerySaleOrderCloseService.class); + // ÷񷽷ҵIDѯ۶ͼϢ + SaleOrderViewVO[] vos = service.queryByIds(bids); + + // ʹù෽֮ǰȡʱϢ۶ͼеʱֶ + TransBillUtil.fillBodyTs(vos, "csaleorderbid", bid_ts); + // ۶ͼеĹرԭϢ + SaleOrderCloseUtils.setCloseOpenReason(vos, vclosereason); + // ˲ѯ۶ͼ + return vos; + } + /* + *ʱ䣺2024-11-28 + *ãѯ + *ֵ + *ֵmap + */ + private int updateSaleBSQty(String sql) throws BusinessException { + BaseDAO baseDAO = new BaseDAO(); + int succInt = baseDAO.executeUpdate(sql); + return succInt; + } + + public IUAPQueryBS getQueryService() { + return NCLocator.getInstance().lookup(IUAPQueryBS.class); + } + +} \ No newline at end of file diff --git a/so/src/public/nccloud/api/so/so/saleorder/bipDelete.java b/so/src/public/nccloud/api/so/so/saleorder/bipDelete.java new file mode 100644 index 0000000..0774f0f --- /dev/null +++ b/so/src/public/nccloud/api/so/so/saleorder/bipDelete.java @@ -0,0 +1,125 @@ +package nccloud.api.so.so.saleorder; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import nc.bs.framework.common.NCLocator; +import nc.itf.uap.IUAPQueryBS; +import nc.jdbc.framework.exception.DbException; +import nc.jdbc.framework.processor.ColumnProcessor; +import nc.pubitf.so.m30.api.ISaleOrderQueryAPI; +import nc.vo.pub.BusinessException; +import nc.vo.scmpub.res.billtype.SOBillType; +import nc.vo.scmpub.util.AppInfoContext; +import nc.vo.so.m30.entity.SaleOrderVO; +import nccloud.api.rest.utils.ResultMessageUtil; +import nccloud.pubitf.riart.pflow.CloudPFlowContext; +import nccloud.pubitf.riart.pflow.ICloudScriptPFlowService; +import nccloud.ws.rest.resource.AbstractNCCRestResource; +import org.json.JSONString; + +@Path("so/so/saleorder") +public class bipDelete extends AbstractNCCRestResource { + + @Override + public String getModule() { + return "so"; + } + + @POST + @Path("/bipDelete") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString bipDelete(JSONString json) { + try { + JSONObject object = JSON.parseObject(json.toJSONString()); + if (object == null) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException("JSONString:null")); + } + // Уֶ + String tipsStr = checkRequiredFields(object); + if (!tipsStr.equals("")) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException(tipsStr)); + } + String pk_org = (String) object.getOrDefault("pk_org", ""); + String vbillcode = (String) object.getOrDefault("vbillcode", ""); + String saleDelStr = getSaleorderPK(pk_org, vbillcode); + if (saleDelStr == null || saleDelStr.equals("")) { + JSONObject returnJson = new JSONObject(); + returnJson.put("state", 0); + returnJson.put("Ascript", "ɾʧܣûҵӦ۶!"); + returnJson.put("result", ""); + return ResultMessageUtil.toJSON(returnJson); + } + String[] ids = {saleDelStr}; + SaleOrderVO[] billvos = NCLocator.getInstance().lookup(ISaleOrderQueryAPI.class).queryVOByIDs(ids); + + CloudPFlowContext context = new CloudPFlowContext(); + context.setActionName("DELETE"); + context.setBillType(SOBillType.Order.getCode()); + context.setBillVos(billvos); + AppInfoContext.setBtnCode("Delete"); + ICloudScriptPFlowService service = NCLocator.getInstance().lookup(ICloudScriptPFlowService.class); + Object obj = service.exeScriptPFlow(context); + + JSONObject returnJson = new JSONObject(); + returnJson.put("state", 1); + returnJson.put("Ascript", "ɾɹ!"); + returnJson.put("result", billvos); + + return ResultMessageUtil.toJSON(returnJson); + } catch (DbException e) { + JSONObject returnJson = new JSONObject(); + returnJson.put("state", 0); + returnJson.put("Ascript", "ɾʧ" + e.getMessage()); + returnJson.put("result", ""); + return ResultMessageUtil.toJSON(returnJson); + } catch (Exception e) { + JSONObject returnJson = new JSONObject(); + returnJson.put("state", 0); + returnJson.put("Ascript", "ɾʧ" + e.getMessage()); + returnJson.put("result", ""); + return ResultMessageUtil.toJSON(returnJson); + } + } + + // תMap + public static String checkRequiredFields(JSONObject data) throws Exception { + String returnStr = ""; + // 2. ֶ pk_org + String pkOrg = (String) data.getOrDefault("pk_org", ""); + if (pkOrg.isEmpty()) { + return "ֶpk_orgȱʧΪ!"; + } + // 2. ֶ pk_org + String vbillcode = (String) data.getOrDefault("vbillcode", ""); + if (vbillcode.isEmpty()) { + return "ֶvbillcodeȱʧΪ!"; + } + return returnStr; + } + + + /* + *ʱ䣺2024-11-28 + *ãѯ + *ֵ + *ֵmap + */ + private String getSaleorderPK(String pk_org, String vbillcode) throws BusinessException { + String sql = " select h.csaleorderid from so_saleorder h\n" + + "LEFT JOIN org_salesorg o ON h.pk_org = o.pk_salesorg\n" + + "where o.code = '" + pk_org + "' and h.vbillcode = '" + vbillcode + "' "; + String saleorderPK = (String) getQueryService().executeQuery(sql, new ColumnProcessor()); + return saleorderPK; + } + + + public IUAPQueryBS getQueryService() { + return NCLocator.getInstance().lookup(IUAPQueryBS.class); + } + +} \ No newline at end of file diff --git a/so/src/public/nccloud/api/so/so/saleorder/saleUpdateLJfh.java b/so/src/public/nccloud/api/so/so/saleorder/saleUpdateLJfh.java new file mode 100644 index 0000000..48c790f --- /dev/null +++ b/so/src/public/nccloud/api/so/so/saleorder/saleUpdateLJfh.java @@ -0,0 +1,247 @@ +package nccloud.api.so.so.saleorder; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import nc.bs.framework.common.NCLocator; +import nc.itf.uap.IUAPQueryBS; +import nc.jdbc.framework.JdbcSession; +import nc.jdbc.framework.PersistenceManager; +import nc.jdbc.framework.exception.DbException; +import nc.jdbc.framework.processor.ColumnProcessor; +import nc.vo.pub.BusinessException; +import nccloud.api.rest.utils.ResultMessageUtil; +import nccloud.ws.rest.resource.AbstractNCCRestResource; +import org.json.JSONString; +import nc.bs.dao.BaseDAO; + +@Path("so/so/saleorder") +public class saleUpdateLJfh extends AbstractNCCRestResource { + + @Override + public String getModule() { + return "so"; + } + + // ڴ洢ֹάıֶκֶ˵ + private Map requiredFields; + + // 췽ʼֶμ˵ + public saleUpdateLJfh() { + // ʼֶбֶ˵ + requiredFields = new HashMap<>(); + requiredFields.put("pk_org", "ҵԪ"); + requiredFields.put("array.vbillcode", "ݱ"); + requiredFields.put("array.crowno", "к"); + requiredFields.put("array.sendQty", ""); + } + + @POST + @Path("/saleUpdateLJfh") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString saleUpdateLJfh(JSONString json) { + try { + + JSONObject object = JSON.parseObject(json.toJSONString()); + if (object == null) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException("JSONString:null")); + } + // Уֶ + String tipsStr = checkRequiredFields(object); + if (!tipsStr.equals("")) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException(tipsStr)); + } + String pk_org = (String) object.getOrDefault("pk_org", ""); + Object obj = object.getOrDefault("array", ""); + ArrayList arrayList = new ArrayList<>(); + if (obj instanceof JSONArray) { + JSONArray jsonArray = (JSONArray) obj; + arrayList = new ArrayList<>(jsonArray.toJavaList(Object.class)); + } +// StringBuilder sqlStr = new StringBuilder(); + List sqlStr = new ArrayList(); + for (int i = 0; i < arrayList.size(); i++) { + Map dataMap = (Map) arrayList.get(i); + sqlStr.add("UPDATE so_saleorder_b b " + + "SET b.vbdef2 = '" + dataMap.get("sendQty") + "'" + + "WHERE b.csaleorderid IN (" + + " SELECT h.csaleorderid" + + " FROM so_saleorder h" + + " LEFT JOIN org_salesorg o ON h.pk_org = o.pk_salesorg" + + " WHERE h.vbillcode = '" + dataMap.get("vbillcode") + "' " + + " AND o.code = '" + pk_org + "' " + + " AND b.crowno = '" + dataMap.get("crowno") + "'" + + ");"); + } +// int succState = updateSaleBSQty(sqlStr.toString()); + int succState = executeUpdate(sqlStr); + + JSONObject returnJson = new JSONObject(); + returnJson.put("state", '1'); + // + if (succState == 0) { + returnJson.put("msg", "ʧ"); + }else { + returnJson.put("msg", "ɹ,޸"+succState+""); + } + return ResultMessageUtil.toJSON(returnJson); + } catch (DbException e) { + throw new RuntimeException(e); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** + * updateSqlsΪҪִеsql䡣Ӱ + */ + public int executeUpdate(List updateSqls) throws DbException { + if (updateSqls == null) { + return 0; + } + + int ret = 0; + PersistenceManager manager = null; + JdbcSession session = null; + Connection connection = null; + + try { + manager = PersistenceManager.getInstance(); + session = manager.getJdbcSession(); + connection = session.getConnection(); // ȡʵʵݿ + + // ʼ + connection.setAutoCommit(false); // Զύֶ + + // ִ + for (String sql : updateSqls) { + session.addBatch(sql); + } + + // ִ + ret = session.executeBatch(); + + // ύ + connection.commit(); // ɹύ + + } catch (DbException e) { + if (connection != null) { + try { + // 쳣ع + connection.rollback(); + } catch (SQLException rollbackEx) { + // ¼ع쳣ϸϢ + throw new DbException("Error during transaction rollback", rollbackEx) { + @Override + public boolean isDataIntegrityViolation() { + return false; + } + + @Override + public boolean isBadSQLGrammar() { + return false; + } + }; + } + } + throw e; // ԭʼ쳣׳ + } catch (SQLException e) { + throw new RuntimeException(e); + } finally { + if (connection != null) { + try { + // ָԶύģʽȷӰ + connection.setAutoCommit(true); + } catch (SQLException e) { + // ԻָԶύʱ쳣 + } + } + if (manager != null) { + manager.release(); + } + } + + return ret; + } + + // תMap + public static String checkRequiredFields(JSONObject data) throws Exception { + String returnStr = ""; + // 2. ֶ pk_org + String pkOrg = (String) data.getOrDefault("pk_org", ""); + if (pkOrg.isEmpty()) { + return "ֶpk_orgȱʧΪ!"; + } + // 3. ȡ array ֶ + Object array = data.getOrDefault("array", null); + if (array == null || !(array instanceof JSONArray) || ((JSONArray) array).isEmpty()) { + return "arrayΪջ򲻴!"; + } + ArrayList arrayList = new ArrayList<>(); + if (array instanceof JSONArray) { + JSONArray jsonArray = (JSONArray) array; + arrayList = new ArrayList<>(jsonArray.toJavaList(Object.class)); + } + // 5. ÿ󣬼ֶ + for (int i = 0; i < arrayList.size(); i++) { + Map item = (Map) arrayList.get(i); + // ֶ 'crowno' + if (item.getOrDefault("crowno", "").toString().isEmpty()) { + return " " + (i + 1) + " ȱٱֶcrowno!"; + } + // ֶ 'vbillcode' + if (item.getOrDefault("vbillcode", "").toString().isEmpty()) { + return " " + (i + 1) + " ȱٱֶvbillcode!"; + } + // ֶ 'sendQty' + if (item.getOrDefault("sendQty", "").toString().isEmpty()) { + return " " + (i + 1) + " ȱٱֶsendQty!"; + } + } + return returnStr; + } + + + /* + *ʱ䣺2024-11-28 + *ãѯ + *ֵ + *ֵmap + */ + private String getSaleorderBPK(String pk_org, String vbillcode, String crowno) throws BusinessException { + String sql = " select b.csaleorderbid from so_saleorder h \n" + + "left join so_saleorder_b b on h.csaleorderid=b.csaleorderid\n" + + "left join org_salesorg o on h.pk_org=o.pk_salesorg\n" + + "where h.vbillcode='" + vbillcode + "' and o.code='" + pk_org + "' and b.crowno='" + crowno + "' "; + String saleorderBPK = (String) getQueryService().executeQuery(sql, new ColumnProcessor()); + return saleorderBPK; + } + + /* + *ʱ䣺2024-11-28 + *ãѯ + *ֵ + *ֵmap + */ + private int updateSaleBSQty(String sql) throws BusinessException { + BaseDAO baseDAO = new BaseDAO(); + int succInt = baseDAO.executeUpdate(sql); + return succInt; + } + + public IUAPQueryBS getQueryService() { + return NCLocator.getInstance().lookup(IUAPQueryBS.class); + } + +} \ No newline at end of file diff --git a/so/src/public/nccloud/api/so/so/saleorder/saleUpdateSQty.java b/so/src/public/nccloud/api/so/so/saleorder/saleUpdateSQty.java new file mode 100644 index 0000000..1d4167e --- /dev/null +++ b/so/src/public/nccloud/api/so/so/saleorder/saleUpdateSQty.java @@ -0,0 +1,260 @@ +package nccloud.api.so.so.saleorder; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.ufida.web.html.S; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import nc.bs.framework.common.NCLocator; +import nc.itf.uap.IUAPQueryBS; +import nc.jdbc.framework.JdbcSession; +import nc.jdbc.framework.PersistenceManager; +import nc.jdbc.framework.exception.DbException; +import nc.jdbc.framework.processor.ColumnProcessor; +import nc.vo.pub.BusinessException; +import nccloud.api.rest.utils.ResultMessageUtil; +import nccloud.ws.rest.resource.AbstractNCCRestResource; +import org.json.JSONString; +import nc.bs.dao.BaseDAO; +import nccloud.web.so.saleorder.action.SaleOrderBillCloseAction; + +@Path("so/so/SendQty") +public class saleUpdateSQty extends AbstractNCCRestResource { + + @Override + public String getModule() { + return "so"; + } + + // ڴ洢ֹάıֶκֶ˵ + private Map requiredFields; + + // 췽ʼֶμ˵ + public saleUpdateSQty() { + // ʼֶбֶ˵ + requiredFields = new HashMap<>(); + requiredFields.put("pk_org", "ҵԪ"); + requiredFields.put("array.vbillcode", "ݱ"); + requiredFields.put("array.crowno", "к"); + requiredFields.put("array.sendQty", ""); + } + + @POST + @Path("/updateSendQty") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString updateSendQty(JSONString json) { + try { + JSONObject returnJson = new JSONObject(); + JSONObject object = JSON.parseObject(json.toJSONString()); + if (object == null) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException("JSONString:null")); + } + // Уֶ + String tipsStr = checkRequiredFields(object); + if (!tipsStr.equals("")) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException(tipsStr)); + } + String pk_org = (String) object.getOrDefault("pk_org", ""); + Object obj = object.getOrDefault("array", ""); + ArrayList arrayList = new ArrayList<>(); + if (obj instanceof JSONArray) { + JSONArray jsonArray = (JSONArray) obj; + arrayList = new ArrayList<>(jsonArray.toJavaList(Object.class)); + } +// StringBuilder sqlStr = new StringBuilder(); + List sqlStr = new ArrayList(); + for (int i = 0; i < arrayList.size(); i++) { + Map dataMap = (Map) arrayList.get(i); + String csaleorderid = getSaleorderBPK(pk_org, (String) dataMap.get("vbillcode"), + (String) dataMap.get("crowno")); + if (csaleorderid != null) { + sqlStr.add( + "UPDATE so_saleorder_b SET vbdef2 = '" + dataMap.get("sendQty") + "' WHERE csaleorderbid='" + + csaleorderid + "'"); + } else { + returnJson.put("state", "N"); + returnJson.put("msg", + "޸ʧ,ţ" + dataMap.get("vbillcode") + "кţ" + dataMap.get( + "crowno") + "޷NCC۶"); + return ResultMessageUtil.toJSON(returnJson); + } + + } + int succState = executeUpdate(sqlStr); + + if (succState == arrayList.size()) { + returnJson.put("state", 'Y'); + returnJson.put("msg", "ɹ,޸" + succState + ""); + + } else { + returnJson.put("state", 'N'); + returnJson.put("msg", "ʧ,޸" + succState + ""); + } + return ResultMessageUtil.toJSON(returnJson); + } catch (DbException e) { + JSONObject returnJson = new JSONObject(); + returnJson.put("state", 'N'); + returnJson.put("msg", "޸ʧ" + e.getMessage()); + return ResultMessageUtil.toJSON(returnJson); + } catch (Exception e) { + JSONObject returnJson = new JSONObject(); + returnJson.put("state", 'N'); + returnJson.put("msg", "޸ʧ" + e.getMessage()); + return ResultMessageUtil.toJSON(returnJson); + } + } + + public int executeUpdate(List updateSqls) throws DbException { + if (updateSqls == null) { + return 0; + } + + int ret = 0; + PersistenceManager manager = null; + JdbcSession session = new JdbcSession(); + Connection connection = null; + try { + manager = PersistenceManager.getInstance(); + session = manager.getJdbcSession(); + connection = session.getConnection(); // ȡʵʵݿ + // Զύȷ + connection.setAutoCommit(false); + + try { + // ִ + // ִ + for (String sql : updateSqls) { + session.addBatch(sql); + } + ret = session.executeBatch(); + + // ȷвɹ֮ύ + connection.commit(); // ɹύ + connection.getAutoCommit(); + } catch (SQLException batchEx) { + // ִʱ쳣ع + connection.rollback(); + } + + } catch (DbException e) { + // DbExceptionִлع + if (connection != null) { + try { + connection.rollback(); // ع + } catch (SQLException rollbackEx) { + // ¼ع쳣ϸϢ + e.printStackTrace(); + } + } + e.printStackTrace(); // ߼¼־ + } catch (SQLException e) { + // SQLException 쳣Ĵ + if (connection != null) { + try { + connection.rollback(); // ع + } catch (SQLException rollbackEx) { + // ¼ع쳣ϸϢ + e.printStackTrace(); // ߼¼־ + } + } + e.printStackTrace(); // ߼¼־ + } finally { + if (connection != null) { + try { + // ָԶύģʽ + connection.setAutoCommit(true); + } catch (SQLException e) { + // ԻָԶύʱ쳣 + e.printStackTrace(); + } + } + if (manager != null) { + manager.release(); + } + } + + return ret; + } + + + // תMap + public static String checkRequiredFields(JSONObject data) throws Exception { + String returnStr = ""; + // 2. ֶ pk_org + String pkOrg = (String) data.getOrDefault("pk_org", ""); + if (pkOrg.isEmpty()) { + return "ֶpk_orgȱʧΪ!"; + } + // 3. ȡ array ֶ + Object array = data.getOrDefault("array", null); + if (array == null || !(array instanceof JSONArray) || ((JSONArray) array).isEmpty()) { + return "arrayΪջ򲻴!"; + } + ArrayList arrayList = new ArrayList<>(); + if (array instanceof JSONArray) { + JSONArray jsonArray = (JSONArray) array; + arrayList = new ArrayList<>(jsonArray.toJavaList(Object.class)); + } + // 5. ÿ󣬼ֶ + for (int i = 0; i < arrayList.size(); i++) { + Map item = (Map) arrayList.get(i); + // ֶ 'crowno' + if (item.getOrDefault("crowno", "").toString().isEmpty()) { + return " " + (i + 1) + " ȱٱֶcrowno!"; + } + // ֶ 'vbillcode' + if (item.getOrDefault("vbillcode", "").toString().isEmpty()) { + return " " + (i + 1) + " ȱٱֶvbillcode!"; + } + // ֶ 'sendQty' + if (item.getOrDefault("sendQty", "").toString().isEmpty()) { + return " " + (i + 1) + " ȱٱֶsendQty!"; + } + } + return returnStr; + } + + + /* + *ʱ䣺2024-11-28 + *ãѯ + *ֵ + *ֵmap + */ + private String getSaleorderBPK(String pk_org, String vbillcode, String crowno) throws BusinessException { + String sql = " select b.csaleorderbid from so_saleorder h \n" + + " left join so_saleorder_b b on h.csaleorderid=b.csaleorderid\n" + + " left join org_salesorg o on h.pk_org=o.pk_salesorg\n" + + " where h.dr=0 and b.dr=0 and\n" + + " h.vbillcode='" + vbillcode + "' and o.code='" + pk_org + "' and b.crowno='" + crowno + "' "; + String saleorderBPK = (String) getQueryService().executeQuery(sql, new ColumnProcessor()); + return saleorderBPK; + } + + /* + *ʱ䣺2024-11-28 + *ãѯ + *ֵ + *ֵmap + */ + private int updateSaleBSQty(String sql) throws BusinessException { + BaseDAO baseDAO = new BaseDAO(); + int succInt = baseDAO.executeUpdate(sql); + return succInt; + } + + public IUAPQueryBS getQueryService() { + return NCLocator.getInstance().lookup(IUAPQueryBS.class); + } + +} \ No newline at end of file diff --git a/so/src/public/nccloud/api/so/so/salepc/saleUpdateLJpc.java b/so/src/public/nccloud/api/so/so/salepc/saleUpdateLJpc.java new file mode 100644 index 0000000..139e3d8 --- /dev/null +++ b/so/src/public/nccloud/api/so/so/salepc/saleUpdateLJpc.java @@ -0,0 +1,265 @@ +package nccloud.api.so.so.salepc; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import nc.bs.dao.BaseDAO; +import nc.bs.framework.common.NCLocator; +import nc.itf.uap.IUAPQueryBS; +import nc.jdbc.framework.ConnectionFactory; +import nc.jdbc.framework.JdbcSession; +import nc.jdbc.framework.PersistenceManager; +import nc.jdbc.framework.exception.DbException; +import nc.jdbc.framework.processor.ColumnProcessor; +import nc.jdbc.framework.processor.MapListProcessor; +import nc.vo.pub.BusinessException; +import nccloud.api.rest.utils.ResultMessageUtil; +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.sql.Connection; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Path("so/so/salepc") +public class saleUpdateLJpc extends AbstractNCCRestResource { + @Override + public String getModule() { + return "so"; + } + // ڴ洢ֹάıֶκֶ˵ + private Map requiredFields; + // 췽ʼֶμ˵ + public saleUpdateLJpc() { + // ʼֶбֶ˵ + requiredFields = new HashMap<>(); + requiredFields.put("pk_org", "ҵԪ"); + requiredFields.put("array.vbillcode", "ݱ"); + requiredFields.put("array.crowno", "к"); + requiredFields.put("array.sendQty", ""); + } + + @POST + @Path("/saleUpdateLJpc") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString saleUpdateLJpc(JSONString json) { + JSONObject returnJson = new JSONObject(); + try { + JSONObject object = JSON.parseObject(json.toJSONString()); + if (object == null) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException("JSONString:null")); + } + // Уֶ + String tipsStr = checkRequiredFields(object); + if (!tipsStr.equals("")) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException(tipsStr)); + } + String pk_org = (String) object.getOrDefault("pk_org", ""); + Object obj = object.getOrDefault("array", ""); + ArrayList arrayList = new ArrayList<>(); + if (obj instanceof JSONArray) { + JSONArray jsonArray = (JSONArray) obj; + arrayList = new ArrayList<>(jsonArray.toJavaList(Object.class)); + } + +// StringBuilder sqlStr = new StringBuilder(); + List sqlStr = new ArrayList(); + for (int i = 0; i < arrayList.size(); i++) { + Map dataMap = (Map) arrayList.get(i); + + String sqlser="SELECT b.csaleorderid, b.vbdef6, b.vbdef12 " + + "FROM so_saleorder_b b " + + "LEFT JOIN so_saleorder h ON b.csaleorderid = h.csaleorderid " + + "LEFT JOIN org_salesorg o ON h.pk_org = o.pk_salesorg " + + "WHERE b.dr=0 and h.vbillcode = '" + dataMap.get("vbillcode") + "' " + + "AND o.code = '" + pk_org + "' " + + "AND b.crowno = '" + dataMap.get("crowno") + "'"; + List> results = (List>) getQueryService().executeQuery(sqlser, new MapListProcessor()); + if (results.size()==0){ + returnJson.put("state", 'N'); + returnJson.put("msg", "ʧ,"+dataMap.get("vbillcode")+"к:"+dataMap.get("crowno")+""); + return ResultMessageUtil.toJSON(returnJson); + } + if (dataMap.get("sendQty")!=null){ + sqlStr.add("UPDATE so_saleorder_b b " + + "SET b.vbdef6 = '1001A11000000C0W6P7S',b.vbdef12 = '"+dataMap.get("sendQty")+"'" + + "WHERE b.csaleorderid IN (" + + " SELECT h.csaleorderid" + + " FROM so_saleorder h" + + " LEFT JOIN org_salesorg o ON h.pk_org = o.pk_salesorg" + + " WHERE h.vbillcode = '" + dataMap.get("vbillcode") + "' " + + " AND o.code = '" + pk_org + "' " + + " AND b.crowno = '" + dataMap.get("crowno") + "' and b.dr=0 " + + ");"); + } + } + +// int succState = updateSaleBSQty(sqlStr.toString()); + int succState = executeUpdate(sqlStr); + + if (succState == arrayList.size()) { + returnJson.put("state", 'Y'); + returnJson.put("msg", "ɹ,޸"+succState+""); + + }else { + returnJson.put("state", 'N'); + returnJson.put("msg", "ʧ,޸"+succState+""); + } + return ResultMessageUtil.toJSON(returnJson); + } catch (DbException e) { + throw new RuntimeException(e); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** + * updateSqlsΪҪִеsql䡣Ӱ + */ + public int executeUpdate(List updateSqls) throws DbException { + if (updateSqls == null) { + return 0; + } + + int ret = 0; + PersistenceManager manager = null; + JdbcSession session = null; + Connection connection = null; + + try { + manager = PersistenceManager.getInstance(); + session = manager.getJdbcSession(); + connection = session.getConnection(); // ȡʵʵݿ +// connection = ConnectionFactory.getConnection(); + // ʼ + connection.setAutoCommit(false); // Զύֶ + + // ִ + for (String sql : updateSqls) { + session.addBatch(sql); + } + + // ִ + ret = session.executeBatch(); + + // ύ + connection.commit(); // ɹύ + + } catch (DbException e) { + if (connection != null) { + try { + // 쳣ع + connection.rollback(); + } catch (SQLException rollbackEx) { + // ¼ع쳣ϸϢ + throw new DbException("Error during transaction rollback", rollbackEx) { + @Override + public boolean isDataIntegrityViolation() { + return false; + } + + @Override + public boolean isBadSQLGrammar() { + return false; + } + }; + } + } + throw e; // ԭʼ쳣׳ + } catch (SQLException e) { + throw new RuntimeException(e); + } finally { + if (connection != null) { + try { + // ָԶύģʽȷӰ + connection.setAutoCommit(true); + } catch (SQLException e) { + // ԻָԶύʱ쳣 + } + } + if (manager != null) { + manager.release(); + } + } + + return ret; + } + + // תMap + public static String checkRequiredFields(JSONObject data) throws Exception { + String returnStr = ""; + // 2. ֶ pk_org + String pkOrg = (String) data.getOrDefault("pk_org", ""); + if (pkOrg.isEmpty()) { + return "ֶpk_orgȱʧΪ!"; + } + // 3. ȡ array ֶ + Object array = data.getOrDefault("array", null); + if (array == null || !(array instanceof JSONArray) || ((JSONArray) array).isEmpty()) { + return "arrayΪջ򲻴!"; + } + ArrayList arrayList = new ArrayList<>(); + if (array instanceof JSONArray) { + JSONArray jsonArray = (JSONArray) array; + arrayList = new ArrayList<>(jsonArray.toJavaList(Object.class)); + } + // 5. ÿ󣬼ֶ + for (int i = 0; i < arrayList.size(); i++) { + Map item = (Map) arrayList.get(i); + // ֶ 'crowno' + if (item.getOrDefault("crowno", "").toString().isEmpty()) { + return " " + (i + 1) + " ȱٱֶcrowno!"; + } + // ֶ 'vbillcode' + if (item.getOrDefault("vbillcode", "").toString().isEmpty()) { + return " " + (i + 1) + " ȱٱֶvbillcode!"; + } + // ֶ 'sendQty' + if (item.getOrDefault("sendQty", "").toString().isEmpty()) { + return " " + (i + 1) + " ȱٱֶsendQty!"; + } + } + return returnStr; + } + + + /* + *ʱ䣺2024-11-28 + *ãѯ + *ֵ + *ֵmap + */ + private String getSaleorderBPK(String pk_org, String vbillcode, String crowno) throws BusinessException { + String sql = " select b.csaleorderbid from so_saleorder h \n" + + "left join so_saleorder_b b on h.csaleorderid=b.csaleorderid\n" + + "left join org_salesorg o on h.pk_org=o.pk_salesorg\n" + + "where h.vbillcode='" + vbillcode + "' and o.code='" + pk_org + "' and b.crowno='" + crowno + "' "; + String saleorderBPK = (String) getQueryService().executeQuery(sql, new ColumnProcessor()); + return saleorderBPK; + } + + /* + *ʱ䣺2024-11-28 + *ãѯ + *ֵ + *ֵmap + */ + private int updateSaleBSQty(String sql) throws BusinessException { + BaseDAO baseDAO = new BaseDAO(); + int succInt = baseDAO.executeUpdate(sql); + return succInt; + } + + public IUAPQueryBS getQueryService() { + return NCLocator.getInstance().lookup(IUAPQueryBS.class); + } + +} \ No newline at end of file