2312销售订单排产、发货、bip删除相关补丁-张鑫0411

This commit is contained in:
zhangxinah@yonyou.com 2025-04-11 18:42:41 +08:00
parent e6836e42dc
commit 7a4aef3ff1
14 changed files with 1558 additions and 0 deletions

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding='gb2312'?>
<module>
<rest>
<resource classname="nccloud.api.so.so.UpCloses.ClosesoUpdateBL" exinfo="测试开启关闭推送"/>
</rest>
</module>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding='gb2312'?>
<module>
<rest>
<resource classname="nccloud.api.so.so.UpCdate.Updateinformer" exinfo="测试推送"/>
</rest>
</module>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding='gb2312'?>
<module>
<rest>
<resource classname="nccloud.api.so.so.saleorder.bipDelete" exinfo="根据销售订单号、业务单元删除销售订单 "/>
</rest>
</module>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding='gb2312'?>
<module>
<rest>
<resource classname="nccloud.api.so.so.saleorder.saleUpdateLJfh" exinfo="测试推送"/>
</rest>
</module>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding='gb2312'?>
<module>
<rest>
<resource classname="nccloud.api.so.so.salepc.saleUpdateLJpc" exinfo="21212"/>
</rest>
</module>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding='gb2312'?>
<module>
<rest>
<resource classname="nccloud.openapi.so.m30.SaleOrderResource" exinfo="销售订单接口"/>
<resource classname="nccloud.api.so.saleinvoice.operator.saveCommitAction" exinfo="销售发票接口"/>
</rest>
</module>

9
so/META-INF/sobill.rest Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="gb2312"?>
<module>
<rest>
<resource classname="nccloud.openapi.so.m30.SaleOrderResource" exinfo=""/>
</rest>
<rest>
<resource classname="nccloud.openapi.so.m4331.DeliveryResource" exinfo=""/>
</rest>
</module>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding='gb2312'?>
<module>
<rest>
<resource classname="nccloud.api.so.so.saleorder.saleUpdateSQty" exinfo="根据销售订单号、行号、业务单元反写到销售订单明细的发货数量 "/>
</rest>
</module>

View File

@ -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<String, String> 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<String> 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<String> results = (ArrayList<String>) getQueryService().executeQuery(sqlser, new ArrayListProcessor());
List<Map<String,String>> results = (List<Map<String, String>>) 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<String> 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<Object> 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<String> 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);
}
}

View File

@ -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<String, String> 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<String> vbillcodes = new HashSet<>();
// 创建map 9-冻结 10-办结 11-终止 8生效(取消冻结)
Map<String, String> operationMap = new HashMap<>();
try {
ArrayList<String> 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<Object[]> result = (List<Object[]>) 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取csaleorderbid与ts生成"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<PickmDeleteInfo> 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<Object[]> vresult = (List<Object[]>) 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());
// 如果操作成功设置错误JSON对象的code为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<String, UFDateTime> 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<AggPickmVO> 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<String, UFDateTime> 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);
}
}

View File

@ -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);
}
}

View File

@ -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<String, String> 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<String> 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);
}
}

View File

@ -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<String, String> 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<String> 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);
}
}

View File

@ -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<String, String> 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<Map<String, Object>> results = (List<Map<String, Object>>) 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<String> 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);
}
}