U8接口业务新增

This commit is contained in:
yuqh 2025-03-19 09:54:38 +08:00
parent 7de3720668
commit d189458a82
17 changed files with 1593 additions and 14 deletions

View File

@ -70,8 +70,17 @@ public class MasterDataServiceImpl extends BaseService<ComparisonEntity, String>
// 向前偏移两分钟
calendar.add(Calendar.MINUTE, -2);
Date twoMinutesAgo = calendar.getTime();
// 创建 Calendar 实例
Date now1 = json.getDate("endTime");
Calendar calendar1 = Calendar.getInstance();
calendar1.setTime(now1);
// 向前偏移两分钟
calendar1.add(Calendar.MINUTE, 2);
Date twoMinutesAgo1 = calendar1.getTime();
String startTime = DateUtil.format(twoMinutesAgo,"yyyy-MM-dd HH:mm:ss");//定时任务执行时传入的开始时间
String endTime = DateUtil.format(json.getDate("endTime"),"yyyy-MM-dd HH:mm:ss");//定时任务执行时传入的结束时间
String endTime = DateUtil.format(twoMinutesAgo1,"yyyy-MM-dd HH:mm:ss");//定时任务执行时传入的结束时间
// logger.info("本次任务查询区间开始时间:{} 结束时间:{}",startTime,endTime);
String tableName = "";
try {
@ -154,7 +163,7 @@ public class MasterDataServiceImpl extends BaseService<ComparisonEntity, String>
}else{
// ts = DateUtil.dateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
sb.append(" and a.dModifyDate >= '"+startTime+"'");
sb.append(" and a.dModifyDate <> '"+endTime+"'");
sb.append(" and a.dModifyDate <= '"+endTime+"'");
}
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("select * from v_hzya_Customer a WHERE 1=1 " +sb.toString());
@ -199,7 +208,7 @@ public class MasterDataServiceImpl extends BaseService<ComparisonEntity, String>
}else{
// ts = DateUtil.dateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
sb.append(" and a.dModifyDate >= '"+startTime+"'");
sb.append(" and a.dModifyDate <> '"+endTime+"'");
sb.append(" and a.dModifyDate <= '"+endTime+"'");
}
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("select * from v_hzya_Warehouse a where 1=1 " +sb.toString());
@ -230,7 +239,7 @@ public class MasterDataServiceImpl extends BaseService<ComparisonEntity, String>
}else{
// ts = DateUtil.dateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
sb.append(" and a.dModifyDate >= '"+startTime+"'");
sb.append(" and a.dModifyDate <> '"+endTime+"'");
sb.append(" and a.dModifyDate <= '"+endTime+"'");
}
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("select * from v_hzya_Inventory a where 1=1 " +sb.toString());

View File

@ -46,4 +46,22 @@ public interface IDeliveryOrderService extends IBaseService<DeliveryOrderEntity,
*
*/
U8ResultEntity Close(JSONObject parm);
/**
*
* @content 发货单-部分作废
* @className: Administrator
* @author laborer
* @date 2025-02-24 14:33
*
*/
U8ResultEntity ClosePartial(JSONObject parm);
/**
*
* @content 发货单-是否出库查询
* @className: Administrator
* @author laborer
* @date 2025-02-24 14:33
*
*/
U8ResultEntity GetOutQuantity(JSONObject parm);
}

View File

@ -14,11 +14,13 @@ import com.hzya.frame.u8.delivery.entity.DeliveryOrderEntity;
import com.hzya.frame.u8.delivery.service.IDeliveryOrderService;
import com.hzya.frame.u8.saleinv.dao.ISaleInvDao;
import com.hzya.frame.u8.saleinv.entity.SaleInvEntity;
import com.hzya.frame.u8.saleout.service.ISaleOutService;
import com.hzya.frame.u8.util.BaseU8Result;
import com.hzya.frame.u8.util.U8ResultEntity;
import com.hzya.frame.u8.util.U8Util;
import com.hzya.frame.web.entity.BaseResult;
import com.hzya.frame.web.entity.JsonResultEntity;
import lombok.val;
import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -40,6 +42,7 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrderEntity,St
@Autowired
private ISaleInvDao saleInvDao;
private IDeliveryOrderDao deliveryOrderDao;
private ISaleOutService saleOutServiceImpl;
@Autowired
public void setDeliveryOrderDao(IDeliveryOrderDao dao) {
@ -128,6 +131,10 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrderEntity,St
return BaseU8Result.getFailureMessageEntity("请传入第三方唯一标识");
}
AccId = jsonObject.getString("AccId");
String cmemo = jsonObject.getString("cmemo");
if(cmemo.length()>255){
jsonObject.put("cmemo", cmemo.substring(0,254));
}
if(StrUtil.isEmpty(AccId)){
return BaseU8Result.getFailureMessageEntity("请传入正确的账套号");
}
@ -224,6 +231,8 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrderEntity,St
if(CollectionUtils.isNotEmpty(hashMaps)){
return BaseU8Result.getFailureMessageEntity("发货通知单号已存在!对应发货单号为:"+jHead.getString("cdefine10"));
}
//todo 发货单表体
JSONArray body = new JSONArray();
JSONArray jBody = jsonObject.getJSONArray("body");
@ -525,8 +534,9 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrderEntity,St
return BaseU8Result.getFailureMessageEntity("关闭人不能为空");
}
//判断当前单据是否审核
String sqlIsAudit = "select DLID,cVerifier from DispatchList where cDLCode = '"+cdlcode+"'";
String sqlIsAudit = "select DLID,cVerifier from "+AccCode+".dbo.DispatchList where cDLCode = '"+cdlcode+"'";
SaleInvEntity erdt = new SaleInvEntity();
erdt.setDataSourceCode("YONYOUU8NEW");
List<HashMap<String, Object>> dlMap = saleInvDao.getU8BillData(sqlIsAudit,erdt);
if(CollectionUtils.isEmpty(dlMap)){
return BaseU8Result.getFailureMessageEntity("单据不存在::"+cdlcode);
@ -536,7 +546,24 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrderEntity,St
if(StrUtil.isEmpty(cVerifier)){
return BaseU8Result.getFailureMessageEntity("未审核不允许关闭:"+cdlcode);
}
//验证书库数量
//验证出库数量
String sqlSaleOutQty = "select cDLCode,ISNULL(iQuantity,0) as 'iQuantity',ISNULL(rs32.saleOutQty,0) as 'saleOutQty' " +
"from "+AccCode+".dbo.DispatchList dl " +
"left join "+AccCode+".dbo.DispatchLists dls on dls.DLID = dl.DLID " +
"left join ( select iDLsID,SUM(iQuantity) as 'saleOutQty' "+AccCode+".dbo.from rdrecords32 group by iDLsID )rs32 on rs32.iDLsID = dls.iDLsID " +
"where dl.cDLCode = '"+cdlcode+"'";
List<HashMap<String, Object>> saleOutQtyMap = saleInvDao.getU8BillData(sqlSaleOutQty,erdt);
if(CollectionUtils.isEmpty(saleOutQtyMap)){
return BaseU8Result.getFailureMessageEntity("关闭失败,原因:校验发货单"+cdlcode+"出库数量失败:::");
}
JSONObject dt1 = new JSONObject(saleOutQtyMap.get(0));
if(dt1.getDouble("saleOutQty")>0){
return BaseU8Result.getFailureMessageEntity("关闭失败,原因:发货单"+cdlcode+"已有部分出库,不能整单关闭!");
}
String updateMain = "update "+AccCode+".dbo.DispatchList set cCloser = '"+ccloser+"', bSettleAll = 1 where cDLCode = '"+cdlcode+"'";
String updatebody = "update "+AccCode+".dbo.Dispatchlists set cSCloser = '"+ccloser+"',bSettleAll = 1 where DLID = '"+dt.getString("DLID")+"'";
saleInvDao.execUpdateSql(updateMain,erdt);
saleInvDao.execUpdateSql(updatebody,erdt);
} catch (Exception e) {
logger.info("关闭失败:"+e.getMessage());
return BaseU8Result.getFailureMessageEntity("关闭失败请联系U8管理员");
@ -544,5 +571,834 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrderEntity,St
return null;
}
@Override
public U8ResultEntity ClosePartial(JSONObject parm) {
String billCode = "";
String dlId = "";
String AccId = "";
try {
JSONObject jsonObject = parm.getJSONObject("jsonStr");
logger.info("接收到的参数"+jsonObject.toString());
StringBuffer resultStr = new StringBuffer();//回传json
String billid = jsonObject.getString("billid");
if(StrUtil.isEmpty(billid)){
return BaseU8Result.getFailureMessageEntity("请传入第三方唯一标识");
}
AccId = jsonObject.getString("AccId");
if(StrUtil.isEmpty(AccId)){
return BaseU8Result.getFailureMessageEntity("请传入正确的账套号");
}
String AccCode = U8Util.accMap.get(AccId);
if(StrUtil.isEmpty(AccCode)){
return BaseU8Result.getFailureMessageEntity("请传入正确的账套号");
}
JSONObject jHead = jsonObject.getJSONObject("head");
String cdlcode = jHead.getString("cdlcode");
if(StrUtil.isEmpty(cdlcode)){
return BaseU8Result.getFailureMessageEntity("发货单号不能为空");
}
String ccloser = jHead.getString("ccloser");
if(StrUtil.isEmpty(ccloser)){
return BaseU8Result.getFailureMessageEntity("关闭人不能为空");
}
JSONArray jBody = jsonObject.getJSONArray("body");
SaleInvEntity erdt = new SaleInvEntity();
erdt.setDataSourceCode("YONYOUU8NEW");
if(StrUtil.isEmpty(cdlcode)){
return BaseU8Result.getFailureMessageEntity("发货单号不能为空");
}
if(StrUtil.isEmpty(ccloser)){
return BaseU8Result.getFailureMessageEntity("关闭人不能为空");
}
for (int i = 0; i < jBody.size(); i++){
// JSONObject jBodyObj = jBody.getJSONObject(i);
String[] MustInputCodes = new String[] { "irowno", "iquantity","inum" };
String[] MustInputNames = new String[] { "发货单行号", "数量","辅计量数量" };
for (int j = 0; j < MustInputCodes.length; j++){
if (StrUtil.isEmpty(MustInputCodes[j])){
resultStr.append("请输入:" + MustInputCodes[j] + "(" + MustInputNames[j] + "),错误行:" + (i + 1)) ;
}
}
}
//如果有错误信息则返回错误信息
if(StrUtil.isNotEmpty(resultStr.toString())){
return BaseU8Result.getSuccessMessageEntity(resultStr.toString());
}
//判断当前单据是否审核
String sqlIsAudit = "select * from "+AccCode+".dbo.DispatchList where cDLCode = '"+cdlcode+"'";
List<HashMap<String, Object>> dlMap = saleInvDao.getU8BillData(sqlIsAudit,erdt);
if(CollectionUtils.isEmpty(dlMap)){
return BaseU8Result.getFailureMessageEntity("单据不存在::"+cdlcode);
}
HashMap<String, Object> dt = dlMap.get(0);
String cVerifier = String.valueOf(dt.get("cVerifier"));
if(StrUtil.isEmpty(cVerifier)){
return BaseU8Result.getFailureMessageEntity("未审核不允许关闭:"+cdlcode);
}
String sqlSaleOutQty = " select cDLCode,irowno,ISNULL(iQuantity,0) as 'iQuantity',ISNULL(rs32.saleOutQty,0) as 'saleOutQty',ISNULL(iQuantity,0) - ISNULL(rs32.saleOutQty,0) as 'qty' " +
"from "+AccCode+".dbo.DispatchList dl " +
"left join "+AccCode+".dbo.DispatchLists dls on dls.DLID = dl.DLID " +
"left join ( select iDLsID,SUM(iQuantity) as 'saleOutQty' from "+AccCode+".dbo.rdrecords32 group by iDLsID )rs32 on rs32.iDLsID = dls.iDLsID " +
"where dl.cDLCode = '"+cdlcode+"' ";
List<HashMap<String, Object>> saleOutQtyMap = saleInvDao.getU8BillData(sqlSaleOutQty,erdt);
if(CollectionUtils.isEmpty(saleOutQtyMap)){
return BaseU8Result.getFailureMessageEntity("关闭失败,原因:校验发货单"+cdlcode+"出库数量失败:");
}
//校验发货单作废数量不能超过剩余出库数量
jBody.forEach(obj -> {
JSONObject d = (JSONObject) obj;
String irowno = d.getString("irowno");
for(int i = 0; i < saleOutQtyMap.size(); i++) {
HashMap<String, Object> selDis= saleOutQtyMap.get(0);;
String soRowNo = String.valueOf(selDis.get("irowno"));
if (irowno.equals(soRowNo)) {
BigDecimal qty = new BigDecimal(String.valueOf(selDis.get("qty")));
if(qty.compareTo(d.getBigDecimal("iquantity")) <0){
resultStr .append("关闭失败,原因:发货单"+cdlcode+""+soRowNo+"本次作废数量超出剩余出库数量"+qty+"") ;
}
}
}
});
//如果有错误信息则返回错误信息
if(StrUtil.isNotEmpty(resultStr.toString())){
return BaseU8Result.getSuccessMessageEntity(resultStr.toString());
}
//todo 处理销售出库单
JSONObject saleOutJSON = GetSaleOutJSON(AccCode,jHead,jBody,String.valueOf(dt.get("DLID")),erdt);
//创建销售出库单
U8ResultEntity resultEntity = saleOutServiceImpl.addSaleOut(saleOutJSON);
if(!resultEntity.issuccess()){
return BaseU8Result.getFailureMessageEntity(resultEntity.getmessage());
}
JSONObject rtn = GetDelJSON(AccCode,resultEntity.getmessage(),resultEntity.getmessage(),1);
//todo 处理销售退货单
JSONObject retnJSON = new JSONObject();
try {
retnJSON = GetDLRedJSON(AccCode,jHead,jBody,String.valueOf(dt.get("DLID")),erdt);
} catch (Exception e) {
//组装参数失败需要删除销售出库单
//删除销售出库单
U8ResultEntity resultDelete = saleOutServiceImpl.deleteSaleOut(rtn);
boolean deleteFlag =resultDelete.issuccess();
throw new RuntimeException(e);
}
//创建红字发货单
U8ResultEntity resultAddRed = AddRed(retnJSON);
if(!resultAddRed.issuccess()){
//如果创建红字发货单失败还是要回滚销售出库单
U8ResultEntity resultDelete = saleOutServiceImpl.deleteSaleOut(rtn);
boolean deleteFlag =resultDelete.issuccess();
if(resultDelete.issuccess()){
return BaseU8Result.getFailureMessageEntity("回滚销售出库单删除失败:"+resultDelete.getmessage());
}
return BaseU8Result.getFailureMessageEntity("红字发货单制单失败!原因:"+resultAddRed.getmessage());
}
//创建红字销售出库
try {
JSONObject saleOutRed = GetSaleOutRedJSON(resultAddRed.getmessage(),AccId,AccCode,erdt);
} catch (Exception e) {
//获取json失败需要删除销售出库和红字销售发货
//删除销售出库单
try {
rtn = GetDelJSON(AccCode,resultEntity.getmessage(),resultEntity.getmessage(),1);
U8ResultEntity resultDelete = saleOutServiceImpl.deleteSaleOut(rtn);
boolean deleteFlag =resultDelete.issuccess();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
//删除红字销售发货单
try {
rtn = GetDelJSON(AccCode,resultAddRed.getmessage(),resultEntity.getmessage(),1);
U8ResultEntity resultDelete = saleOutServiceImpl.deleteSaleOut(rtn);
boolean deleteFlag =resultDelete.issuccess();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
throw new RuntimeException(e);
}
//开始创建红字销售出库
U8ResultEntity resultAdd = saleOutServiceImpl.Add_DLPartialClose(retnJSON);
if(!resultAdd.issuccess()){
//删除销售出库单
try {
rtn = GetDelJSON(AccCode,resultEntity.getmessage(),resultEntity.getmessage(),1);
U8ResultEntity resultDelete = saleOutServiceImpl.deleteSaleOut(rtn);
boolean deleteFlag =resultDelete.issuccess();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
//删除红字销售发货单
try {
rtn = GetDelJSON(AccCode,resultAddRed.getmessage(),resultEntity.getmessage(),1);
U8ResultEntity resultDelete = saleOutServiceImpl.deleteSaleOut(rtn);
boolean deleteFlag =resultDelete.issuccess();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
//作废后下发给WMS一条数量为0的数据
String querySql = "select " +
"ERP_NO,LIST_KIND,RCV_SEND_KIND,IO,CUST_NO,PROD_ID, " +
"CONVERT(FLOAT,( " +
" case " +
" when bReturnFlag = 0 then (case when ISNULL(num,0) = 0 then ISNULL(qty,0) else ISNULL(num,0) end) " +
" when bReturnFlag = 1 then (case when ISNULL(-num,0) = 0 then ISNULL(-qty,0) else ISNULL(-num,0) end) " +
" end) " +
" ) as 'QTY', " +
" PALLET_QTY, " +
" CREATION_DATE " +
" from " +
" ( " +
" select " +
" dl.cDLCode as 'ERP_NO' " +
" ,case when bReturnFlag = 0 then '销售出库' when bReturnFlag = 1 then '销售退货' end as 'LIST_KIND' " +
" ,'201' as 'RCV_SEND_KIND' " +
" ,case when bReturnFlag = 0 then 'O' when bReturnFlag = 1 then 'I' end as 'IO' " +
" ,dl.cCusCode as 'CUST_NO' " +
" ,dls.cInvCode as 'PROD_ID' " +
" --,0 as 'QTY' " +
" ,0 as 'PALLET_QTY' " +
" ,GETDATE() as 'CREATION_DATE' " +
" ,bReturnFlag " +
" ,ISNULL(iQuantity,0) - ISNULL(rs32.saleOutQty,0) as 'qty', " +
" ISNULL(iNum,0) - ISNULL(rs32.saleOutNum,0) as 'num' " +
" from "+AccCode+".dbo.DispatchList dl " +
" left join DispatchLists dls on dls.DLID = dl.DLID " +
" left join " +
" ( " +
" select " +
" iDLsID,SUM(iQuantity) as 'saleOutQty',SUM(ISNULL(iNum,0)) as 'saleOutNum' " +
" from "+AccCode+".dbo.rdrecords32 " +
" group by iDLsID " +
" )rs32 on rs32.iDLsID = dls.iDLsID " +
" where dl.cDLCode = '"+cdlcode+"' and ISNULL(dls.iQuantity,0) != 0 " +
" )a ";
List<HashMap<String, Object>> dlsMap = saleInvDao.getU8BillData(querySql,erdt);
if(CollectionUtils.isEmpty(dlsMap)){
logger.info("单据不存在不写入WMS中间表"+cdlcode);
}
dlsMap.forEach(item->{
try {
String insSql = "" +
"INSERT INTO [WMS].[dbo].[EW_IO_LIST] (" +
"[ERP_NO]," +
" [LIST_KIND]," +
" [RCV_SEND_KIND]," +
"[IO]," +
" [CUST_NO]," +
" [PROD_ID]," +
" [QTY]," +
" [RES_CODE]," +
" [CREATION_DATE]," +
" [PALLET_QTY]" +
") VALUES (" +
" '"+item.get("ERP_NO")+"'," +
" '"+item.get("LIST_KIND")+"'," +
" '"+item.get("RCV_SEND_KIND")+"'," +
" '"+item.get("IO")+"', " +
" '"+item.get("CUST_NO")+"'," +
" '"+item.get("PROD_ID")+"'," +
" '"+item.get("QTY")+"'," +
" '"+item.get("RES_CODE")+"'," +
" '"+item.get("CREATION_DATE")+"'," +
" '"+item.get("PALLET_QTY")+"');";
SaleInvEntity wmsErdt = new SaleInvEntity();
wmsErdt.setDataSourceCode("WMS");
logger.info("写入WMS中间表"+saleInvDao.execInsertSql(insSql,wmsErdt));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
});
}
} catch (Exception e) {
logger.info("部分作废:"+e.getMessage());
return BaseU8Result.getFailureMessageEntity("部分作废失败请联系U8管理员");
}
return null;
}
@Override
public U8ResultEntity GetOutQuantity(JSONObject parm) {
String billCode = "";
String dlId = "";
String AccId = "";
try {
JSONObject jsonObject = parm.getJSONObject("jsonStr");
logger.info("接收到的参数"+jsonObject.toString());
StringBuffer resultStr = new StringBuffer();//回传json
String billid = jsonObject.getString("billid");
if(StrUtil.isEmpty(billid)){
return BaseU8Result.getFailureMessageEntity("请传入第三方唯一标识");
}
AccId = jsonObject.getString("AccId");
if(StrUtil.isEmpty(AccId)){
return BaseU8Result.getFailureMessageEntity("请传入正确的账套号");
}
String AccCode = U8Util.accMap.get(AccId);
if(StrUtil.isEmpty(AccCode)){
return BaseU8Result.getFailureMessageEntity("请传入正确的账套号");
}
String cdlcode = jsonObject.getString("cdlcode");
if(StrUtil.isEmpty(cdlcode)){
return BaseU8Result.getFailureMessageEntity("发货单号不能为空");
}
SaleInvEntity erdt = new SaleInvEntity();
erdt.setDataSourceCode("YONYOUU8NEW");
//验证出库数量
String sqlSaleOutQty = " select cDLCode,cInvCode,cInvName,dls.irowno,dls.iQuantity,dls.iNum, r32.cCode, ISNULL(r32.iQuantity,0) as 'iOutQuantity', " +
"ISNULL(r32.iNum,0) as 'iOutNum' from "+AccCode+".DispatchList dl " +
"left join "+AccCode+".DispatchLists dls on dls.DLID = dl.DLID " +
"left join ( select cCode,iDLsID,SUM(iQuantity) as 'iQuantity',SUM(iNum) as 'iNum' " +
"from "+AccCode+".rdrecord32 a " +
"left join "+AccCode+".rdrecords32 b on b.ID = a.ID " +
"where cSource = '发货单' group by cCode,iDLsID )r32 on r32.iDLsID = dls.iDLsID " +
"where cDLCode = '"+cdlcode+"' " +
"order by irowno";
List<HashMap<String, Object>> saleOutQtyMap = saleInvDao.getU8BillData(sqlSaleOutQty,erdt);
if(CollectionUtils.isEmpty(saleOutQtyMap)){
return BaseU8Result.getFailureMessageEntity("查询失败:"+cdlcode+"");
}
BaseU8Result.getSuccessMessageEntity(saleOutQtyMap);
} catch (Exception e) {
logger.info("查询失败:"+e.getMessage());
return BaseU8Result.getFailureMessageEntity("查询失败请联系U8管理员");
}
return null;
}
/// <summary>
/// 发货单部分作废-获取红字销售出库单制单JSON
/// </summary>
/// <param name="_U8db"></param>
/// <param name="ID"></param>
/// <param name="AccId"></param>
/// <param name="bReturnFlag"></param>
/// <returns></returns>
public JSONObject GetSaleOutRedJSON( String dlid, String AccId,String AccCode, SaleInvEntity erdt)throws Exception{
JSONObject json = new JSONObject();
JSONObject head = new JSONObject();
JSONArray body = new JSONArray();
json.put("Token", "Hzya1314_CheckSkip");
json.put("billid", "123");
json.put("AccId", AccId);
//表头
String sqlHead = " select 0 as 'brdflag' ,'32' as 'cvouchtype' ,'普通销售' as 'cbustype' ,'发货单' as 'csource' ,cdlcode as 'cbuscode' ,convert(nvarchar,ddate,23) as 'ddate'" +
",'203' as 'crdcode' ,cDepCode as 'cdepcode' ,cSTCode as 'cstcode' ,cCusCode as 'ccuscode' ,DLID as 'cdlcode' ,87 as 'vt_id' ,DLID as 'dlid' " +
",cmaker ,breturnflag as 'bredvouch' ,cMemo as 'cmemo' " +
"from "+AccCode+".dbo.DispatchList " +
"where DLID = '"+dlid+"' ";
List<HashMap<String, Object>> dlMap = saleInvDao.getU8BillData(sqlHead,erdt);
if(CollectionUtils.isEmpty(dlMap)){
throw new Exception("发货单部分作废-获取红字销售出库单制单JSON-获取表头数据失败"+dlid);
}
head.putAll(dlMap.get(0));
//表体
String sqlBody = " select cinvcode ,iquantity ,inum ,cunitid as 'cAssUnit' ,'03002' as cWhcode ,cBatch ,iDLsID as 'idlsid' " +
",'"+head.getString("cdlcode")+"' as 'cbdlcode' " +
"from DispatchLists " +
"where DLID = '"+dlid+"' and ISNULL(iquantity,0) != 0";
List<HashMap<String, Object>> dlsMap = saleInvDao.getU8BillData(sqlHead,erdt);
if(CollectionUtils.isEmpty(dlsMap)){
throw new Exception("发货单部分作废-获取红字销售出库单制单JSON-获取表体数据失败"+dlid);
}
head.put("cwhcode",dlsMap.get(0).get("cwhcode"));
body.addAll(dlsMap);
json.put("body", body);
json.put("head", head);
return json;
}
/**
*
* @content 获取删除JSON
* @className: Administrator
* @author laborer
* @date 2025-03-18 16:11
*
*/
public JSONObject GetDelJSON(String AccId, String ID, String cCode, int isUnAudit)
{
JSONObject json = new JSONObject();
json.put("Token", "Hzya1314_CheckSkip");
json.put("billid", cCode);
json.put("AccId", AccId);
json.put("cVoucherId", ID);
json.put("isUnAudit", isUnAudit);
return json;
}
/**
*
* @content 发货单部分作废-红字发货单-新增
* @className: Administrator
* @author laborer
* @date 2025-03-18 15:54
*
*/
private U8ResultEntity AddRed(JSONObject parm){
String billCode = "";
String dlId = "";
String AccId = "";
try {
JSONObject jsonObject = parm.getJSONObject("jsonStr");
logger.info("接收到的参数"+jsonObject.toString());
StringBuffer resultStr = new StringBuffer();//回传json
String billid = jsonObject.getString("billid");
if(StrUtil.isEmpty(billid)){
return BaseU8Result.getFailureMessageEntity("请传入第三方唯一标识");
}
AccId = jsonObject.getString("AccId");
if(StrUtil.isEmpty(AccId)){
return BaseU8Result.getFailureMessageEntity("请传入正确的账套号");
}
String AccCode = U8Util.accMap.get(AccId);
if(StrUtil.isEmpty(AccCode)){
return BaseU8Result.getFailureMessageEntity("请传入正确的账套号");
}
//表头
JSONObject jHead = jsonObject.getJSONObject("head");
//业务类型
String cbustype = jHead.getString("cbustype");
if(StrUtil.isEmpty(cbustype)){
jHead.put("cbustype","普通销售");
}
//销售类型
String cvouchtype = jHead.getString("cvouchtype");
if(StrUtil.isEmpty(cvouchtype)){
jHead.put("cvouchtype","05");
}
//日期
String ddate = jHead.getString("ddate");
if(StrUtil.isEmpty(ddate)){
jHead.put("ddate", DateUtil.format(new Date(),"yyyy-MM-dd"));
}
//单据模版号
String ivtid = jHead.getString("ivtid");
if(StrUtil.isEmpty(ivtid)){
jHead.put("ivtid","71");
}
//税率
String itaxrate = jHead.getString("itaxrate");
if(StrUtil.isEmpty(itaxrate)){
jHead.put("itaxrate","13");
}
//汇率
String iexchrate = jHead.getString("iexchrate");
if(StrUtil.isEmpty(iexchrate)){
jHead.put("iexchrate","1");
}
//币种
String cexch_name = jHead.getString("cexch_name");
if(StrUtil.isEmpty(cexch_name)){
jHead.put("cexch_name","人民币");
}
//是否立账单据 bcredit 0
String bcredit = jHead.getString("bcredit");
if(StrUtil.isEmpty(bcredit)){
jHead.put("bcredit","0");
}
//流程id iflowid 0
String iflowid = jHead.getString("iflowid");
if(StrUtil.isEmpty(iflowid)){
jHead.put("iflowid","0");
}
//签回损失生成 bsigncreate 0
String bsigncreate = jHead.getString("bsigncreate");
if(StrUtil.isEmpty(bsigncreate)){
jHead.put("bsigncreate","0");
}
//现款结算 bcashsale
String bcashsale = jHead.getString("bcashsale");
if(StrUtil.isEmpty(bcashsale)){
jHead.put("bcashsale","0");
}
//必有定金 bmustbook 0
String bmustbook = jHead.getString("bmustbook");
if(StrUtil.isEmpty(bmustbook)){
jHead.put("bmustbook","0");
}
//存货选项切换 baccswitchflag 0
String baccswitchflag = jHead.getString("baccswitchflag");
if(StrUtil.isEmpty(baccswitchflag)){
jHead.put("baccswitchflag","0");
}
//todo 发货单表头必输项
String[] MustInputCode = new String[] { "cvouchtype", "cstcode", "ddate", "breturnflag", "cdepcode" };
String[] MustInputName = new String[] { "单据类型编码", "销售类型编码 ", "单据日期", "退货标识0发货1退货", "部门编码" };
//根据当前单据类型 所需参数判断是否传入该参数没有传入
for (int i = 0; i < MustInputCode.length; i++)
{
if (StrUtil.isEmpty(jHead.getString(MustInputCode[i]))) {
resultStr.append("请输入:" + MustInputCode[i] + "(" + MustInputName[i] + ")") ;
}
}
//如果有错误信息则返回错误信息
if(StrUtil.isNotEmpty(resultStr.toString())){
return BaseU8Result.getFailureMessageEntity(resultStr.toString());
}
//表体
//todo 发货单表体
JSONArray body = new JSONArray();
JSONArray jBody = jsonObject.getJSONArray("body");
for (int i = 0; i < jBody.size(); i++) {
JSONObject jBodyObj = jBody.getJSONObject(i);
//验证数据如果为空则返回报错信息
String[] MustInputCodes = new String[] { "iquantity", "cinvcode" };
String[] MustInputNames = new String[] { "数量", "存货编码"};
for (int j = 0; j < MustInputCodes.length; j++){
if (StrUtil.isEmpty(MustInputCodes[j])){
resultStr.append("请输入:" + MustInputCodes[j] + "(" + MustInputNames[j] + "),错误行:" + (i + 1)) ;
}
}
//获取计量单位组信息
String sqlUnit = "select b.cInvCName,a.* from "+AccCode+".dbo.Inventory a left join "+AccCode+".dbo.InventoryClass b on b.cInvCCode = a.cInvCCode " +
"where cInvCode='"+jBodyObj.getString("cinvcode")+"'";
SaleInvEntity U8Body = new SaleInvEntity();
U8Body.setDataSourceCode("YONYOUU8NEW");
List<HashMap<String, Object>> U8BodyHashMaps = saleInvDao.getU8BillData(sqlUnit,U8Body);
if(CollectionUtils.isEmpty(U8BodyHashMaps)){
resultStr.append("存货编码不存在[" + jBodyObj.getString("cinvcode")+ "],行:"+i + 1+"" );
}
//存货信息
HashMap<String, Object> inv= U8BodyHashMaps.get(0);
//必须传下面参数不然CO会报错
jBodyObj.put("cgroupcode",inv.get("cGroupCode"));
jBodyObj.put("igrouptype",inv.get("iGroupType"));
jBodyObj.put("ccomunitcode",inv.get("cComUnitCode"));
//默认项 在第三方调用不传输数据情况下 则默认以下数据
// 买赠类型
String cdefine22 = jBodyObj.getString("cdefine22");
if(StrUtil.isEmpty(cdefine22)){
jBodyObj.put("cdefine22","正常");
}
//累计出库数量 (似乎有这个bug不传这个参数累计出库数量会和发货数量一致导致发货单关闭反正加上没坏处)
jBodyObj.put("fOutQuantity","0.00");
//工厂编码
jBodyObj.put("cfactorycode","001");
//退补数量 tbquantity
String tbquantity = jBodyObj.getString("tbquantity");
if(StrUtil.isEmpty(tbquantity)){
jBodyObj.put("tbquantity","0");
}
//零售单价 fsalecost
String fsalecost = jBodyObj.getString("fsalecost");
if(StrUtil.isEmpty(fsalecost)){
jBodyObj.put("fsalecost","0");
}
//零售金额 fsaleprice
String fsaleprice = jBodyObj.getString("fsaleprice");
if(StrUtil.isEmpty(fsaleprice)){
jBodyObj.put("fsaleprice","0");
}
//客户最低售价 fcusminprice
String fcusminprice = jBodyObj.getString("fcusminprice");
if(StrUtil.isEmpty(fcusminprice)){
jBodyObj.put("fcusminprice","0");
}
//有效期推算方式 iexpiratdatecalcu
String iexpiratdatecalcu = jBodyObj.getString("iexpiratdatecalcu");
if(StrUtil.isEmpty(iexpiratdatecalcu)){
jBodyObj.put("iexpiratdatecalcu","0");
}
//需要签回 bneedsign
String bneedsign = jBodyObj.getString("bneedsign");
if(StrUtil.isEmpty(bneedsign)){
jBodyObj.put("bneedsign","0");
}
//报价含税标识 bsaleprice
String bsaleprice = jBodyObj.getString("bsaleprice");
if(StrUtil.isEmpty(bsaleprice)){
jBodyObj.put("bsaleprice","1");
}
//是否赠品 bgift
String bgift = jBodyObj.getString("bgift");
if(StrUtil.isEmpty(bgift)){
jBodyObj.put("bgift","0");
}
//行号 irowno
jBodyObj.put("irowno",i+1);
// 金额计算
//原币折扣金额
BigDecimal idiscount = StrUtil.isNotEmpty(jBodyObj.getString("idiscount")) ? jBodyObj.getBigDecimal("idiscount") : new BigDecimal(0);
BigDecimal iquantity = jBodyObj.getBigDecimal("iquantity");//数量
BigDecimal isum = jBodyObj.getBigDecimal("isum");//价税合计
BigDecimal itaxrate_b = jBodyObj.getBigDecimal("itaxrate");//税率
BigDecimal nflat = jHead.getBigDecimal("iexchrate");//汇率
BigDecimal iTaxUnitPrice = isum.divide(iquantity,6); //原币含税单价
JSONObject ae = new JSONObject();
//工具类编写金额信息进行计算
U8Util.CalculationSum(isum, iquantity, nflat, itaxrate_b, 6);
jBodyObj.put("iquotedprice",ae.getString("TaxPrice")) ;
jBodyObj.put("itaxunitprice",ae.getString("TaxPrice")) ;//原币含税单价
jBodyObj.put("isum",ae.getString("Sum"));//价税合计
jBodyObj.put("iunitprice",ae.getString("UnitPrice")) ;//原币不含税单价
jBodyObj.put("imoney",ae.getString("Money"));//原货不含税金额
jBodyObj.put("itax",ae.getString("Tax"));//原币税额
jBodyObj.put("inatunitprice",ae.getString("NatUnitPrice"));//本币含税单价
jBodyObj.put("inatmoney",ae.getString("NatMoney"));//本币含税金额
jBodyObj.put("inattax",ae.getString("NatTax"));//本币税额
jBodyObj.put("inatsum",ae.getString("NatSum"));//本币含税金额
body.add(jBodyObj) ;
}
JSONObject main = new JSONObject();
main.put("head",jHead);
main.put("billid",billid);
main.put("AccId",AccId);
main.put("head",jHead);
main.put("body",body);
main.put("domPosition",new ArrayList<>());
//如果有错误信息则返回错误信息
if(StrUtil.isNotEmpty(resultStr.toString())){
return BaseU8Result.getSuccessMessageEntity(resultStr.toString());
}
logger.info("发货单新增推送U8"+main.toString());
String result = U8Util.sengBillToU8(main.toString(), "8000110015");
logger.info("发货单新增推送U8结果"+result);
JSONObject resultObj = JSON.parseObject(result);
boolean flag = resultObj.getBoolean("success");
logger.info(resultObj.toString());
if(!flag){
return BaseU8Result.getFailureMessageEntity("新增失败:::"+resultObj.getString("message"));
}else{
billCode = resultObj.getString("message");
//新增成功之后调用审核接口进行审核
//通过返回的编码获取发货单主键
String dlSql = "select DLID from "+AccCode+".dbo.DispatchList where cDLCode = '"+billCode+"' ";
SaleInvEntity erdt = new SaleInvEntity();
erdt.setDataSourceCode("YONYOUU8NEW");
List<HashMap<String, Object>> dlMap = saleInvDao.getU8BillData(dlSql,erdt);
if(CollectionUtils.isEmpty(dlMap)){
return BaseU8Result.getFailureMessageEntity("查询发货单主键失败::"+billCode);
}
JSONObject dt3 = new JSONObject(dlMap.get(0));
dlId = dt3.getString("DLID");
//审核
JSONObject audit = new JSONObject();
audit.put("billid", UUID.randomUUID());
audit.put("AccId", AccId);
audit.put("cVoucherId", dlId);
logger.info("发货单审核:"+main.toString());
String resultAudit = U8Util.sengBillToU8(audit.toString(), "8000110016");
logger.info("发货单审核结果:"+result);
JSONObject resultObjA = JSON.parseObject(resultAudit);
boolean flagAudit = resultObjA.getBoolean("success");
// logger.info(resultObj.toString());
if(!flagAudit){
//如果审核失败需要调用删除接口回滚单据
JSONObject delete = new JSONObject();
delete.put("billid", UUID.randomUUID());
delete.put("AccId", AccId);
delete.put("cVoucherId", dlId);
//删除
String resultDelete = U8Util.sengBillToU8(delete.toString(), "8000110017");
//删除之后直接返回失败信息
return BaseU8Result.getFailureMessageEntity("新增正常但审核失败:::"+resultObjA.getString("message"));
}
}
return BaseU8Result.getSuccessMessageEntity(resultObj.getString("message"));
} catch (Exception e) {
logger.info("发货单部分作废-红字发货单-新增失败:"+e.getMessage());
return BaseU8Result.getFailureMessageEntity("发货单部分作废-红字发货单-新增失败请联系U8管理员");
}
}
/**
*
* @content 组装销售出库单json
* @className: Administrator
* @author laborer
* @date 2025-03-18 13:54
*
*/
private JSONObject GetSaleOutJSON(String AccCode, JSONObject jHead, JSONArray jBody, String dlid, SaleInvEntity erdt)throws Exception {
JSONObject saleOutJSON = new JSONObject();
JSONObject head = new JSONObject();
JSONArray body = new JSONArray();
saleOutJSON.put("Token","Hzya1314_CheckSkip");
saleOutJSON.put("billid","123");
saleOutJSON.put("AccId",AccCode);
JSONArray bodyArr = new JSONArray();
String sqlHead = " select 0 as 'brdflag' ,'32' as 'cvouchtype' ,'普通销售' as 'cbustype' ,'发货单' as 'csource' ,cdlcode as 'cbuscode' " +
",convert(nvarchar,getdate(),23) as 'ddate' ,'203' as 'crdcode' ,cDepCode as 'cdepcode' ,cSTCode as 'cstcode' " +
",cCusCode as 'ccuscode',cexch_name,iexchrate,iTaxRate,DLID as 'cdlcode',87 as 'vt_id',DLID as 'dlid',cmaker,'0' as 'bredvouch' " +
",cDLCode + '部分自动作废' as 'cmemo'" +
"from "+AccCode+".dbo.DispatchList where DLID = '"+dlid+"'";
List<HashMap<String, Object>> dlMap = saleInvDao.getU8BillData(sqlHead,erdt);
if(CollectionUtils.isEmpty(dlMap)){
throw new Exception("获取出库单表头数据失败:"+dlid);
}
head.putAll(dlMap.get(0));
for(int i = 0; i < jBody.size(); i++) {
JSONObject bodyObj = jBody.getJSONObject(i);
head.put("cwhcode",bodyObj.getString("cwhcode"));
String sqlBody = "select " +
"cinvcode ," +
"'"+bodyObj.getString("iquantity")+"' as iquantity ," +
"cunitid as 'cAssUnit' ," +
"'"+bodyObj.getString("inum")+"' as inum ," +
"iTaxUnitPrice ," +
"iTaxRate ,'03002' as cWhcode ," +
"case when cinvcode in(select cInvCode from "+AccCode+".dbo.Inventory where bInvBatch = 1) then 0 else NULL end as 'cBatch' ," +
"iDLsID as 'idlsid' ," +
"'"+jHead.getString("cdlcode")+"' as 'cbdlcode'" +
" from DispatchLists " +
"where DLID = '"+dlid+"' " +
"and irowno = '"+bodyObj.getString("irowno")+"'";
List<HashMap<String, Object>> dlsMap = saleInvDao.getU8BillData(sqlHead,erdt);
if(CollectionUtils.isEmpty(dlsMap)){
throw new Exception("获取表体数据失败:"+dlid);
}
body.addAll(dlsMap);
}
saleOutJSON.put("head",head);
saleOutJSON.put("body",body);
logger.info("批量作废中组装好的销售出库单"+saleOutJSON.toJSONString());
return saleOutJSON;
}
/**
*
* @content 发货单部分作废-获取退货单制单JSON
* @className: Administrator
* @author laborer
* @date 2025-03-18 13:54
*
*/
private JSONObject GetDLRedJSON(String AccCode, JSONObject jHead, JSONArray jBody, String dlid, SaleInvEntity erdt)throws Exception {
StringBuffer resultStr = new StringBuffer();
JSONObject retnJSON = new JSONObject();
JSONObject head = new JSONObject();
JSONArray body = new JSONArray();
retnJSON.put("Token","Hzya1314_CheckSkip");
retnJSON.put("billid","123");
retnJSON.put("AccId",AccCode);
String sqlHead = " select convert(nvarchar,getdate(),23) as 'dDate', '05' as cvouchtype, '11' as cstcode ,cDepCode ,cPersonCode " +
",ccuscode ,cexch_name ,iexchrate ,iTaxRate ,1 as 'breturnflag' ,'"+jHead.getString("ccloser")+"' as 'cmaker' ,1 as 'cdefine11' ,cDLCode " +
" '部分自动作废' as 'cmemo' " +
"from "+AccCode+".dbo.DispatchList where DLID = '"+dlid+"'";
List<HashMap<String, Object>> dlMap = saleInvDao.getU8BillData(sqlHead,erdt);
if(CollectionUtils.isEmpty(dlMap)){
throw new Exception("获取退货单制单-获取发货单表头数据失败:"+dlid);
}
head.putAll(dlMap.get(0));
for(int i = 0; i < jBody.size(); i++) {
JSONObject bodyObj = jBody.getJSONObject(i);
BigDecimal qty = bodyObj.getBigDecimal("iquantity").multiply(new BigDecimal("-1"));
BigDecimal num = bodyObj.getBigDecimal("num") .multiply(new BigDecimal("-1"));
if(qty.compareTo(new BigDecimal(0))>0 ){
head.put("breturnflag",0);
}
if(qty.compareTo(new BigDecimal(0))<0 ){
head.put("breturnflag",1);
}
String sqlBody = " select a.cinvcode ,'"+qty+"' as iquantity ,'"+num+"' as inum ,a.cunitid ,a.iTaxUnitPrice ," +
"a.iTaxRate ,'03002' as cWhcode ,case when a.cinvcode in(select cInvCode from "+AccCode+".dbo.Inventory where bInvBatch = 1) then 0 else NULL end as 'cBatch'" +
",cdefine22 ,b.cInvCCode " +
"from "+AccCode+".dbo.DispatchLists a " +
"left join "+AccCode+".dbo.Inventory b on b.cInvCode = a.cInvCode " +
"where DLID = '"+dlid+" and irowno = '"+bodyObj.getString("irowno")+"' ";
List<HashMap<String, Object>> dlsMap = saleInvDao.getU8BillData(sqlHead,erdt);
if(CollectionUtils.isEmpty(dlsMap)){
throw new Exception("获取表体数据失败:"+dlid);
}
dlsMap.forEach(map->{
body.add(map);
Double idiscount = StrUtil.isEmpty(String.valueOf(map.get("idiscount")))?0:Double.parseDouble(String.valueOf(map.get("idiscount")));
Double nflat = StrUtil.isEmpty(String.valueOf(map.get("nflat")))?0:Double.parseDouble(String.valueOf(map.get("nflat")));
Double itaxrate = StrUtil.isEmpty(String.valueOf(map.get("itaxrate")))?0:Double.parseDouble(String.valueOf(map.get("itaxrate")));
//行上如果存在折扣额需要生成一行折扣商品行
if (idiscount != 0){
map.put("idiscount",0);
JSONObject discountObj = new JSONObject();
String sqlType = "select * from HzyaDataInteractionPlatform_KJS.dbo.Base_DispatchList_VoucherType where voucherType = '"+map.get("cdefine22")+"'";
try {
List<HashMap<String, Object>> dt1 = saleInvDao.getU8BillData(sqlHead,erdt);
if(CollectionUtils.isEmpty(dt1) || dt1.size()>1){
resultStr.append("查询发货单类型对照表失败:"+map.get("cdefine22")+"在对照表中不存在或存在多个!");
}
String cinvcode = String.valueOf(dt1.get(0).get("cInvCode"));
discountObj.put("cdefine22","返利");
discountObj.put("cinvcode",cinvcode);
discountObj.put("iquantity",0);
discountObj.put("inum",0);
discountObj.put("isum",idiscount);
JSONObject ae = U8Util.CalculationSum(discountObj.getBigDecimal("isum"), new BigDecimal(1), new BigDecimal(nflat), new BigDecimal(itaxrate), 6);
// AmountEntity ae = U8AmountCalculation.CalculationSum(decimal.Parse(discountObj["isum"]?.ToString()), 1, nflat, itaxrate, 6);
discountObj.put("itaxunitprice",0);
discountObj.put("isum",ae.getString("Sum"));
discountObj.put("iunitprice",0);
discountObj.put("imoney",ae.getString("Money"));
discountObj.put("itax",ae.getString("Tax"));
discountObj.put("inatunitprice",0);
discountObj.put("inatmoney",ae.getString("NatMoney"));
discountObj.put("inattax",ae.getString("NatTax"));
discountObj.put("inatsum",ae.getString("NatSum"));
discountObj.put("itaxrate",ae.getString("PerTaxRate"));
discountObj.put("iquotedprice",0);
discountObj.put("idiscount",0);
discountObj.put("inatdiscount",0);
discountObj.put("kl",100);
discountObj.put("kl2",100);
discountObj.put("irowno",dlsMap.size()+ 1);//行号
if (cinvcode == "98"){
cinvcode = "9800";
}else if (cinvcode == "99"){
String cinvccode = String.valueOf(dlsMap.get(0).get("cInvCCode"));
//白酒
String startStr = "050201";
String endStr = "050205";
// 将字符串转换为整数
Integer targetNumber = null;
Integer startNumber = null;
Integer endNumber = null;
targetNumber = Integer.valueOf(cinvccode);
startNumber = Integer.valueOf(startStr);
endNumber = Integer.valueOf(endStr);
// 将字符串转换为整数
boolean isInRange = targetNumber >= startNumber && targetNumber <= endNumber;
// 判断目标数字是否在范围内
if (isInRange){
cinvcode = "9902";
}else{
cinvcode = "9900";
}
String sqlInv = " select * from "+AccCode+".dbo.Inventory where cInvCode = '"+cinvcode+"'";
List<HashMap<String, Object>> erdtInvMap = saleInvDao.getU8BillData(sqlInv,erdt);
if(CollectionUtils.isEmpty(erdtInvMap)){
resultStr.append("查询存货失败::"+cinvcode);
}
JSONObject dt2 = new JSONObject(erdtInvMap.get(0));
discountObj.put("cinvcode",dt2.getString("cInvCode"));
discountObj.put("cinvname",dt2.getString("cInvName"));
discountObj.put("cgroupcode",dt2.getString("cGroupCode"));
discountObj.put("igrouptype",dt2.getString("iGroupType"));
discountObj.put("cunitid",dt2.getString("cComunitCode"));
discountObj.put("calculate",false);
body.add(discountObj) ;
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
retnJSON.put("head",head);
retnJSON.put("body",body);
return retnJSON;
}
}

View File

@ -21,7 +21,8 @@
<select id="entity_list_base" resultMap="get-entity-result" parameterType="com.hzya.frame.u8.otherin.entity.OtherInEntity">
select * from kjs_external.dbo.v_hzya_other_in
<if test="ids != null and ids != ''">and ids = #{ids} </if>
<if test="ids == null or ids == ''"> where sync_flag is null</if>
<if test="ids != null and ids != ''">where ids = #{ids} </if>
</select>
<!--通过主键修改方法-->

View File

@ -19,7 +19,8 @@
<select id="entity_list_base" resultMap="get-entity-result" parameterType="com.hzya.frame.u8.otherout.entity.OtherOutEntity">
select * from kjs_external.dbo.v_hzya_otherout
<if test="ids != null and ids != ''">and ids = #{ids} </if>
<if test="ids == null or ids == ''"> where sync_flag is null</if>
<if test="ids != null and ids != ''">where ids = #{ids} </if>
</select>
<!--通过主键修改方法-->
<update id="entity_update" parameterType="com.hzya.frame.u8.otherout.entity.OtherOutEntity">

View File

@ -17,7 +17,8 @@
<select id="entity_list_base" resultMap="get-entity-result" parameterType="com.hzya.frame.u8.otherreceipt.entity.OtherReceiptEntity">
select * from kjs_external.dbo.v_hzya_other_receipt
<if test="ids != null and ids != ''">and ids = #{ids} </if>
<if test="ids == null or ids == ''"> where sync_flag is null</if>
<if test="ids != null and ids != ''">where ids = #{ids} </if>
</select>

View File

@ -0,0 +1,13 @@
package com.hzya.frame.u8.productionin.entity;
import com.hzya.frame.web.entity.BaseEntity;
/**
* com.hzya.frame.u8.productionin.entity
*生产入库单
* @author makejava
* @date 2025-02 -27 9:09
*/
public class ProductionInEntity extends BaseEntity {
}

View File

@ -0,0 +1,30 @@
package com.hzya.frame.u8.productionin.service;
import com.alibaba.fastjson.JSONObject;
import com.hzya.frame.basedao.service.IBaseService;
import com.hzya.frame.u8.production.entity.MomOrderEntity;
import com.hzya.frame.u8.productionin.entity.ProductionInEntity;
import com.hzya.frame.u8.util.U8ResultEntity;
/**
*
* @content 生产入库单
* @className: Administrator
* @author laborer
* @date 2025-02-27 9:10
*
*/
public interface IProductionInService extends IBaseService<ProductionInEntity,String> {
/**
*
* @content 产成品入库-新增
* @className: Administrator
* @author laborer
* @date 2025-02-24 14:33
*
*/
U8ResultEntity addProductionIn(JSONObject parm);
}

View File

@ -0,0 +1,304 @@
package com.hzya.frame.u8.productionin.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.hzya.frame.basedao.service.impl.BaseService;
import com.hzya.frame.u8.production.dao.IMomOrderDao;
import com.hzya.frame.u8.production.entity.MomOrderEntity;
import com.hzya.frame.u8.productionin.entity.ProductionInEntity;
import com.hzya.frame.u8.productionin.service.IProductionInService;
import com.hzya.frame.u8.saleinv.dao.ISaleInvDao;
import com.hzya.frame.u8.saleinv.entity.SaleInvEntity;
import com.hzya.frame.u8.util.BaseU8Result;
import com.hzya.frame.u8.util.U8ResultEntity;
import com.hzya.frame.u8.util.U8Util;
import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
/**
*
* @content 生产入库单
* @className: Administrator
* @author laborer
* @date 2025-02-27 9:10
*
*/
@Service(value = "ProductionInServicempl")
public class ProductionInServicempl extends BaseService<ProductionInEntity,String> implements IProductionInService {
@Autowired
private ISaleInvDao saleInvDao;
Logger logger = LogManager.getLogger(getClass());
/**
*
* @content 产成品入库-新增
* @className: Administrator
* @author laborer
* @date 2025-02-24 14:33
*
*/
@Override
public U8ResultEntity addProductionIn(JSONObject parm) {
String billCode = "";
String dlId = "";
String AccId = "";
JSONObject jsonObject = parm.getJSONObject("jsonStr");
logger.info("接收到的参数"+jsonObject.toString());
StringBuffer resultStr = new StringBuffer();//回传json
try {
String billid = jsonObject.getString("billid");
if(StrUtil.isEmpty(billid)){
return BaseU8Result.getFailureMessageEntity("请传入第三方唯一标识");
}
AccId = jsonObject.getString("AccId");
if(StrUtil.isEmpty(AccId)){
return BaseU8Result.getFailureMessageEntity("请传入正确的账套号");
}
String AccCode = U8Util.accMap.get(AccId);
if(StrUtil.isEmpty(AccCode)){
return BaseU8Result.getFailureMessageEntity("请传入正确的账套号");
}
JSONObject jHead = jsonObject.getJSONObject("head");
//todo 发货单表头必输项
String[] MustInputCode = new String[] { "cmpocode", "ddate", "cwhcode", "cmaker"};
String[] MustInputName = new String[] { "生产订单号", "单据日期", "仓库编码", "制单人"};
//根据当前单据类型 所需参数判断是否传入该参数没有传入
for (int i = 0; i < MustInputCode.length; i++)
{
if (StrUtil.isEmpty(jHead.getString(MustInputCode[i]))) {
resultStr.append("请输入:" + MustInputCode[i] + "(" + MustInputName[i] + ")") ;
}
}
//如果有错误信息则返回错误信息
if(StrUtil.isNotEmpty(resultStr.toString())){
return BaseU8Result.getFailureMessageEntity(resultStr.toString());
}
// //单据编号暂时不需要我处理
// if(StrUtil.isEmpty(jHead.getString("ccode"))){
//
// }
//默认字段
//入库类别
if(StrUtil.isEmpty(jHead.getString("crdcode"))){
jHead.put("crdcode","103");
}
//收发标识
if(StrUtil.isEmpty(jHead.getString("brdflag"))){
jHead.put("brdflag","1");
}
//单据类型编码
if(StrUtil.isEmpty(jHead.getString("cvouchtype"))){
jHead.put("cvouchtype","10");
}
//单据日期
if(StrUtil.isEmpty(jHead.getString("ddate"))){
jHead.put("ddate", DateUtil.format(new Date(),"yyyy-MM-dd"));
}
//来源单据
if(StrUtil.isEmpty(jHead.getString("csource"))){
jHead.put("csource","生产订单");
}
//业务类型
if(StrUtil.isEmpty(jHead.getString("cbustype"))){
jHead.put("cbustype","成品入库");
}
//单据模板号
if(StrUtil.isEmpty(jHead.getString("vt_id"))){
jHead.put("vt_id","63");
}
SaleInvEntity U8Obj = new SaleInvEntity();
U8Obj.setDataSourceCode("YONYOUU8NEW");
//验证单号唯一
String cdefine5 = jsonObject.getString("cdefine5");
if(StrUtil.isNotEmpty(cdefine5)){
String cdefine5Sql = "select cdefine5 from "+AccCode+".dbo.rdrecord10 where cdefine5 = '"+cdefine5+"'";
List<HashMap<String, Object>> cdefine5Map = saleInvDao.getU8BillData(cdefine5Sql,U8Obj);
if(CollectionUtils.isNotEmpty(cdefine5Map) ){
return BaseU8Result.getFailureMessageEntity("单号重复,请检查:"+cdefine5);
}
}
//生产订单id
if(StrUtil.isEmpty(jHead.getString("iproorderid"))){
String sql = "select MoId from "+AccCode+".dbo.mom_order where MoCode = '"+jHead.getString("cmpocode")+"'";
List<HashMap<String, Object>> momMap = saleInvDao.getU8BillData(sql,U8Obj);
if(CollectionUtils.isEmpty(momMap) ){
return BaseU8Result.getFailureMessageEntity("未找到生产订单"+jHead.getString("cmpocode"));
}
HashMap<String, Object> mom= momMap.get(0);
jHead.put("iproorderid",mom.get("MoId"));
}
//表体
//表体
JSONArray body = new JSONArray();
JSONArray jBody = jsonObject.getJSONArray("body");
for (int i = 0; i < jBody.size(); i++) {
JSONObject jBodyObj = jBody.getJSONObject(i);
//todo 发货单表头必输项
String[] MustInputCodes = new String[] { "cinvcode", "iquantity", "cmpocode", "imoseq"};
String[] MustInputNames = new String[] { "产品编码", "数量", "生产订单号", "生产订单行号"};
//根据当前单据类型 所需参数判断是否传入该参数没有传入
for (int j = 0; j < MustInputCodes.length; j++)
{
if (StrUtil.isEmpty(jHead.getString(MustInputCodes[j]))) {
resultStr.append("请输入:" + MustInputCodes[j] + "(" + MustInputNames[j] + ")") ;
}
}
//如果有错误信息则返回错误信息
if(StrUtil.isNotEmpty(resultStr.toString())){
return BaseU8Result.getFailureMessageEntity(resultStr.toString());
}
//验证必填项
if(StrUtil.isEmpty(jBodyObj.getString("cinvcode"))){
resultStr.append("存货编码不能为空 行:"+i+1) ;
//如果有错误信息则返回错误信息
if(StrUtil.isNotEmpty(resultStr.toString())){
return BaseU8Result.getFailureMessageEntity(resultStr.toString());
}
}
//判断数量不能为空 否则下面无法计算
if(StrUtil.isEmpty(jBodyObj.getString("iquantity"))){
resultStr.append("数量不能为空 行:"+i+1) ;
//如果有错误信息则返回错误信息
if(StrUtil.isNotEmpty(resultStr.toString())){
return BaseU8Result.getFailureMessageEntity(resultStr.toString());
}
}
if("0".equals(jBodyObj.getString("iquantity"))){
resultStr.append("数量不能为0 行:"+i+1) ;
//如果有错误信息则返回错误信息
if(StrUtil.isNotEmpty(resultStr.toString())){
return BaseU8Result.getFailureMessageEntity(resultStr.toString());
}
}
//获取辅计量单位
String invSql = "select cInvCode,cInvName,cInvStd,Inv.cComUnitCode,cInvCCode,iChangRate,cPUComUnitCode,cSAComUnitCode,cProductUnit,cSTComUnitCode " +
"from "+AccCode+".dbo.Inventory Inv " +
"left join "+AccCode+".dbo.ComputationUnit Com On Inv.cComUnitCode = Com.cComUnitCode where cInvCode='" + jBodyObj.getString("cinvcode")+ "'";
List<HashMap<String, Object>> invMap = saleInvDao.getU8BillData(invSql,U8Obj);
if(CollectionUtils.isEmpty(invMap) ){
return BaseU8Result.getFailureMessageEntity("ERP没有该物料"+jBodyObj.getString("cinvcode"));
}
HashMap<String, Object> inv= invMap.get(0);
if(StrUtil.isNotEmpty(String.valueOf(inv.get("cSTComUnitCode")))){
jBodyObj.put("cassunit",inv.get("cSTComUnitCode"));
String sqlCassUnit = "select * from "+AccCode+".dbo.ComputationUnit where cComUnitCode='" +inv.get("cSTComUnitCode")+"'";
List<HashMap<String, Object>> dtUnit = saleInvDao.getU8BillData(sqlCassUnit,U8Obj);
if(CollectionUtils.isEmpty(dtUnit) ){
return BaseU8Result.getFailureMessageEntity("查询单位失败,请检查,行号:"+i+1);
}
HashMap<String, Object> dtUnitObj= dtUnit.get(0);
jBodyObj.put("iinvexchrate",dtUnitObj.get("iChangRate"));
jBodyObj.put("inum",jBodyObj.getBigDecimal("iquantity").divide(new BigDecimal(String.valueOf(dtUnitObj.get("iChangRate"))),6, RoundingMode.HALF_UP));
}
jBodyObj.put("irowno",i+1);
//生产订单行号 imoseq
String momsSql = " select MoDId ,SortSeq ,OrderDId ,OrderType ,OrderCode ,OrderSeq ,SoDId ,SoType ,SoCode ,SoSeq " +
"from "+AccCode+".dbo.mom_order mo " +
"left join "+AccCode+".dbo.mom_orderdetail mos on mos.MoId = mo.MoId " +
"where MoCode = '"+jBodyObj.getString("cmpocode")+"' and InvCode = '"+jBodyObj.getString("cinvcode")+"' and SortSeq = '"+jBodyObj.getString("imoseq")+"'";
List<HashMap<String, Object>> momsMap = saleInvDao.getU8BillData(momsSql,U8Obj);
if(CollectionUtils.isEmpty(momsMap)){
return BaseU8Result.getFailureMessageEntity("生产订单号:"+jBodyObj.getString("cmpocode")+",存货编码::"+jBodyObj.getString("cinvcode")+",行号:"+jBodyObj.getString("imoseq")+",不存在");
}
HashMap<String, Object> momsObj= momsMap.get(0);
//生产订单子表ID
if(StrUtil.isEmpty(jBodyObj.getString("impoids"))){
jBodyObj.put("impoids",momsObj.get("MoDId"));
}
//生产订单行号
if(StrUtil.isEmpty(jBodyObj.getString("imoseq"))){
jBodyObj.put("imoseq",momsObj.get("SortSeq"));
}
//订单子表id
if(StrUtil.isEmpty(jBodyObj.getString("iorderdid"))){
jBodyObj.put("iorderdid",momsObj.get("OrderDId"));
}
//订单类型
if(StrUtil.isEmpty(jBodyObj.getString("iordertype"))){
jBodyObj.put("iordertype",momsObj.get("OrderType"));
}
//订单号
if(StrUtil.isEmpty(jBodyObj.getString("iordercode"))){
jBodyObj.put("iordercode",momsObj.get("OrderCode"));
}
//订单行号
if(StrUtil.isEmpty(jBodyObj.getString("iorderseq"))){
jBodyObj.put("iorderseq",momsObj.get("OrderSeq"));
}
//销售订单子表ID
if(StrUtil.isEmpty(jBodyObj.getString("isodid"))){
jBodyObj.put("isodid",momsObj.get("SoDId"));
}
//订单类型
if(StrUtil.isEmpty(jBodyObj.getString("isotype"))){
jBodyObj.put("isotype",momsObj.get("SoType"));
}
//销售订单号
if(StrUtil.isEmpty(jBodyObj.getString("csocode"))){
jBodyObj.put("csocode",momsObj.get("SoCode"));
}
//销售订单行号
if(StrUtil.isEmpty(jBodyObj.getString("isoseq"))){
jBodyObj.put("isoseq",momsObj.get("SoSeq"));
}
//判断单价是否传输传了则计算金额
if(StrUtil.isNotEmpty(jBodyObj.getString("iunitcost"))){
if(StrUtil.isEmpty(jBodyObj.getString("iprice"))){
BigDecimal iquantity= jBodyObj.getBigDecimal("iquantity");
BigDecimal iunitcost= jBodyObj.getBigDecimal("iunitcost");
jBodyObj.put("iprice",iquantity.multiply(iunitcost));
}
}
body.add(jBodyObj);
}
JSONObject main = new JSONObject();
main.put("head",jHead);
main.put("billid",billid);
main.put("AccId",AccId);
main.put("head",jHead);
main.put("body",body);
main.put("domPosition",new ArrayList<>());
logger.info("产成品入库单新增推送U8"+main.toString());
String result = U8Util.sengBillToU8(main.toString(), "8000110018");
logger.info("产成品入库单新增推送U8结果"+result);
JSONObject resultObj = JSON.parseObject(result);
boolean flag = resultObj.getBoolean("success");
logger.info(resultObj.toString());
if(flag){
return BaseU8Result.getSuccessMessageEntity(resultObj.getString("message"));
}else{
return BaseU8Result.getFailureMessageEntity(resultObj.getString("message"));
}
} catch (Exception e) {
//如果审核失败需要调用删除接口回滚单据
JSONObject delete = new JSONObject();
delete.put("billid", UUID.randomUUID());
delete.put("AccId", AccId);
delete.put("cVoucherId", billCode);
//删除
String resultDelete = U8Util.sengBillToU8(delete.toString(), "8000110020");
logger.info("新增失败:"+e.getMessage());
return BaseU8Result.getFailureMessageEntity("新增失败请联系U8管理员");
}
}
}

View File

@ -22,7 +22,9 @@
<select id="entity_list_base" resultMap="get-entity-result" parameterType="com.hzya.frame.u8.receipt.entity.ReceiptEntity">
select * from kjs_external.dbo.v_hzya_receipt
<if test="ids != null and ids != ''">and ids = #{ids} </if>
<if test="ids == null or ids == ''"> where sync_flag is null</if>
<if test="ids != null and ids != ''">where ids = #{ids} </if>
</select>
<!--通过主键修改方法-->

View File

@ -45,4 +45,6 @@ public interface ISaleInvDao extends IBaseDao<SaleInvEntity,String> {
*/
List<HashMap<String, Object>> getU8BillData(String str , SaleInvEntity entity)throws Exception;
int execUpdateSql(String str , SaleInvEntity entity)throws Exception;
int execInsertSql(String str , SaleInvEntity entity)throws Exception;
}

View File

@ -37,6 +37,16 @@ public class SaleInvDaoImpl extends MybatisGenericDao<SaleInvEntity,String> impl
@DS("#entity.dataSourceCode")
@Override
public List<HashMap<String, Object>> getU8BillData(String str, SaleInvEntity entity)throws Exception {
return execSqlService.execSelectSql(str, "");
return execSqlService.execSelectSql(str, entity.getDataSourceCode());
}
@DS("#entity.dataSourceCode")
@Override
public int execUpdateSql(String str, SaleInvEntity entity) throws Exception {
return execSqlService.execUpdateSql(str, entity.getDataSourceCode());
}
@Override
public int execInsertSql(String str, SaleInvEntity entity) throws Exception {
return execSqlService.execInsertSql(str, entity.getDataSourceCode());
}
}

View File

@ -17,7 +17,8 @@
<select id="entity_list_base" resultMap="get-entity-result" parameterType="com.hzya.frame.u8.saleinv.entity.SaleInvEntity">
select * from kjs_external.dbo.v_hzya_saleinv
<if test="ids != null and ids != ''">and ids = #{ids} </if>
<if test="ids == null or ids == ''"> where sync_flag is null</if>
<if test="ids != null and ids != ''">where ids = #{ids} </if>
</select>

View File

@ -19,7 +19,8 @@
<select id="entity_list_base" resultMap="get-entity-result" parameterType="com.hzya.frame.u8.saleout.entity.SaleOutEntity">
-- 销售单主表
select * from kjs_external.dbo.v_hzya_saleout
<if test="ids != null and ids != ''">and ids = #{ids} </if>
<if test="ids == null or ids == ''"> where sync_flag is null</if>
<if test="ids != null and ids != ''">where ids = #{ids} </if>
</select>
<!--通过主键修改方法-->
<update id="entity_update" parameterType="com.hzya.frame.u8.saleout.entity.SaleOutEntity">

View File

@ -35,4 +35,14 @@ public interface ISaleOutService extends IBaseService<SaleOutEntity,String> {
*/
U8ResultEntity addSaleOut(JSONObject parm);
/**
*
* @content 销售出库-新增
* @className: Administrator
* @author laborer
* @date 2025-02-24 14:33
*
*/
U8ResultEntity deleteSaleOut(JSONObject parm);
U8ResultEntity Add_DLPartialClose(JSONObject parm);
}

View File

@ -295,6 +295,17 @@ public class SaleOutServiceImpl extends BaseService<SaleOutEntity,String> implem
if(StrUtil.isEmpty(AccCode)){
return BaseU8Result.getFailureMessageEntity("获取账套号有误,请联系管理员");
}
//验证单号唯一
String cdefine5 = jsonObject.getString("cdefine5");
if(StrUtil.isNotEmpty(cdefine5)){
String cdefine5Sql = "select cdefine5 from "+AccCode+".dbo.rdrecord32 where cdefine5 = '"+cdefine5+"'";
List<HashMap<String, Object>> cdefine5Map = saleInvDao.getU8BillData(cdefine5Sql,U8Obj);
if(CollectionUtils.isNotEmpty(cdefine5Map) ){
return BaseU8Result.getFailureMessageEntity("单号重复,请检查:"+cdefine5);
}
}
//发货退货单主表@
//发货退货单主表
String sqlSelDisList = "select DLID as 'dlid',DLID as 'cdlcode' ,cDLCode as 'cbuscode' ,cDepCode as 'cdepcode' ,cPersonCode as 'cpersoncode' ,cCusCode as 'ccuscode'," +
@ -501,4 +512,313 @@ public class SaleOutServiceImpl extends BaseService<SaleOutEntity,String> implem
return BaseU8Result.getFailureMessageEntity("新增失败请联系U8管理员");
}
}
@Override
public U8ResultEntity deleteSaleOut(JSONObject parm) {
String billCode = "";
String dlId = "";
String AccId = "";
JSONObject jsonObject = parm.getJSONObject("jsonStr");
JSONObject jHead = jsonObject.getJSONObject("head");
logger.info("接收到的参数"+jsonObject.toString());
StringBuffer resultStr = new StringBuffer();//回传json
try {
String billid = jsonObject.getString("billid");
if(StrUtil.isEmpty(billid)){
return BaseU8Result.getFailureMessageEntity("请传入第三方唯一标识");
}
AccId = jsonObject.getString("AccId");
if(StrUtil.isEmpty(AccId)){
return BaseU8Result.getFailureMessageEntity("请传入正确的账套号");
}
String AccCode = U8Util.accMap.get(AccId);
if(StrUtil.isEmpty(AccCode)){
return BaseU8Result.getFailureMessageEntity("请传入正确的账套号");
}
String cVoucherId = jHead.getString("cVoucherId");
if(StrUtil.isEmpty(cVoucherId)){
return BaseU8Result.getFailureMessageEntity("销售出库单删除异常cVoucherId 单据id 未输入");
}
//弃审
String isUnAudit = jHead.getString("isUnAudit");
if(StrUtil.isNotEmpty(isUnAudit) && isUnAudit.equals("1")){
String sql = " select cHandler as 'auditPersonName' from "+AccCode+".dbo.rdrecord32 where ID = '"+cVoucherId+"' ";
SaleInvEntity erdt = new SaleInvEntity();
erdt.setDataSourceCode("YONYOUU8NEW");
List<HashMap<String, Object>> erdtMap = saleInvDao.getU8BillData(sql,erdt);
if(CollectionUtils.isEmpty(erdtMap)){
return BaseU8Result.getFailureMessageEntity("销售出库单删除-销售出库单不存在或已被删除!"+cVoucherId);
}
HashMap<String, Object> dt = erdtMap.get(0);
String auditPersonName = String.valueOf(dt.get("auditPersonName"));
if(StrUtil.isNotEmpty(auditPersonName)){
JSONObject json = new JSONObject();
json.put("Token", "Hzya1314_CheckSkip");
json.put("billid", cVoucherId);
json.put("AccId", AccId);
json.put("cVoucherId", cVoucherId);
//弃审
String resultUnAudit = U8Util.sengBillToU8(json.toString(), "8000110024");
JSONObject resultObj = JSON.parseObject(resultUnAudit);
boolean flag = resultObj.getBoolean("success");
if(!flag){
return BaseU8Result.getFailureMessageEntity("销售出库单自动弃审失败:"+cVoucherId);
}else{
//删除
JSONObject delete = new JSONObject();
delete.put("Token", "Hzya1314_CheckSkip");
delete.put("billid", cVoucherId);
delete.put("AccId", AccId);
delete.put("cVoucherId", cVoucherId);
String resultDelete = U8Util.sengBillToU8(delete.toString(), "8000110023");
JSONObject resultDeleteObj = JSON.parseObject(resultDelete);
boolean deleteFlag = resultDeleteObj.getBoolean("success");
if(deleteFlag){
return BaseU8Result.getSuccessMessageEntity("销售出库单删除成功");
}else{
return BaseU8Result.getFailureMessageEntity("销售出库单删除失败:"+resultDelete);
}
}
}
}
} catch (Exception e) {
return BaseU8Result.getFailureMessageEntity("销售出库单删除失败请联系U8管理员");
}
return BaseU8Result.getSuccessMessageEntity("销售出库单删除成功");
}
/// <summary>
/// 销售出库单-新增发货单部分作废用
/// </summary>
/// <param name="json"></param>
/// <returns></returns>
public U8ResultEntity Add_DLPartialClose(JSONObject parm) {
String billCode = "";
String dlId = "";
String AccId = "";
JSONObject jsonObject = parm.getJSONObject("jsonStr");
logger.info("接收到的参数"+jsonObject.toString());
StringBuffer resultStr = new StringBuffer();//回传json
try {
String billid = jsonObject.getString("billid");
if(StrUtil.isEmpty(billid)){
return BaseU8Result.getFailureMessageEntity("请传入第三方唯一标识");
}
AccId = jsonObject.getString("AccId");
if(StrUtil.isEmpty(AccId)){
return BaseU8Result.getFailureMessageEntity("请传入正确的账套号");
}
String AccCode = U8Util.accMap.get(AccId);
if(StrUtil.isEmpty(AccCode)){
return BaseU8Result.getFailureMessageEntity("请传入正确的账套号");
}
JSONObject jHead = jsonObject.getJSONObject("head");
//todo 发货单表头必输项
String[] MustInputCode = new String[] { "cbuscode", "crdcode", "cwhcode", "cmaker"};
String[] MustInputName = new String[] { "发货单号", "收发类别", "仓库", "制单人"};
//根据当前单据类型 所需参数判断是否传入该参数没有传入
for (int i = 0; i < MustInputCode.length; i++)
{
if (StrUtil.isEmpty(jHead.getString(MustInputCode[i]))) {
resultStr.append("请输入:" + MustInputCode[i] + "(" + MustInputName[i] + ")") ;
}
}
//如果有错误信息则返回错误信息
if(StrUtil.isNotEmpty(resultStr.toString())){
return BaseU8Result.getFailureMessageEntity(resultStr.toString());
}
//发货退货单主表
String sqlSelDisList = "select DLID as 'dlid' ,DLID as 'cdlcode' ,cDLCode as 'cbuscode' ,cDepCode as 'cdepcode' ," +
"cPersonCode as 'cpersoncode' ,cCusCode as 'ccuscode' ,cCusCode as 'cinvoicecompany' ,cSTCode as 'cstcode' ," +
"'32' as 'cvouchtype' ,'普通销售' as 'cbustype' ,'发货单' as 'csource' ,GETDATE() as 'ddate' " +
"from DispatchList " +
"where cDLCode = '"+jHead.getString("cbuscode");
//查询账套中的发货单信息
SaleInvEntity U8Obj = new SaleInvEntity();
U8Obj.setDataSourceCode("YONYOUU8NEW");
List<HashMap<String, Object>> selDisListMap = saleInvDao.getU8BillData(sqlSelDisList,U8Obj);
if(CollectionUtils.isEmpty(selDisListMap) ){
return BaseU8Result.getFailureMessageEntity("发货单主表查询失败"+jHead.getString("cbuscode"));
}
HashMap<String, Object> selDis= selDisListMap.get(0);
if(StrUtil.isEmpty(jHead.getString("dlid"))){
jHead.put("dlid",selDis.get("dlid"));
}
if(StrUtil.isEmpty(jHead.getString("cdlcode"))){
jHead.put("cdlcode",selDis.get("cdlcode"));
}
if(StrUtil.isEmpty(jHead.getString("cbuscode"))){
jHead.put("cbuscode",selDis.get("cbuscode"));
}
if(StrUtil.isEmpty(jHead.getString("cdepcode"))){
jHead.put("cdepcode",selDis.get("cdepcode"));
}
if(StrUtil.isEmpty(jHead.getString("cpersoncode"))){
jHead.put("cpersoncode",selDis.get("cpersoncode"));
}
if(StrUtil.isEmpty(jHead.getString("ccuscode"))){
jHead.put("ccuscode",selDis.get("ccuscode"));
}
if(StrUtil.isEmpty(jHead.getString("cinvoicecompany"))){
jHead.put("cinvoicecompany",selDis.get("cinvoicecompany"));
}
if(StrUtil.isEmpty(jHead.getString("cinvoicecompany"))){
jHead.put("cinvoicecompany",selDis.get("cinvoicecompany"));
}
if(StrUtil.isEmpty(jHead.getString("cvouchtype"))){
jHead.put("cvouchtype",selDis.get("cvouchtype"));
}
if(StrUtil.isEmpty(jHead.getString("cbustype"))){
jHead.put("cbustype",selDis.get("cbustype"));
}
if(StrUtil.isEmpty(jHead.getString("csource"))){
jHead.put("csource",selDis.get("csource"));
}
if(StrUtil.isEmpty(jHead.getString("ddate"))){
jHead.put("ddate",selDis.get("ddate"));
}
if(StrUtil.isEmpty(jHead.getString("cmemo"))){
jHead.put("cmemo",selDis.get("cmemo"));
}
if(StrUtil.isEmpty(jHead.getString("cdefine1"))){
jHead.put("cdefine1",selDis.get("cdefine1"));
}
//表体
JSONArray body = new JSONArray();
JSONArray jBody = jsonObject.getJSONArray("body");
for (int i = 0; i < jBody.size(); i++) {
JSONObject jBodyObj = jBody.getJSONObject(i);
if(StrUtil.isEmpty(jBodyObj.getString("cinvcode"))){
resultStr.append("材料编码不能为空 行:"+i+1) ;
//如果有错误信息则返回错误信息
if(StrUtil.isNotEmpty(resultStr.toString())){
return BaseU8Result.getFailureMessageEntity(resultStr.toString());
}
}
if(StrUtil.isEmpty(jBodyObj.getString("iquantity"))){
resultStr.append("数量不能为空 行:"+i+1) ;
//如果有错误信息则返回错误信息
if(StrUtil.isNotEmpty(resultStr.toString())){
return BaseU8Result.getFailureMessageEntity(resultStr.toString());
}
}
if("0".equals(jBodyObj.getString("iquantity"))){
resultStr.append("数量不能为0 行:"+i+1) ;
//如果有错误信息则返回错误信息
if(StrUtil.isNotEmpty(resultStr.toString())){
return BaseU8Result.getFailureMessageEntity(resultStr.toString());
}
}
//发货退货单子表@
String sqlSelDisLists = " select idlsid from "+AccCode+".dbo.DispatchList dl left join "+AccCode+".dbo.DispatchLists dls on dls.DLID = dl.DLID " +
"where cDLCode = '"+jBodyObj.getString("cbdlcode")+"" +
"' and cInvCode = '"+jBodyObj.getString("cinvcode")+"" +
"' and irowno = '"+jBodyObj.getString("cdblrowno")+"'";
List<HashMap<String, Object>> selDisDetailsListMap = saleInvDao.getU8BillData(sqlSelDisLists,U8Obj);
if(CollectionUtils.isEmpty(selDisDetailsListMap) ){
return BaseU8Result.getFailureMessageEntity("发货单子表查询失败"+jHead.getString("cbuscode")+"发货单表体存货"+jBodyObj.getString("cinvcode")+"行号"+jBodyObj.getString("cdblrowno")+"不存在");
}
HashMap<String, Object> selDisDetails= selDisDetailsListMap.get(0);
if(StrUtil.isEmpty(jBodyObj.getString("idlsid"))){
jBodyObj.put("idlsid",selDisDetails.get("idlsid"));
}
//获取辅计量单位
String dtInvSql = "select cInvCode,cInvName,cInvStd,Inv.cComUnitCode,cInvCCode,iChangRate, cPUComUnitCode,cSAComUnitCode,cProductUnit,cSTComUnitCode " +
"from "+AccCode+".dbo.Inventory Inv " +
"left join "+AccCode+".dbo.ComputationUnit Com On Inv.cComUnitCode = Com.cComUnitCode " +
"where cInvCode='" + jBodyObj.getString("cinvcode") +"'";
List<HashMap<String, Object>> dtInv = saleInvDao.getU8BillData(dtInvSql,U8Obj);
if(CollectionUtils.isEmpty(dtInv) ){
return BaseU8Result.getFailureMessageEntity("ERP没有该物料请检查行号"+i+1);
}
HashMap<String, Object> dtInvObj= dtInv.get(0);
//存在辅计量单位则 计算件数 =数量/换算率
if(StrUtil.isNotEmpty(String.valueOf(dtInvObj.get("cSTComUnitCode")))){
jBodyObj.put("cassunit",dtInvObj.get("cSTComUnitCode"));
String sqlCassUnit = "select * from "+AccCode+".dbo.ComputationUnit where cComUnitCode='" +dtInvObj.get("cSTComUnitCode")+"'";
List<HashMap<String, Object>> dtUnit = saleInvDao.getU8BillData(sqlCassUnit,U8Obj);
if(CollectionUtils.isEmpty(dtUnit) ){
return BaseU8Result.getFailureMessageEntity("查询单位失败,请检查,行号:"+i+1);
}
HashMap<String, Object> dtUnitObj= dtUnit.get(0);
jBodyObj.put("iinvexchrate",dtUnitObj.get("iChangRate"));
jBodyObj.put("inum",jBodyObj.getBigDecimal("iquantity").divide(new BigDecimal(String.valueOf(dtUnitObj.get("iChangRate"))),6, RoundingMode.HALF_UP));
}
jBodyObj.put("irowno",i+1);
//默认字段
//是否需要开票
if(StrUtil.isEmpty(jBodyObj.getString("bneedbill"))){
jBodyObj.put("bneedbill",1);
}
//是否存货核算开票
if(StrUtil.isEmpty(jBodyObj.getString("bIAcreatebill"))){
jBodyObj.put("bIAcreatebill",0);
}
//是否销售出库开票
if(StrUtil.isEmpty(jBodyObj.getString("bsaleoutcreatebill"))){
jBodyObj.put("bsaleoutcreatebill",0);
}
body.add(jBodyObj);
}
JSONObject main = new JSONObject();
main.put("head",jHead);
main.put("billid",billid);
main.put("AccId",AccId);
main.put("head",jHead);
main.put("body",body);
main.put("domPosition",new ArrayList<>());
logger.info("销售出库单新增推送U8"+main.toString());
String result = U8Util.sengBillToU8(main.toString(), "8000110021");
logger.info("销售出库单新增推送U8结果"+result);
JSONObject resultObj = JSON.parseObject(result);
boolean flag = resultObj.getBoolean("success");
logger.info(resultObj.toString());
if(!flag){
return BaseU8Result.getFailureMessageEntity("新增失败:::"+resultObj.getString("message"));
}else{
billCode = resultObj.getString("message");
//审核
JSONObject audit = new JSONObject();
audit.put("billid", UUID.randomUUID());
audit.put("AccId", AccId);
audit.put("cVoucherId", billCode);
logger.info("销售出库单审核:"+main.toString());
String resultAudit = U8Util.sengBillToU8(audit.toString(), "8000110022");
logger.info("销售出库单审核结果:"+result);
JSONObject resultObjA = JSON.parseObject(resultAudit);
boolean flagAudit = resultObjA.getBoolean("success");
// logger.info(resultObj.toString());
if(!flagAudit){
//如果审核失败需要调用删除接口回滚单据
JSONObject delete = new JSONObject();
delete.put("billid", UUID.randomUUID());
delete.put("AccId", AccId);
delete.put("cVoucherId", billCode);
//删除
String resultDelete = U8Util.sengBillToU8(delete.toString(), "8000110023");
//删除之后直接返回失败信息
return BaseU8Result.getFailureMessageEntity("新增正常但审核失败:::"+resultObjA.getString("message"));
}
}
return BaseU8Result.getSuccessMessageEntity(resultObj.getString("message"));
} catch (Exception e) {
//如果审核失败需要调用删除接口回滚单据
JSONObject delete = new JSONObject();
delete.put("billid", UUID.randomUUID());
delete.put("AccId", AccId);
delete.put("cVoucherId", billCode);
//删除
String resultDelete = U8Util.sengBillToU8(delete.toString(), "8000110023");
logger.info("新增失败:"+e.getMessage());
return BaseU8Result.getFailureMessageEntity("新增失败请联系U8管理员");
}
}
}

View File

@ -46,7 +46,7 @@ public class U8Util {
}
public static String sengBillToU8(String parm, String apiCode){
String baseUrl = "http://127.0.0.1:9990/kangarooDataCenterV3/entranceController/externalCallInterface";
String baseUrl = "http://127.0.0.1:9999/kangarooDataCenterV3/entranceController/externalCallInterface";
System.out.println("推送参数"+parm);
String result = HttpRequest.post(baseUrl)
.header("appId", "800011")//头信息多个头信息多次调用此方法即可