1
0

CusWaybillImpl.java 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. package com.emato.ccnet.service.ccent.impl;
  2. import com.emato.ccnet.config.Merchant;
  3. import com.emato.ccnet.contants.Contants;
  4. import com.emato.ccnet.domain.ccnet.CusWaybill;
  5. import com.emato.ccnet.domain.ccnet.CusWaybillGoods;
  6. import com.emato.ccnet.domain.ccnet.CusWaybillStatus;
  7. import com.emato.ccnet.domain.kmall.OrderGoods;
  8. import com.emato.ccnet.domain.kmall.WayBill;
  9. import com.emato.ccnet.mapper.ccnet.CusWaybillGoodsMapper;
  10. import com.emato.ccnet.mapper.ccnet.CusWaybillMapper;
  11. import com.emato.ccnet.mapper.ccnet.CusWaybillStatusMapper;
  12. import com.emato.ccnet.mapper.kmall.KmallOrderMapper;
  13. import com.emato.ccnet.service.ccent.CusWaybillService;
  14. import com.emato.ccnet.snow.SnowflakeUtil;
  15. import org.slf4j.Logger;
  16. import org.slf4j.LoggerFactory;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Service;
  19. import java.util.ArrayList;
  20. import java.util.Date;
  21. import java.util.List;
  22. @Service
  23. public class CusWaybillImpl implements CusWaybillService{
  24. private static final Logger logger = LoggerFactory.getLogger(CusPaymentCollectImpl.class);
  25. @Autowired
  26. private CusWaybillMapper cusWaybillMapper;
  27. @Autowired
  28. private CusWaybillGoodsMapper cusWaybillGoodsMapper;
  29. @Autowired
  30. private CusWaybillStatusMapper cusWaybillStatusMapper;
  31. @Autowired
  32. private Merchant merchant;
  33. @Autowired
  34. private KmallOrderMapper kmallOrderMapper;
  35. /**
  36. * 运单初始化
  37. * @param list
  38. * @return
  39. */
  40. @Override
  41. public int addCusWaybill(List list) {
  42. //海关运单集合
  43. List<CusWaybill> cusWaybills = new ArrayList<>();
  44. //海关运单状态表集合
  45. List<CusWaybillStatus> cusWaybillStatues = new ArrayList<>();
  46. //运单数据
  47. List<WayBill> wayBillList = (List<WayBill>) list;
  48. for(WayBill wayBill:wayBillList){
  49. CusWaybill waybill = cusWaybillMapper.findCusWaybillByOrderNo(wayBill.getOrderNo());
  50. if(waybill == null){
  51. String cusWaybillSn = Contants.ZWSH + SnowflakeUtil.getSnowNextId();
  52. //海关运单
  53. CusWaybill cusWaybill = buildCusWaybill(wayBill,cusWaybillSn);
  54. cusWaybills.add(cusWaybill);
  55. //海关运单商品
  56. buildCusWaybillGoods(wayBill,cusWaybillSn);
  57. //海关运单状态
  58. CusWaybillStatus cusWaybillStatus = buildCusWaybillStatus(wayBill,cusWaybillSn);
  59. cusWaybillStatues.add(cusWaybillStatus);
  60. }
  61. }
  62. //批量插入海关运单
  63. if(cusWaybillMapper.insertCusWaybillItemBatch(cusWaybills) <= 0){
  64. logger.error("批量插入,海关运单记录全部失败");
  65. return 0;
  66. }
  67. //批量插入海关运单状态
  68. if(cusWaybillStatusMapper.insertCusWaybillStatusItemBatch(cusWaybillStatues) <= 0){
  69. logger.error("批量插入,海关运单状态记录全部失败");
  70. return 0;
  71. }
  72. return 1;
  73. }
  74. /**
  75. * 查询海关运单
  76. * @return
  77. */
  78. @Override
  79. public List<CusWaybill> findAllCusWaybill() {
  80. return cusWaybillMapper.findAllCusWaybill();
  81. }
  82. /**
  83. * 组装CusWaybillStatus
  84. * @param wayBill
  85. * @param cusWaybillSn
  86. * @return
  87. */
  88. private CusWaybillStatus buildCusWaybillStatus(WayBill wayBill, String cusWaybillSn) {
  89. CusWaybillStatus cusWaybillStatus = new CusWaybillStatus();
  90. String cusWaybillStatusSn = Contants.ZWSH + SnowflakeUtil.getSnowNextId();
  91. cusWaybillStatus.setCusWaybillStatusSn(cusWaybillStatusSn);
  92. cusWaybillStatus.setCusWaybillSn(cusWaybillSn);
  93. cusWaybillStatus.setMerchOrderType(Contants.MERCH_WAY_TYPE);
  94. cusWaybillStatus.setMerchOrderSn(wayBill.getOrderNo());
  95. cusWaybillStatus.setMerchSn(merchant.getMerchSn());
  96. cusWaybillStatus.setMerchName(merchant.getMerchName());
  97. cusWaybillStatus.setPlatSn(merchant.getPlatSn());
  98. cusWaybillStatus.setPlatName(merchant.getPlatName());
  99. cusWaybillStatus.setThirdPartyMerchCode(wayBill.getSellerId());
  100. cusWaybillStatus.setThirdPartyMerchName(wayBill.getSellerName());
  101. cusWaybillStatus.setSendStatus(Contants.INIT_STATUS);
  102. cusWaybillStatus.setRespStatus(Contants.INIT_STATUS);
  103. cusWaybillStatus.setCreaterSn(Contants.CREATER_NUMBER);
  104. cusWaybillStatus.setCreateTime(new Date());
  105. return cusWaybillStatus;
  106. }
  107. /**
  108. * 组装CusWaybillGoods
  109. * @param wayBill
  110. * @param cusWaybillSn
  111. * @return
  112. */
  113. private void buildCusWaybillGoods(WayBill wayBill, String cusWaybillSn) {
  114. List<OrderGoods> orderGoodsList = kmallOrderMapper.getOrderGoods(wayBill.getOrderNo());
  115. if (orderGoodsList == null || orderGoodsList.size() <= 0){
  116. logger.error("电子订单为空!");
  117. return;
  118. }
  119. //海关运单商品集合
  120. List<CusWaybillGoods> cusWaybillGoodes = new ArrayList<>();
  121. for (OrderGoods orderGoods:orderGoodsList) {
  122. CusWaybillGoods cusWaybillGoods = new CusWaybillGoods();
  123. String cusWaybillGoodsSn = Contants.ZWSH + SnowflakeUtil.getSnowNextId();
  124. cusWaybillGoods.setCusWaybillGoodsSn(cusWaybillGoodsSn);
  125. cusWaybillGoods.setCusWaybillSn(cusWaybillSn);
  126. cusWaybillGoods.setMerchOrderSn(wayBill.getOrderNo());
  127. cusWaybillGoods.setSku(orderGoods.getGoodsNo());
  128. cusWaybillGoods.setBuyUnitPrice(orderGoods.getSellPrice());
  129. cusWaybillGoods.setBuyQty(orderGoods.getGoodsNums());
  130. cusWaybillGoods.setCreaterSn(Contants.CREATER_NUMBER);
  131. cusWaybillGoods.setCreateTime(new Date());
  132. cusWaybillGoodes.add(cusWaybillGoods);
  133. }
  134. //批量插入海关运单商品
  135. if(cusWaybillGoodsMapper.insertCusWaybillGoodsItemBatch(cusWaybillGoodes) <= 0){
  136. logger.error("批量插入,海关运单商品记录全部失败");
  137. return;
  138. }
  139. }
  140. /**
  141. * 组装CusWaybill
  142. * @param wayBill
  143. * @param cusWaybillSn
  144. * @return
  145. */
  146. private CusWaybill buildCusWaybill(WayBill wayBill, String cusWaybillSn) {
  147. CusWaybill cusWaybill = new CusWaybill();
  148. cusWaybill.setCusWaybillSn(cusWaybillSn);
  149. cusWaybill.setMerchOrderSn(wayBill.getOrderNo());
  150. cusWaybill.setMerchSn(merchant.getMerchSn());
  151. cusWaybill.setMerchName(merchant.getMerchName());
  152. cusWaybill.setPlatSn(merchant.getPlatSn());
  153. cusWaybill.setPlatName(merchant.getPlatName());
  154. cusWaybill.setThirdPartyMerchCode(wayBill.getSellerId());
  155. cusWaybill.setThirdPartyMerchName(wayBill.getSellerName());
  156. cusWaybill.setPlaceOrderlTime(wayBill.getCreateTime());
  157. cusWaybill.setBuyerName(wayBill.getTrueName());
  158. cusWaybill.setBuyerMob(wayBill.getMobile());
  159. cusWaybill.setBuyerTel(wayBill.getTelephone());
  160. cusWaybill.setConsigneeIdCode(wayBill.getIdCode());
  161. cusWaybill.setConsigneeName(wayBill.getAcceptName());
  162. cusWaybill.setConsigneeMob(wayBill.getAcceptMobile());
  163. cusWaybill.setConsigneeTel(wayBill.getAcceptTelphone());
  164. cusWaybill.setConsigneeCountryCode(wayBill.getCountry());
  165. cusWaybill.setConsigneeProvinceCode(wayBill.getProvince());
  166. cusWaybill.setConsigneeProvince(wayBill.getProvinceName());
  167. cusWaybill.setConsigneeCityCode(wayBill.getCity());
  168. cusWaybill.setConsigneeCity(wayBill.getCityName());
  169. cusWaybill.setConsigneeDistrictCode(wayBill.getArea());
  170. cusWaybill.setConsigneeDistrict(wayBill.getAreaName());
  171. cusWaybill.setConsigneeAddress(wayBill.getAddress());
  172. cusWaybill.setConsigneeZipCode(wayBill.getZip());
  173. cusWaybill.setPayerName(wayBill.getTrueName());
  174. cusWaybill.setPayerIdCode(wayBill.getIdCode());
  175. cusWaybill.setPayerMob(wayBill.getMobile());
  176. cusWaybill.setPayerTel(wayBill.getTelephone());
  177. cusWaybill.setPayEntCusCode(merchant.getMerchantCustomsCode());
  178. cusWaybill.setPayNo(wayBill.getTradeNo());
  179. cusWaybill.setActuralPaid(wayBill.getRealAmount());
  180. cusWaybill.setPayTime(wayBill.getPayTime());
  181. cusWaybill.setCreaterSn(Contants.CREATER_NUMBER);
  182. cusWaybill.setCreateTime(new Date());
  183. return cusWaybill;
  184. }
  185. }