对接吉客云代码

This commit is contained in:
yuqh 2025-08-07 14:20:15 +08:00
parent b24828951a
commit 2fc23bd4f0
10 changed files with 643 additions and 83 deletions

View File

@ -103,8 +103,8 @@ public class JeckYunGoodsdocOutToU8PluginInitializer extends PluginBaseEntity {
boolean flag = false; boolean flag = false;
String minDate = ""; String minDate = "";
String maxDate = ""; String maxDate = "";
// Date now = new Date(); Date now = new Date();
Date now = DateUtil.parse("2025-07-06 05:10:11"); // Date now = DateUtil.parse("2025-07-16 05:10:11");
boolean isLastDay = DateUtil.isSameDay(now, DateUtil.endOfMonth(now)); boolean isLastDay = DateUtil.isSameDay(now, DateUtil.endOfMonth(now));
// isLastDay = true; // isLastDay = true;
if (isLastDay) { if (isLastDay) {
@ -126,7 +126,7 @@ public class JeckYunGoodsdocOutToU8PluginInitializer extends PluginBaseEntity {
} else { } else {
LocalDate today = LocalDate.now(); LocalDate today = LocalDate.now();
int dayOfMonth = today.getDayOfMonth(); int dayOfMonth = today.getDayOfMonth();
dayOfMonth = 6; // dayOfMonth = 16;
boolean isTargetDate = (dayOfMonth == 6 || dayOfMonth == 11 || boolean isTargetDate = (dayOfMonth == 6 || dayOfMonth == 11 ||
dayOfMonth == 16 || dayOfMonth == 21 || dayOfMonth == 16 || dayOfMonth == 21 ||
dayOfMonth == 26); dayOfMonth == 26);
@ -147,9 +147,10 @@ public class JeckYunGoodsdocOutToU8PluginInitializer extends PluginBaseEntity {
logger.info(maxDate + " 23:59:59"); logger.info(maxDate + " 23:59:59");
} }
} }
// requestJson.put("minDate", minDate+ " 00:00:00"); requestJson.put("minDate", minDate+ " 00:00:00");
requestJson.put("minDate", "2025-07-01 00:00:00"); // requestJson.put("minDate", "2025-07-01 00:00:00");
requestJson.put("maxDate", maxDate+ " 23:59:59"); requestJson.put("maxDate", maxDate+ " 23:59:59");
// requestJson.put("maxDate", "2025-07-15 23:59:59");
if(flag){ if(flag){
logger.info("开始执行"+getPluginName()+requestJson.toString()); logger.info("开始执行"+getPluginName()+requestJson.toString());
goodsdocOutService.getJeckGoodsdocOutToU8(requestJson); goodsdocOutService.getJeckGoodsdocOutToU8(requestJson);

View File

@ -148,6 +148,27 @@ public class GoodsdocInServiceImpl extends BaseService<GoodsdocInEntity,String>
@Override @Override
public void getJeckGoodsdocInBak(JSONObject requestJson) { public void getJeckGoodsdocInBak(JSONObject requestJson) {
//备份物流信息
// //新增到备份表
// goodsdocInLogisticDao.saveLogisBak(logis);
// //在业务表删除数据
// goodsdocInLogisticDao.deleteByMainId(logisEntity);
//
// //备份明细信息
// //新增到备份表
// goodsdocInDetailDao.saveDetailsBak(details);
// //在业务表删除数据
// goodsdocInDetailDao.deleteByMainId(detailEntity);
//
//
// //备份主表信息
// //将表头数据新增到备份表
// goodsdocInDao.saveGoodsdocInBak(item);
// //删除业务表数据
// goodsdocInDao.deleteByRecId(recId);
GoodsdocInEntity goodsdocInEntity = new GoodsdocInEntity(); GoodsdocInEntity goodsdocInEntity = new GoodsdocInEntity();
goodsdocInEntity.setState("Y"); goodsdocInEntity.setState("Y");
//查询所有所有已经处理完成的出库单 //查询所有所有已经处理完成的出库单
@ -275,7 +296,8 @@ public class GoodsdocInServiceImpl extends BaseService<GoodsdocInEntity,String>
head.put("crdcode", "203");//入库类别编码 head.put("crdcode", "203");//入库类别编码
head.put("cmemo",cmemo);//TODO 这里填的是发货单的最早日期和最晚日期 head.put("cmemo",cmemo);//TODO 这里填的是发货单的最早日期和最晚日期
head.put("cwhcode", "04009");//仓库编码 todo 正式需要切换为04009 head.put("cwhcode", "04009");//仓库编码 todo 正式需要切换为04009
head.put("ddate", DateUtil.format(new Date(),"yyyy-MM-dd"));//销售类型 head.put("ddate", DateUtil.format(DateUtil.offsetDay(new Date(), -1), "yyyy-MM-dd"));//销售类型
// head.put("ddate", DateUtil.format(new Date(),"yyyy-MM-dd"));//销售类型
// head.put("ddate", "2025-05-31");//销售类型 // head.put("ddate", "2025-05-31");//销售类型
head.put("ccuscode", "99989922");//todo 正式需要切换未这个客户 head.put("ccuscode", "99989922");//todo 正式需要切换未这个客户
@ -298,7 +320,7 @@ public class GoodsdocInServiceImpl extends BaseService<GoodsdocInEntity,String>
details.put("iquantity",new BigDecimal(item.getQuantity()).subtract(new BigDecimal(item.getQuantity()).add(new BigDecimal(item.getQuantity())))); details.put("iquantity",new BigDecimal(item.getQuantity()).subtract(new BigDecimal(item.getQuantity()).add(new BigDecimal(item.getQuantity()))));
// details.put("iquantity", item.getQuantity());//数量 // details.put("iquantity", item.getQuantity());//数量
details.put("itaxrate",item.getTaxRate()); details.put("itaxrate",item.getTaxRate());
details.put("itaxrate","13");
body.add(details); body.add(details);
} }
} }
@ -320,7 +342,8 @@ public class GoodsdocInServiceImpl extends BaseService<GoodsdocInEntity,String>
head.put("ccuscode", "99989922");//todo 正式需要切换未这个客户 head.put("ccuscode", "99989922");//todo 正式需要切换未这个客户
// head.put("ccuscode", "01010918");//客户 // head.put("ccuscode", "01010918");//客户
head.put("cstcode", "11");//销售类型 head.put("cstcode", "11");//销售类型
head.put("ddate", DateUtil.format(new Date(),"yyyy-MM-dd"));//创建时间 // head.put("ddate", DateUtil.format(new Date(),"yyyy-MM-dd"));//创建时间
head.put("ddate", DateUtil.format(DateUtil.offsetDay(new Date(), -1), "yyyy-MM-dd"));//创建时间
// head.put("ddate", "2025-05-31");//创建时间 // head.put("ddate", "2025-05-31");//创建时间
jsonObject.put("head",head); jsonObject.put("head",head);
JSONArray body = new JSONArray(); JSONArray body = new JSONArray();
@ -338,7 +361,7 @@ public class GoodsdocInServiceImpl extends BaseService<GoodsdocInEntity,String>
details.put("isum",item.getTransHasTaxAmount()); details.put("isum",item.getTransHasTaxAmount());
details.put("iquantity",new BigDecimal(item.getQuantity()).subtract(new BigDecimal(item.getQuantity()).add(new BigDecimal(item.getQuantity())))); details.put("iquantity",new BigDecimal(item.getQuantity()).subtract(new BigDecimal(item.getQuantity()).add(new BigDecimal(item.getQuantity()))));
details.put("itaxrate",item.getTaxRate()); details.put("itaxrate",item.getTaxRate());
details.put("itaxrate","0.13"); details.put("itaxrate","13");
body.add(details); body.add(details);
}); });
} }

View File

@ -159,7 +159,7 @@ and goodsNo like '5%'
<!-- 查询 采用==查询 --> <!-- 查询 采用==查询 -->
<select id="entity_list_base_group" resultMap="get-entity-result" parameterType="com.hzya.frame.Jackyun.goodsdocout.entity.GoodsdocOutEntity"> <select id="entity_list_base_group" resultMap="get-entity-result" parameterType="com.hzya.frame.Jackyun.goodsdocout.entity.GoodsdocOutEntity">
select select
goodsNo,goodsName,unitName, case when d.u8_code is not null then d.u8_code else c.cinvcode end as goodsNo,case when c.cinvname is not null then c.cinvname else goodsName end as goodsName,case when d.sale_spec is not null then d.sale_spec else unitName end as unitName,
CAST(SUM( CAST(SUM(
CASE CASE
WHEN (ISNULL(c.cComUnitName,'')=b.unitName AND ISNUMERIC(c.ichangrate)=1) WHEN (ISNULL(c.cComUnitName,'')=b.unitName AND ISNUMERIC(c.ichangrate)=1)
@ -179,16 +179,16 @@ and goodsNo like '5%'
inner join contrast_warehouse cc on a.warehouseCode=cc.jeck_code inner join contrast_warehouse cc on a.warehouseCode=cc.jeck_code
left join contrast_inventory_big dd on b.goodsno = dd.invcode left join contrast_inventory_big dd on b.goodsno = dd.invcode
where a.inouttype = '201' where a.inouttype = '201'
and b.goodsNo like '5%' and state is null
<if test="warehouseCode != null and warehouseCode !='' ">and cc.u8_code = #{warehouseCode} </if> <if test="warehouseCode != null and warehouseCode !='' ">and cc.u8_code = #{warehouseCode} </if>
<if test="channelCode != null and channelCode !='' "> and bb.u8_code = #{channelCode}</if> <if test="channelCode != null and channelCode !='' "> and bb.u8_code = #{channelCode}</if>
and CAST(GETDATE() AS DATE)>inoutdate and CAST(GETDATE() AS DATE)>inoutdate
and c.cinvcode is not null and (goodsNo like '5%' or goodsNo like '7%' or d.u8_code like '5%' or d.u8_code like '7%')
/*and inoutdate >='2025-05-01 00:00:00' /*and inoutdate >='2025-05-01 00:00:00'
and inoutdate &lt; '2025-06-01 00:00:00'*/ and inoutdate &lt; '2025-06-01 00:00:00'*/
and inoutdate >= #{minDate} and inoutdate >= #{minDate}
and inoutdate &lt;= #{maxDate} and inoutdate &lt;= #{maxDate}
group by goodsNo,goodsName,unitName group by c.cinvcode,c.cinvname,unitName,d.u8_code,d.sale_spec,goodsName
</select> </select>
<!-- 新增 --> <!-- 新增 -->
<insert id="entity_insert" parameterType="com.hzya.frame.Jackyun.goodsdocout.entity.GoodsdocOutDetailEntity"> <insert id="entity_insert" parameterType="com.hzya.frame.Jackyun.goodsdocout.entity.GoodsdocOutDetailEntity">

View File

@ -148,13 +148,13 @@ order by inOutDate asc
inner join contrast_customer b on a.channelCode=b.jeck_code inner join contrast_customer b on a.channelCode=b.jeck_code
inner join contrast_warehouse c on a.warehouseCode=c.jeck_code inner join contrast_warehouse c on a.warehouseCode=c.jeck_code
where inouttype = '201' where inouttype = '201'
and state is null and state is null
and CAST(GETDATE() AS DATE)>inoutdate and CAST(GETDATE() AS DATE)>inoutdate
and inoutdate >= #{minDate} and inoutdate >= #{minDate}
and inoutdate &lt;= #{maxDate} and inoutdate &lt;= #{maxDate}
group by c.u8_code,b.u8_code,b.u8_accid group by c.u8_code,b.u8_code,b.u8_accid
</select> </select>
<!--通过主键修改方法--> <!--通过主键修改方法-->
<insert id="entity_insert" parameterType="com.hzya.frame.Jackyun.goodsdocout.entity.GoodsdocOutEntity"> <insert id="entity_insert" parameterType="com.hzya.frame.Jackyun.goodsdocout.entity.GoodsdocOutEntity">
INSERT INTO [dbo].[jeck_goodsdocout] ( INSERT INTO [dbo].[jeck_goodsdocout] (
<trim suffix="" suffixOverrides=","> <trim suffix="" suffixOverrides=",">

View File

@ -242,6 +242,7 @@ public class GoodsdocOutServiceImpl extends BaseService<GoodsdocOutEntity,String
//查询明细数据 //查询明细数据
List<GoodsdocOutDetailEntity> goodsdocOutDetailEntityList = goodsdocOutDetailDao.getGoodsdocOutDetailListGroup(item); List<GoodsdocOutDetailEntity> goodsdocOutDetailEntityList = goodsdocOutDetailDao.getGoodsdocOutDetailListGroup(item);
if (goodsdocOutDetailEntityList.size()==0){ if (goodsdocOutDetailEntityList.size()==0){
item.setState("Y"); item.setState("Y");
goodsdocOutDao.updateGoodsdocOut(item); goodsdocOutDao.updateGoodsdocOut(item);
return; return;
@ -308,7 +309,8 @@ public class GoodsdocOutServiceImpl extends BaseService<GoodsdocOutEntity,String
head.put("cbustype", "普通销售");//创建人 head.put("cbustype", "普通销售");//创建人
head.put("crdcode", "203");//入库类别编码 head.put("crdcode", "203");//入库类别编码
head.put("cwhcode", goodsdocOutEntity.getWarehouseCode());//仓库编码 todo 正式需要切换为04009 head.put("cwhcode", goodsdocOutEntity.getWarehouseCode());//仓库编码 todo 正式需要切换为04009
head.put("ddate", DateUtil.format(new Date(),"yyyy-MM-dd"));//销售类型 // head.put("ddate", DateUtil.format(new Date(),"yyyy-MM-dd"));//销售类型
head.put("ddate", DateUtil.format(DateUtil.offsetDay(new Date(), -1), "yyyy-MM-dd"));//销售类型
head.put("ccuscode", goodsdocOutEntity.getCustCode());//todo 正式需要切换未这个客户 head.put("ccuscode", goodsdocOutEntity.getCustCode());//todo 正式需要切换未这个客户
head.put("cDefine1", "多组织-采购订单");// head.put("cDefine1", "多组织-采购订单");//
// head.put("ccuscode", "01010918");//客户 // head.put("ccuscode", "01010918");//客户
@ -355,7 +357,8 @@ public class GoodsdocOutServiceImpl extends BaseService<GoodsdocOutEntity,String
head.put("ccuscode", goodsdocOutEntity.getChannelCode()); head.put("ccuscode", goodsdocOutEntity.getChannelCode());
// head.put("ccuscode", "01010918");//客户 // head.put("ccuscode", "01010918");//客户
head.put("cstcode", "11");//销售类型 head.put("cstcode", "11");//销售类型
head.put("ddate", DateUtil.format(new Date(), "yyyy-MM-dd"));//创建时间 // head.put("ddate", DateUtil.format(new Date(), "yyyy-MM-dd"));//创建时间
head.put("ddate", DateUtil.format(DateUtil.offsetDay(new Date(), -1), "yyyy-MM-dd"));//创建时间
jsonObject.put("head", head); jsonObject.put("head", head);
JSONArray body = new JSONArray(); JSONArray body = new JSONArray();
if (CollectionUtils.isNotEmpty(goodsdocOutDetailEntityList)) { if (CollectionUtils.isNotEmpty(goodsdocOutDetailEntityList)) {

View File

@ -56,16 +56,7 @@ public interface IDeliveryOrderService extends IBaseService<DeliveryOrderEntity,
* *
*/ */
U8ResultEntity Close(JSONObject parm); U8ResultEntity Close(JSONObject parm);
/**
*
* @content 发货单-关闭-针对CRM汇总发货定制
* 提供发货单整单关闭接口给CRM进行调用将该发货单明细涉及的发货单&红字发货单协同关闭验证是否出库如果出库则不允许整单关闭
* @className: Administrator
* @author laborer
* @date 2025-04-23 10:42
*
*/
U8ResultEntity consolidClose(JSONObject parm);
/** /**
* 删除发货单需要弃审1 不需要弃审2 * 删除发货单需要弃审1 不需要弃审2
@ -111,4 +102,24 @@ public interface IDeliveryOrderService extends IBaseService<DeliveryOrderEntity,
*/ */
U8ResultEntity u8DeliveryAutoOut(JSONObject requestJson); U8ResultEntity u8DeliveryAutoOut(JSONObject requestJson);
/**
*
* @content 发货单-关闭-针对CRM汇总发货定制
* 提供发货单整单关闭接口给CRM进行调用将该发货单明细涉及的发货单&红字发货单协同关闭验证是否出库如果出库则不允许整单关闭
* @className: Administrator
* @author laborer
* @date 2025-04-23 10:42
*
*/
U8ResultEntity consolidClose(JSONObject parm);
/**
*
* @content 合并发货单-部分作废
* @className: Administrator
* @author laborer
* @date 2025-07-25 11:01
*
*/
U8ResultEntity consolidClosePartial(JSONObject parm);
} }

View File

@ -7,21 +7,19 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DS;
import com.hzya.frame.Jackyun.contrast.customer.entity.CustomerEntity;
import com.hzya.frame.basedao.service.impl.BaseService; import com.hzya.frame.basedao.service.impl.BaseService;
import com.hzya.frame.crm.util.CrmUtil;
import com.hzya.frame.u8.delivery.dao.IDeliveryOrderDao; import com.hzya.frame.u8.delivery.dao.IDeliveryOrderDao;
import com.hzya.frame.u8.delivery.entity.DeliveryOrderEntity; import com.hzya.frame.u8.delivery.entity.DeliveryOrderEntity;
import com.hzya.frame.u8.delivery.service.IDeliveryOrderService; import com.hzya.frame.u8.delivery.service.IDeliveryOrderService;
import com.hzya.frame.u8.saleinv.dao.ISaleInvDao; import com.hzya.frame.u8.saleinv.dao.ISaleInvDao;
import com.hzya.frame.u8.saleinv.entity.SaleInvEntity; import com.hzya.frame.u8.saleinv.entity.SaleInvEntity;
import com.hzya.frame.u8.saleinv.service.ISaleInvService;
import com.hzya.frame.u8.saleout.service.ISaleOutService; import com.hzya.frame.u8.saleout.service.ISaleOutService;
import com.hzya.frame.u8.util.BaseU8Result; import com.hzya.frame.u8.util.BaseU8Result;
import com.hzya.frame.u8.util.U8ResultEntity; import com.hzya.frame.u8.util.U8ResultEntity;
import com.hzya.frame.u8.util.U8Util; import com.hzya.frame.u8.util.U8Util;
import com.hzya.frame.web.entity.BaseResult; import com.hzya.frame.web.entity.BaseResult;
import com.hzya.frame.web.entity.JsonResultEntity; import com.hzya.frame.web.entity.JsonResultEntity;
import lombok.val;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -30,8 +28,8 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.security.KeyPair;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -50,6 +48,8 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrderEntity,St
@Autowired @Autowired
private ISaleOutService saleOutService; private ISaleOutService saleOutService;
@Autowired @Autowired
private ISaleInvService saleInvService;
@Autowired
public void setDeliveryOrderDao(IDeliveryOrderDao dao) { public void setDeliveryOrderDao(IDeliveryOrderDao dao) {
this.deliveryOrderDao = dao; this.deliveryOrderDao = dao;
this.dao = dao; this.dao = dao;
@ -404,8 +404,8 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrderEntity,St
if ("98".equals(cinvcode)){ if ("98".equals(cinvcode)){
cinvcode = "9800"; cinvcode = "9800";
}else if ("99".equals(cinvcode)){ }else if ("99".equals(cinvcode)){
String cinvccode = dt1.getString("cInvCCode"); String cinvccode = dt1.getString("cInvCode");
String cinvcname = dt1.getString("cInvCName"); // String cinvcname = dt1.getString("voucherType");
//白酒 //白酒
String startStr = "050201"; String startStr = "050201";
@ -504,7 +504,7 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrderEntity,St
// {"code":1,"success":"true","message":"2012502250010"} // {"code":1,"success":"true","message":"2012502250010"}
return BaseU8Result.getSuccessMessageEntity(resultObj.getString("message")); return BaseU8Result.getSuccessMessageEntity(resultObj.getString("message"));
} catch (Exception e) { } catch (Exception e) {
if (dlId != null) { if (dlId != null && !"".equals(dlId)) {
//如果进入异常并且单据主键不为空也同样删除单据进行回滚 //如果进入异常并且单据主键不为空也同样删除单据进行回滚
JSONObject delete = new JSONObject(); JSONObject delete = new JSONObject();
delete.put("billid", UUID.randomUUID()); delete.put("billid", UUID.randomUUID());
@ -1021,6 +1021,258 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrderEntity,St
return null; return null;
} }
@Override
public U8ResultEntity consolidClosePartial(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());
}
JSONObject saleOutRed = new JSONObject();
//创建红字销售出库
try {
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(saleOutRed);
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 @Override
public U8ResultEntity deleteDelivery(JSONObject parm) { public U8ResultEntity deleteDelivery(JSONObject parm) {
JSONObject jsonObject = parm.getJSONObject("jsonStr"); JSONObject jsonObject = parm.getJSONObject("jsonStr");
@ -1929,16 +2181,17 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrderEntity,St
if(CollectionUtils.isEmpty(body)){ if(CollectionUtils.isEmpty(body)){
return BaseU8Result.getFailureMessageEntity("请传入发货单数据"); return BaseU8Result.getFailureMessageEntity("请传入发货单数据");
} }
int j = 1; int j = 0;
for(int i = 0 ; i < body.size() ; i++ ){ for(int i = 0 ; i < body.size() ; i++ ){
j++;
JSONObject discountObj = body.getJSONObject(i); JSONObject discountObj = body.getJSONObject(i);
JSONArray bodyArr = new JSONArray(); JSONArray bodyArr = new JSONArray();
bodyArr.add(discountObj); bodyArr.add(discountObj);
//拼接发货单信息按照明细行拆分 //拼接发货单信息按照明细行拆分
//组装发货单数据 //组装发货单数据红字
JSONObject deliveryObjR = bdingParm(head,bodyArr,AccCode,"redd",j); JSONObject deliveryObjR = bdingParm(head,bodyArr,AccId,"reds",j);
//调用U8接口生成发货单 //调用U8接口生成发货单
u8ResultEntity = addDelivery(jsonObject); u8ResultEntity = addDelivery(deliveryObjR);
flag = u8ResultEntity.issuccess(); flag = u8ResultEntity.issuccess();
if(flag){ if(flag){
successList.add(u8ResultEntity.getmessage()); successList.add(u8ResultEntity.getmessage());
@ -1946,24 +2199,27 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrderEntity,St
errorMsg.append(u8ResultEntity.getmessage()); errorMsg.append(u8ResultEntity.getmessage());
break; break;
} }
//组装字发货单数据 //组装字发货单数据
JSONObject deliveryObjB= bdingParm(head,bodyArr,AccCode,"blue",j); JSONObject deliveryObjB= bdingParm(head,bodyArr,AccId,"blue",j);
//调用U8接口生成发货单 //调用U8接口生成发货单
u8ResultEntity = addDelivery(jsonObject); u8ResultEntity = addDelivery(deliveryObjB);
flag = u8ResultEntity.issuccess(); flag = u8ResultEntity.issuccess();
if(flag){ if(flag){
successList.add(u8ResultEntity.getmessage()); successList.add(u8ResultEntity.getmessage());
JSONObject resultCode = new JSONObject(); JSONObject resultCode = new JSONObject();
resultCode.put("cdlcode",u8ResultEntity.getmessage()); resultCode.put("cdlcode",u8ResultEntity.getmessage());
resultCode.put("cdefine10",head.getString("cdefine10")); resultCode.put("cdefine10",head.getString("cdefine10"));
resultArr.add(u8ResultEntity.getmessage()); resultArr.add(resultCode);
}else{ }else{
errorMsg.append(u8ResultEntity.getmessage()); errorMsg.append(u8ResultEntity.getmessage());
break; break;
} }
} }
//组装明细汇总发货单数据 //组装明细汇总发货单数据
JSONObject deliveryObjC = bdingParm(head,body,AccCode,"",0); if(!flag){
return BaseU8Result.getFailureMessageEntity(errorMsg.toString());
}
JSONObject deliveryObjC = bdingParm(head,body,AccId,"",0);
//调用U8接口生成发货单 //调用U8接口生成发货单
u8ResultEntity = addDelivery(deliveryObjC); u8ResultEntity = addDelivery(deliveryObjC);
flag = u8ResultEntity.issuccess(); flag = u8ResultEntity.issuccess();
@ -1980,13 +2236,12 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrderEntity,St
result.put("cdefine10",head.getString("cdefine10")); result.put("cdefine10",head.getString("cdefine10"));
result.put("body",resultArr); result.put("body",resultArr);
//拼接回传json //拼接回传json
BaseU8Result.getSuccessMessageEntity(result); return BaseU8Result.getSuccessMessageEntity(result);
} catch (Exception e) { } catch (Exception e) {
logger.info("查询失败:"+e.getMessage()); logger.info("查询失败:"+e.getMessage());
return BaseU8Result.getFailureMessageEntity("查询失败请联系U8管理员"); return BaseU8Result.getFailureMessageEntity("查询失败请联系U8管理员");
} }
return null;
} }
/** /**
* *
@ -2006,14 +2261,33 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrderEntity,St
accMap.forEach((key,accCode)->{ accMap.forEach((key,accCode)->{
SaleInvEntity erdt = new SaleInvEntity(); SaleInvEntity erdt = new SaleInvEntity();
erdt.setDataSourceCode("YONYOUU8NEW"); erdt.setDataSourceCode("YONYOUU8NEW");
try { try {
String sqlSaleOutQty = "select m1.dlid,m1.cDLCode,m1.iQuantity,m1.saleOutQty,m1.cdefine10,m2.cDLCode as cDLCodeD,m2.dlidd from (\n" + String sqlSaleOutQty = "select DISTINCT m1.dlid,m1.cDLCode,m1.iQuantity,m1.saleOutQty,m1.cdefine10,m2.cDLCode as cDLCodeD,m2.dlid as dlidd from (\n" +
"select \n" + "select \n" +
"dl.cDLCode,\n" + "dl.cDLCode,\n" +
"dl.dlid,\n" + "dl.dlid,\n" +
"ISNULL(dls.iQuantity,0) as iQuantity,\n" + "ISNULL(dls.iQuantity,0) as iQuantity,\n" +
"ISNULL(rs32.saleOutQty,0) as saleOutQty,\n" + "ISNULL(rs32.saleOutQty,0) as saleOutQty,\n" +
"dl.cdefine10\n" + "SUBSTRING(dl.cdefine10, 1, LEN(dl.cdefine10) - 5)as cdefine10,\n" +
"dls.cInvCode\n" +
"from "+accCode+".dbo.DispatchList dl\n" +
"left join "+accCode+".dbo.DispatchLists dls on dls.DLID = dl.DLID \n" +
"left join ( select iDLsID,SUM(iQuantity) as saleOutQty from "+accCode+".dbo.rdrecords32 group by iDLsID )rs32 on rs32.iDLsID = dls.iDLsID \n" +
"where ISNULL(rs32.saleOutQty,0) = 0\n" +
"and dl.cdefine10 is not null\n" +
"and LEN(dl.cdefine10)>5\n" +
" and cmaker in ('CRM合并发货明细reds','CRM合并发货明细blue')\n" +
" )m2 \n" +
" left join (\n" +
" select \n" +
"dl.cDLCode,\n" +
"dl.dlid,\n" +
"ISNULL(dls.iQuantity,0) as iQuantity,\n" +
"ISNULL(rs32.saleOutQty,0) as saleOutQty,\n" +
"dl.cdefine10,\n" +
"dls.cInvCode,\n" +
"rs32.iDLsID \n" +
"from "+accCode+".dbo.DispatchList dl\n" + "from "+accCode+".dbo.DispatchList dl\n" +
"left join "+accCode+".dbo.DispatchLists dls on dls.DLID = dl.DLID \n" + "left join "+accCode+".dbo.DispatchLists dls on dls.DLID = dl.DLID \n" +
"left join ( select iDLsID,SUM(iQuantity) as saleOutQty from "+accCode+".dbo.rdrecords32 group by iDLsID )rs32 on rs32.iDLsID = dls.iDLsID \n" + "left join ( select iDLsID,SUM(iQuantity) as saleOutQty from "+accCode+".dbo.rdrecords32 group by iDLsID )rs32 on rs32.iDLsID = dls.iDLsID \n" +
@ -2022,23 +2296,9 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrderEntity,St
"and ISNULL(iQuantity,0)>0\n" + "and ISNULL(iQuantity,0)>0\n" +
"and dl.cdefine10 is not null\n" + "and dl.cdefine10 is not null\n" +
" and cmaker = 'CRM合并发货汇总'\n" + " and cmaker = 'CRM合并发货汇总'\n" +
")m1\n" + " )m1 on m1.cdefine10 = m2.cdefine10 and m1.cInvCode = m2.cInvCode\n" +
"left join (\n" + " where m1.iDLsID is not null\n" +
"select \n" + "\t";
"dl.cDLCode,\n" +
"dl.dlid,\n" +
"ISNULL(dls.iQuantity,0) as iQuantity,\n" +
"ISNULL(rs32.saleOutQty,0) as saleOutQty,\n" +
"SUBSTRING(dl.cdefine10, 1, LEN(dl.cdefine10) - 5)as cdefine10\n" +
"from "+accCode+".dbo.DispatchList dl\n" +
"left join "+accCode+".dbo.DispatchLists dls on dls.DLID = dl.DLID \n" +
"left join ( select iDLsID,SUM(iQuantity) as saleOutQty from "+accCode+".dbo.rdrecords32 group by iDLsID )rs32 on rs32.iDLsID = dls.iDLsID \n" +
"where ISNULL(rs32.saleOutQty,0) = 0\n" +
"and dl.cdefine10 is not null\n" +
"and LEN(dl.cdefine10)>5\n" +
" and cmaker in ('CRM合并发货明细red','CRM合并发货明细blue')\n" +
")m2 on m1.cdefine10 = m2.cdefine10 \n" +
"where m2.cDLCode is not null\n";
List<HashMap<String, Object>> saleOutQtyMap = saleInvDao.getU8BillData(sqlSaleOutQty,erdt); List<HashMap<String, Object>> saleOutQtyMap = saleInvDao.getU8BillData(sqlSaleOutQty,erdt);
//如果该返回不为空则证明有需要自动出库的数据执行自动出库逻辑 //如果该返回不为空则证明有需要自动出库的数据执行自动出库逻辑
//所有的发货单自动出库 //所有的发货单自动出库
@ -2060,6 +2320,8 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrderEntity,St
String cdefine10 = String.valueOf(selDis.get("cdefine10")); String cdefine10 = String.valueOf(selDis.get("cdefine10"));
//组装开票数据 //组装开票数据
JSONObject saleInvoice = bdingSaleInvoice(accCode,cdefine10,erdt); JSONObject saleInvoice = bdingSaleInvoice(accCode,cdefine10,erdt);
U8ResultEntity u8ResultInt = saleInvService.addSaleInt(saleInvoice);
} }
} }
@ -2088,14 +2350,128 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrderEntity,St
"and cmaker in ('CRM合并发货汇总','CRM合并发货明细red')"; "and cmaker in ('CRM合并发货汇总','CRM合并发货明细red')";
//得到本次需要处理的发货单 //得到本次需要处理的发货单
List<HashMap<String, Object>> cDLCodeList = saleInvDao.getU8BillData(dlSql,erdt); List<HashMap<String, Object>> cDLCodeList = saleInvDao.getU8BillData(dlSql,erdt);
JSONObject saleInvoice = new JSONObject();
StringBuffer sb = new StringBuffer();
JSONArray saleInvoiceArr = new JSONArray();
Integer i= 0;
if(CollectionUtils.isNotEmpty(cDLCodeList)){ if(CollectionUtils.isNotEmpty(cDLCodeList)){
cDLCodeList.forEach(map->{ for(HashMap<String, Object> map : cDLCodeList){
String cDLCode = String.valueOf(map.get("cdlcode"));
//通过发货单号分别查询出库信息 参照出库信息进行合并开票 //通过发货单号分别查询出库信息 参照出库信息进行合并开票
String cDLCode = String.valueOf(map.get("cdlcode"));
}); sb.append(cDLCode);
String saleOutSql = "select\n" +
"rd.id, \n" +
"rd.cvouchtype,\n" +
"rd.cstcode,\n" +
"rd.cdepcode,\n" +
"rd.cshipaddress,\n" +
"dl.itaxrate,\n" +
"-- rd.csbvcode,\n" +
"'汇总出库自动结0生成'cmaker,\n" +
"rd.ddate,\n" +
"rd.ccuscode,\n" +
"dl.ccusname,\n" +
"CustomerBank.cBranch as ccusbank,\n" +
"CustomerBank.cAccountNum as ccusaccount,\n" +
"dl.breturnflag,\n" +
"rd.cdlcode,\n" +
"rd.cmemo,\n" +
"Customer.cCusHand as cdefine12,\n" +
"rd.csource,\n" +
"rd.cbustype,\n" +
"rd.vt_id,\n" +
"dl.cexch_name,\n" +
" dl.iexchrate,\n" +
"'0' as csocode,\n" +
"dl.bcashsale,\n" +
"'1' as idisp\n" +
"from "+accCode+".dbo.RdRecord32 rd\n" +
"left join "+accCode+".dbo.DispatchList dl on rd.cbuscode = dl.cdlcode\n" +
"left join "+accCode+".dbo.Customer Customer on rd.ccuscode = Customer.ccuscode\n" +
"left join "+accCode+".dbo.CustomerBank on rd.ccuscode = CustomerBank.ccuscode and bDefault = '1'\n" +
"where cbuscode = '"+cDLCode+"'";
List<HashMap<String, Object>> saleOutList = null;
try {
saleOutList = saleInvDao.getU8BillData(dlSql,erdt);
} catch (Exception e) {
throw new RuntimeException(e);
}
if(CollectionUtils.isNotEmpty(saleOutList)){
//只要第一行作为发票头
saleInvoice.putAll(saleOutList.get(0));
for(HashMap<String, Object> out : saleOutList){
String id = String.valueOf(out.get("id"));
//获取出库明细用于生成发票行
String saleOutDetailSql = "select \n" +
"rds.idlsid,\n" +
"rds.AutoID as isaleoutid,\n" +
"rds.iquantity as foutquantity,\n" +
"invc.cInvCName as cinvcname,\n" +
"dls.cwhcode,\n" +
"rds.cinvcode,\n" +
"rds.iquantity,\n" +
"rds.inum,\n" +
"rds.iUnitCost iquotedprice,\n" +
"dls.iunitprice,\n" +
"dls.itaxunitprice,\n" +
"dls.imoney,\n" +
"dls.itax,\n" +
"dls.isum,\n" +
"dls.idiscount,\n" +
"dls.inatunitprice,\n" +
"dls.inatmoney,\n" +
"dls.inattax,\n" +
"dls.inatsum,\n" +
"dls.inatdiscount,\n" +
"dls.kl,\n" +
"dls.kl2,\n" +
"dls.itaxrate,\n" +
"dls.bsaleprice,\n" +
"dls.itb,\n" +
"dls.tbquantity,\n" +
"\n" +
"dls.cinvname,\n" +
"dls.bneedsign,\n" +
"dls.bgift,\n" +
"dls.bmpforderclosed,\n" +
"rds.bcosting,\n" +
"inv.cgroupcode,\n" +
"dls.cunitid,\n" +
"inv.igrouptype,\n" +
"dls.isosid,\n" +
"'001' as cfactorycode\n" +
"from "+accCode+".dbo.rdrecords32 rds\n" +
"left join "+accCode+".dbo.inventory inv on rds.cinvcode = inv.cinvcode\n" +
"left join "+accCode+".dbo.InventoryClass invc on inv.cinvccode = invc.cinvccode\n" +
"left join "+accCode+".dbo.DispatchLists dls on rds.iDLsID = dls.iDLsID\n" +
"where id = '"+id+"'";
List<HashMap<String, Object>> saleOutDetailList = null;
try {
saleOutDetailList = saleInvDao.getU8BillData(saleOutDetailSql,erdt);
} catch (Exception e) {
throw new RuntimeException(e);
}
for(HashMap<String, Object> outDetail : saleOutDetailList){
i++;
outDetail.put("cdlcode",out.get("cdlcode"));
outDetail.put("cbsaleout",out.get("cbsaleout"));
outDetail.put("iexchrate",out.get("iexchrate"));
outDetail.put("irowno",i);
saleInvoiceArr.add(outDetail);
};
};
}
}
} }
return null; saleInvoice.put("cdlcode",sb.toString().substring(0, sb.toString().length() - 1));
JSONObject jsonObject = new JSONObject();
jsonObject.put("AccId", accCode);
jsonObject.put("billid", "123");
jsonObject.put("head", saleInvoice);
jsonObject.put("body", saleInvoiceArr);
JSONObject result = new JSONObject();
result.put("jsonStr", jsonObject);
return result;
} }
public static List<HashMap<String, Object>> removeDuplicates(List<HashMap<String, Object>> list) { public static List<HashMap<String, Object>> removeDuplicates(List<HashMap<String, Object>> list) {
@ -2156,12 +2532,12 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrderEntity,St
jsonObject.put("AccId", AccId); jsonObject.put("AccId", AccId);
jsonObject.put("billid", "123"); jsonObject.put("billid", "123");
JSONObject head = new JSONObject(); JSONObject head = new JSONObject();
if("red".equals( type)){ if("reds".equals( type)){
head.put("brdflag", "0");//发货0退货1@
head.put("breturnflag", "0");//发货0退货1
}else{
head.put("brdflag", "1");//发货0退货1@ head.put("brdflag", "1");//发货0退货1@
head.put("breturnflag", "1"); head.put("breturnflag", "1");//发货0退货1
}else{
head.put("brdflag", "0");//发货0退货1@
head.put("breturnflag", "0");
} }
head.put("cbustype", headObj.getString("cbustype"));//业务类型 head.put("cbustype", headObj.getString("cbustype"));//业务类型
head.put("ddate", headObj.getString("ddate"));//业务类型 head.put("ddate", headObj.getString("ddate"));//业务类型
@ -2179,7 +2555,7 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrderEntity,St
head.put("cdefine10", headObj.getString("cdefine10"));//唯一字段因为汇总发货单是我们拆分多行明细的 那么我们拼接各自的标识 head.put("cdefine10", headObj.getString("cdefine10"));//唯一字段因为汇总发货单是我们拆分多行明细的 那么我们拼接各自的标识
}else{ }else{
head.put("cmaker", "CRM合并发货明细"+type);//创建人 head.put("cmaker", "CRM合并发货明细"+type);//创建人
head.put("cdefine10", headObj.getString("cdefine10")+j+type);//唯一字段因为汇总发货单是我们拆分多行明细的 那么我们拼接各自的标识 head.put("cdefine10", headObj.getString("cdefine10")+type+j);//唯一字段因为汇总发货单是我们拆分多行明细的 那么我们拼接各自的标识
} }
@ -2190,10 +2566,10 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrderEntity,St
bodyArr.forEach(line -> { bodyArr.forEach(line -> {
JSONObject lineObj = JSON.parseObject(line.toString()); JSONObject lineObj = JSON.parseObject(line.toString());
JSONObject details = new JSONObject(); JSONObject details = new JSONObject();
String iquantity = lineObj.getString("isum"); String iquantity = lineObj.getString("iquantity");
String isum = lineObj.getString("isum"); String isum = lineObj.getString("isum");
String idiscount = lineObj.getString("isum"); String idiscount = lineObj.getString("idiscount");
if("red".equals( type)){ if("reds".equals( type)){
details.put("iquantity",new BigDecimal(iquantity).subtract(new BigDecimal(iquantity).add(new BigDecimal(iquantity)))); details.put("iquantity",new BigDecimal(iquantity).subtract(new BigDecimal(iquantity).add(new BigDecimal(iquantity))));
details.put("isum",new BigDecimal(isum).subtract(new BigDecimal(isum).add(new BigDecimal(isum)))); details.put("isum",new BigDecimal(isum).subtract(new BigDecimal(isum).add(new BigDecimal(isum))));
details.put("idiscount",new BigDecimal(idiscount).subtract(new BigDecimal(idiscount).add(new BigDecimal(idiscount)))); details.put("idiscount",new BigDecimal(idiscount).subtract(new BigDecimal(idiscount).add(new BigDecimal(idiscount))));
@ -2202,6 +2578,7 @@ public class DeliveryOrderServiceImpl extends BaseService<DeliveryOrderEntity,St
details.put("isum",isum); details.put("isum",isum);
details.put("idiscount",idiscount); details.put("idiscount",idiscount);
} }
details.put("cunitid",lineObj.getString("cunitid")); //仓库
details.put("cwhcode",lineObj.getString("cwhcode")); //仓库 details.put("cwhcode",lineObj.getString("cwhcode")); //仓库
details.put("cdlcode",lineObj.getString("cdlcode")); //发货单号 details.put("cdlcode",lineObj.getString("cdlcode")); //发货单号
details.put("cinvcode",lineObj.getString("cinvcode")); //存货编码 details.put("cinvcode",lineObj.getString("cinvcode")); //存货编码

View File

@ -3,6 +3,7 @@ package com.hzya.frame.u8.saleinv.service;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.hzya.frame.basedao.service.IBaseService; import com.hzya.frame.basedao.service.IBaseService;
import com.hzya.frame.u8.saleinv.entity.SaleInvEntity; import com.hzya.frame.u8.saleinv.entity.SaleInvEntity;
import com.hzya.frame.u8.util.U8ResultEntity;
/** /**
* *
@ -24,4 +25,14 @@ public interface ISaleInvService extends IBaseService<SaleInvEntity,String> {
*/ */
void getU8SaleInvToCrm(JSONObject requestJson); void getU8SaleInvToCrm(JSONObject requestJson);
/**
*
* @content 销售发票-新增
* @param parm
* @className: Administrator
* @author laborer
* @date 2024-10-18 13:48
*
*/
U8ResultEntity addSaleInt(JSONObject parm);
} }

View File

@ -1,6 +1,7 @@
package com.hzya.frame.u8.saleinv.service.impl; package com.hzya.frame.u8.saleinv.service.impl;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
@ -16,6 +17,9 @@ import com.hzya.frame.u8.saleinv.entity.SaleInvEntity;
import com.hzya.frame.u8.saleinv.service.ISaleInvService; import com.hzya.frame.u8.saleinv.service.ISaleInvService;
import com.hzya.frame.u8.saleout.entity.SaleOutDetailEntity; import com.hzya.frame.u8.saleout.entity.SaleOutDetailEntity;
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.JsonResultEntity; import com.hzya.frame.web.entity.JsonResultEntity;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -24,7 +28,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
/** /**
@ -124,6 +132,132 @@ public class SaleInvServiceImpl extends BaseService<SaleInvEntity,String> implem
} }
} }
@Override
public U8ResultEntity addSaleInt(JSONObject parm) {
String billCode = "";
String SBVID = "";
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");
//如果有错误信息则返回错误信息
if(StrUtil.isNotEmpty(resultStr.toString())){
return BaseU8Result.getFailureMessageEntity(resultStr.toString());
}
SaleInvEntity U8Obj = new SaleInvEntity();
U8Obj.setDataSourceCode("YONYOUU8NEW");
//生成单号
String cSBVCodeSql = "SELECT ISNULL(max(CONVERT(DECIMAL(20, 0), cSBVCode))+1, CONVERT (VARCHAR (20),ddate,112) + '0001') as cSBVCode " +
"FROM "+AccCode+".dbo.SaleBillVouch " +
"WHERE cSBVCode LIKE CONVERT (VARCHAR (20),'"+DateUtil.format(jHead.getDate("ddate"),"yyyyMMdd")+"',112) + '%'" +
"AND len(cSBVCode) = 12 GROUP BY ddate";
List<HashMap<String, Object>> ccodeHashMaps = saleInvDao.getU8BillData(cSBVCodeSql,U8Obj);
if(CollectionUtils.isNotEmpty(ccodeHashMaps)){
HashMap<String, Object> ccodeObj= ccodeHashMaps.get(0);
jHead.put("csbvcode",ccodeObj.get("cSBVCode"));
}else{
jHead.put("csbvcode",DateUtil.format(jHead.getDate("ddate"),"yyyyMMdd")+"0001");
}
//todo 发货单表体
JSONArray body = new JSONArray();
JSONArray jBody = jsonObject.getJSONArray("body");
for (int i = 0; i < jBody.size(); i++) {
JSONObject jBodyObj = jBody.getJSONObject(i);
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("销售发票推送前参数:"+main.toString());
String result = U8Util.sengBillToU8(main.toString(), "8000110025");
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 SBVID from "+AccCode+".dbo.SaleBillVouch where cSBVCode = '"+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));
SBVID = dt3.getString("SBVID");
//审核
JSONObject audit = new JSONObject();
audit.put("billid", UUID.randomUUID());
audit.put("AccId", AccId);
audit.put("cVoucherId", SBVID);
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", SBVID);
//删除
String resultDelete = U8Util.sengBillToU8(delete.toString(), "8000110026");
//删除之后直接返回失败信息
return BaseU8Result.getFailureMessageEntity("新增正常但审核失败:::"+resultObjA.getString("message"));
}
}
// {"code":1,"success":"true","message":"2012502250010"}
return BaseU8Result.getSuccessMessageEntity(resultObj.getString("message"));
} catch (Exception e) {
if (SBVID != null) {
//如果进入异常并且单据主键不为空也同样删除单据进行回滚
JSONObject delete = new JSONObject();
delete.put("billid", UUID.randomUUID());
delete.put("AccId", AccId);
delete.put("cVoucherId", SBVID);
//删除
String resultDelete = U8Util.sengBillToU8(delete.toString(), "8000110028");
}
//删除之后直接返回失败信息
logger.info("新增失败:"+e.getMessage());
return BaseU8Result.getFailureMessageEntity("新增失败请联系U8管理员");
}
// return BaseU8Result.getSuccessMessageEntity("更新成功");
}
/** /**
* *
* @content 保存日志信息 * @content 保存日志信息

View File

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