123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- package com.emato.ccnet.service.ccent.impl;
- import com.emato.ccnet.config.Merchant;
- import com.emato.ccnet.contants.Contants;
- import com.emato.ccnet.domain.ccnet.CusWaybill;
- import com.emato.ccnet.domain.ccnet.CusWaybillGoods;
- import com.emato.ccnet.domain.ccnet.CusWaybillStatus;
- import com.emato.ccnet.domain.kmall.OrderGoods;
- import com.emato.ccnet.domain.kmall.WayBill;
- import com.emato.ccnet.mapper.ccnet.CusWaybillGoodsMapper;
- import com.emato.ccnet.mapper.ccnet.CusWaybillMapper;
- import com.emato.ccnet.mapper.ccnet.CusWaybillStatusMapper;
- import com.emato.ccnet.mapper.kmall.KmallOrderMapper;
- import com.emato.ccnet.service.ccent.CusWaybillService;
- import com.emato.ccnet.snow.SnowflakeUtil;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- @Service
- public class CusWaybillImpl implements CusWaybillService{
- private static final Logger logger = LoggerFactory.getLogger(CusPaymentCollectImpl.class);
- @Autowired
- private CusWaybillMapper cusWaybillMapper;
- @Autowired
- private CusWaybillGoodsMapper cusWaybillGoodsMapper;
- @Autowired
- private CusWaybillStatusMapper cusWaybillStatusMapper;
- @Autowired
- private Merchant merchant;
- @Autowired
- private KmallOrderMapper kmallOrderMapper;
- /**
- * 运单初始化
- * @param list
- * @return
- */
- @Override
- public int addCusWaybill(List list) {
- //海关运单集合
- List<CusWaybill> cusWaybills = new ArrayList<>();
- //海关运单状态表集合
- List<CusWaybillStatus> cusWaybillStatues = new ArrayList<>();
- //运单数据
- List<WayBill> wayBillList = (List<WayBill>) list;
- for(WayBill wayBill:wayBillList){
- CusWaybill waybill = cusWaybillMapper.findCusWaybillByOrderNo(wayBill.getOrderNo());
- if(waybill == null){
- String cusWaybillSn = Contants.ZWSH + SnowflakeUtil.getSnowNextId();
- //海关运单
- CusWaybill cusWaybill = buildCusWaybill(wayBill,cusWaybillSn);
- cusWaybills.add(cusWaybill);
- //海关运单商品
- buildCusWaybillGoods(wayBill,cusWaybillSn);
- //海关运单状态
- CusWaybillStatus cusWaybillStatus = buildCusWaybillStatus(wayBill,cusWaybillSn);
- cusWaybillStatues.add(cusWaybillStatus);
- }
- }
- //批量插入海关运单
- if(cusWaybillMapper.insertCusWaybillItemBatch(cusWaybills) <= 0){
- logger.error("批量插入,海关运单记录全部失败");
- return 0;
- }
- //批量插入海关运单状态
- if(cusWaybillStatusMapper.insertCusWaybillStatusItemBatch(cusWaybillStatues) <= 0){
- logger.error("批量插入,海关运单状态记录全部失败");
- return 0;
- }
- return 1;
- }
- /**
- * 查询海关运单
- * @return
- */
- @Override
- public List<CusWaybill> findAllCusWaybill() {
- return cusWaybillMapper.findAllCusWaybill();
- }
- /**
- * 组装CusWaybillStatus
- * @param wayBill
- * @param cusWaybillSn
- * @return
- */
- private CusWaybillStatus buildCusWaybillStatus(WayBill wayBill, String cusWaybillSn) {
- CusWaybillStatus cusWaybillStatus = new CusWaybillStatus();
- String cusWaybillStatusSn = Contants.ZWSH + SnowflakeUtil.getSnowNextId();
- cusWaybillStatus.setCusWaybillStatusSn(cusWaybillStatusSn);
- cusWaybillStatus.setCusWaybillSn(cusWaybillSn);
- cusWaybillStatus.setMerchOrderType(Contants.MERCH_WAY_TYPE);
- cusWaybillStatus.setMerchOrderSn(wayBill.getOrderNo());
- cusWaybillStatus.setMerchSn(merchant.getMerchSn());
- cusWaybillStatus.setMerchName(merchant.getMerchName());
- cusWaybillStatus.setPlatSn(merchant.getPlatSn());
- cusWaybillStatus.setPlatName(merchant.getPlatName());
- cusWaybillStatus.setThirdPartyMerchCode(wayBill.getSellerId());
- cusWaybillStatus.setThirdPartyMerchName(wayBill.getSellerName());
- cusWaybillStatus.setSendStatus(Contants.INIT_STATUS);
- cusWaybillStatus.setRespStatus(Contants.INIT_STATUS);
- cusWaybillStatus.setCreaterSn(Contants.CREATER_NUMBER);
- cusWaybillStatus.setCreateTime(new Date());
- return cusWaybillStatus;
- }
- /**
- * 组装CusWaybillGoods
- * @param wayBill
- * @param cusWaybillSn
- * @return
- */
- private void buildCusWaybillGoods(WayBill wayBill, String cusWaybillSn) {
- List<OrderGoods> orderGoodsList = kmallOrderMapper.getOrderGoods(wayBill.getOrderNo());
- if (orderGoodsList == null || orderGoodsList.size() <= 0){
- logger.error("电子订单为空!");
- return;
- }
- //海关运单商品集合
- List<CusWaybillGoods> cusWaybillGoodes = new ArrayList<>();
- for (OrderGoods orderGoods:orderGoodsList) {
- CusWaybillGoods cusWaybillGoods = new CusWaybillGoods();
- String cusWaybillGoodsSn = Contants.ZWSH + SnowflakeUtil.getSnowNextId();
- cusWaybillGoods.setCusWaybillGoodsSn(cusWaybillGoodsSn);
- cusWaybillGoods.setCusWaybillSn(cusWaybillSn);
- cusWaybillGoods.setMerchOrderSn(wayBill.getOrderNo());
- cusWaybillGoods.setSku(orderGoods.getGoodsNo());
- cusWaybillGoods.setBuyUnitPrice(orderGoods.getSellPrice());
- cusWaybillGoods.setBuyQty(orderGoods.getGoodsNums());
- cusWaybillGoods.setCreaterSn(Contants.CREATER_NUMBER);
- cusWaybillGoods.setCreateTime(new Date());
- cusWaybillGoodes.add(cusWaybillGoods);
- }
- //批量插入海关运单商品
- if(cusWaybillGoodsMapper.insertCusWaybillGoodsItemBatch(cusWaybillGoodes) <= 0){
- logger.error("批量插入,海关运单商品记录全部失败");
- return;
- }
- }
- /**
- * 组装CusWaybill
- * @param wayBill
- * @param cusWaybillSn
- * @return
- */
- private CusWaybill buildCusWaybill(WayBill wayBill, String cusWaybillSn) {
- CusWaybill cusWaybill = new CusWaybill();
- cusWaybill.setCusWaybillSn(cusWaybillSn);
- cusWaybill.setMerchOrderSn(wayBill.getOrderNo());
- cusWaybill.setMerchSn(merchant.getMerchSn());
- cusWaybill.setMerchName(merchant.getMerchName());
- cusWaybill.setPlatSn(merchant.getPlatSn());
- cusWaybill.setPlatName(merchant.getPlatName());
- cusWaybill.setThirdPartyMerchCode(wayBill.getSellerId());
- cusWaybill.setThirdPartyMerchName(wayBill.getSellerName());
- cusWaybill.setPlaceOrderlTime(wayBill.getCreateTime());
- cusWaybill.setBuyerName(wayBill.getTrueName());
- cusWaybill.setBuyerMob(wayBill.getMobile());
- cusWaybill.setBuyerTel(wayBill.getTelephone());
- cusWaybill.setConsigneeIdCode(wayBill.getIdCode());
- cusWaybill.setConsigneeName(wayBill.getAcceptName());
- cusWaybill.setConsigneeMob(wayBill.getAcceptMobile());
- cusWaybill.setConsigneeTel(wayBill.getAcceptTelphone());
- cusWaybill.setConsigneeCountryCode(wayBill.getCountry());
- cusWaybill.setConsigneeProvinceCode(wayBill.getProvince());
- cusWaybill.setConsigneeProvince(wayBill.getProvinceName());
- cusWaybill.setConsigneeCityCode(wayBill.getCity());
- cusWaybill.setConsigneeCity(wayBill.getCityName());
- cusWaybill.setConsigneeDistrictCode(wayBill.getArea());
- cusWaybill.setConsigneeDistrict(wayBill.getAreaName());
- cusWaybill.setConsigneeAddress(wayBill.getAddress());
- cusWaybill.setConsigneeZipCode(wayBill.getZip());
- cusWaybill.setPayerName(wayBill.getTrueName());
- cusWaybill.setPayerIdCode(wayBill.getIdCode());
- cusWaybill.setPayerMob(wayBill.getMobile());
- cusWaybill.setPayerTel(wayBill.getTelephone());
- cusWaybill.setPayEntCusCode(merchant.getMerchantCustomsCode());
- cusWaybill.setPayNo(wayBill.getTradeNo());
- cusWaybill.setActuralPaid(wayBill.getRealAmount());
- cusWaybill.setPayTime(wayBill.getPayTime());
- cusWaybill.setCreaterSn(Contants.CREATER_NUMBER);
- cusWaybill.setCreateTime(new Date());
- return cusWaybill;
- }
- }
|