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 cusWaybills = new ArrayList<>(); //海关运单状态表集合 List cusWaybillStatues = new ArrayList<>(); //运单数据 List wayBillList = (List) 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 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 orderGoodsList = kmallOrderMapper.getOrderGoods(wayBill.getOrderNo()); if (orderGoodsList == null || orderGoodsList.size() <= 0){ logger.error("电子订单为空!"); return; } //海关运单商品集合 List 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; } }