| | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.google.gson.Gson; |
| | | import com.matrix.component.rabbitmq.RabiitMqTemplate; |
| | | import com.matrix.component.asyncmessage.AsyncMessageManager; |
| | | import com.matrix.core.anotations.RemoveRequestToken; |
| | | import com.matrix.core.anotations.SaveRequestToken; |
| | | import com.matrix.core.constance.MatrixConstance; |
| | |
| | | import com.matrix.system.shopXcx.bean.*; |
| | | import com.matrix.system.shopXcx.dao.*; |
| | | import com.matrix.system.shopXcx.dto.DiscountExplain; |
| | | import com.matrix.system.shopXcx.mqTask.MQTaskRouting; |
| | | import com.matrix.system.shopXcx.mqTask.AsyncMessageRouting; |
| | | import com.matrix.system.shopXcx.pojo.ShopOrderQueryPOJO; |
| | | import com.matrix.system.shopXcx.shopEnum.OrderStatusEnum; |
| | | import com.matrix.system.shopXcx.vo.LogisticsImportVo; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | |
| | | private SysShopInfoDao sysShopInfoDao; |
| | | @Autowired |
| | | private SysVipInfoService vipInfoService; |
| | | @Autowired |
| | | private RabiitMqTemplate rabiitMqTemplate; |
| | | |
| | | //记录编辑前的值Before_Edit_Value |
| | | public static final String BEV = "ShopOrder_BEV"; |
| | | |
| | | @Value("${evn}") |
| | | private String evn; |
| | | |
| | | public static final List<LogisticsImportVo> logisticsImportVoLists = new ArrayList<>(); |
| | | @Autowired |
| | | private AsyncMessageManager asyncMessageManager; |
| | | |
| | | |
| | | /** |
| | | * 导入快递单 |
| | | */ |
| | |
| | | AjaxResult ajaxResult = new AjaxResult(); |
| | | List<LogisticsImportVo> logisticsImportVos = logisticsImportFile(saveFile); |
| | | if(CollUtil.isNotEmpty(logisticsImportVos)){ |
| | | for(LogisticsImportVo logisticsImportVo : logisticsImportVos){ |
| | | infoRemind = infoRemind + logisticsImportVo.getRemark()+";"; |
| | | } |
| | | ajaxResult = AjaxResult.buildSuccessInstance(infoRemind); |
| | | ajaxResult = AjaxResult.buildSuccessInstance("部分数据导入失败"); |
| | | ajaxResult.setStatus(AjaxResult.STATUS_FAIL); |
| | | }else{ |
| | | ajaxResult = AjaxResult.buildSuccessInstance("导入成功"); |
| | | ajaxResult.setStatus(AjaxResult.STATUS_SUCCESS); |
| | | } |
| | | return ajaxResult; |
| | | } |
| | | |
| | | @RequestMapping(value = "/exportLogisticsImportExcel") |
| | | public void exportLogisticsImportExcel(HttpServletResponse res) { |
| | | OutputStream os = null; |
| | | try { |
| | | res.setCharacterEncoding("UTF-8"); |
| | | res.setHeader("content-type", "application/octet-stream;charset=UTF-8"); |
| | | res.setContentType("application/octet-stream;charset=UTF-8"); |
| | | Date date = new Date(); |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss"); |
| | | res.setHeader("Content-Disposition", "attachment;filename=" + |
| | | java.net.URLEncoder.encode("快递单导入列表" + dateFormat.format(date) + ".xls".trim(), "UTF-8")); |
| | | |
| | | os = res.getOutputStream(); |
| | | ExcelUtil.createWorkbookAtOutStream(ExcelVersion.V2007, disPoseLogisticsImportExcel(logisticsImportVoLists), os, true); |
| | | logisticsImportVoLists.clear(); |
| | | } catch (Exception e) { |
| | | LogUtil.error("快递单导入异常", e); |
| | | } finally { |
| | | if (os != null) { |
| | | try { |
| | | os.close(); |
| | | } catch (IOException e) { |
| | | LogUtil.error("关闭资源异常", e); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | private List<ExcelSheetPO> disPoseLogisticsImportExcel(List<LogisticsImportVo> logisticsImportVos) { |
| | | List<ExcelSheetPO> res = new ArrayList<>(); |
| | | ExcelSheetPO orderSheet = new ExcelSheetPO(); |
| | | orderSheet.setSheetName("快递单导入"); |
| | | orderSheet.setTitle("快递单导入失败列表"); |
| | | String[] header = new String[]{"订单编号", "物流公司编码", "物流公司名称", "快递单号", "失败原因"}; |
| | | orderSheet.setHeaders(header); |
| | | List<List<Object>> body = new ArrayList<>(); |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss"); |
| | | if(CollUtil.isNotEmpty(logisticsImportVos)){ |
| | | for (LogisticsImportVo logisticsImportVo : logisticsImportVos) { |
| | | List<Object> bodyItem = new ArrayList<>(); |
| | | bodyItem.add(logisticsImportVo.getOrderNo()); |
| | | bodyItem.add(logisticsImportVo.getLogisticsCompanyCode()); |
| | | bodyItem.add(logisticsImportVo.getLogisticsCompany()); |
| | | bodyItem.add(logisticsImportVo.getWaybillNo()); |
| | | bodyItem.add(logisticsImportVo.getFailReason()); |
| | | body.add(bodyItem); |
| | | } |
| | | } |
| | | orderSheet.setDataList(body); |
| | | res.add(orderSheet); |
| | | return res; |
| | | } |
| | | |
| | | public List<LogisticsImportVo> logisticsImportFile(File file) throws IOException { |
| | |
| | | * 订单处于【待付款】【待配送】【待收货】都可以导入 |
| | | * 其他状态生成一个提示 |
| | | */ |
| | | |
| | | LogisticsImportVo logisticsImportVo = new LogisticsImportVo(); |
| | | List<Object> objects = dataList.get(j); |
| | | ShopDeliveryInfo shopDeliveryInfo = new ShopDeliveryInfo(); |
| | | //订单编号 |
| | | String orderNo = objects.get(0).toString(); |
| | | ShopOrder shopOrder = shopOrderDao.selectShopOrderByOrderNo(orderNo); |
| | |
| | | String logisticsCompany = objects.get(2).toString(); |
| | | //快递单号 |
| | | String waybillNo = objects.get(3).toString(); |
| | | shopDeliveryInfo.setOrderNo(orderNo); |
| | | shopDeliveryInfo.setLogisticsCompanyCode(logisticsCompanyCode); |
| | | shopDeliveryInfo.setLogisticsCompany(logisticsCompany); |
| | | shopDeliveryInfo.setWaybillNo(waybillNo); |
| | | shopDeliveryInfo.setUpdateBy(sysUsers.getSuName()); |
| | | shopDeliveryInfo.setLogisticsStatus(AppConstance.LOGISTICS_STATUS_OF_RECEIVE); |
| | | shopDeliveryInfo.setDeliveryTime(new Date()); |
| | | shopDeliveryInfoDao.updateByModel(shopDeliveryInfo); |
| | | |
| | | //构建需要修改订单信息Map |
| | | Map<String, Object> modifyMap = new HashMap<>(); |
| | | modifyMap.put("id", shopOrder.getId()); |
| | | modifyMap.put("orderStatus", ShopOrder.ORDER_STATUS_WAIT_RECEIVE); |
| | | shopOrderDao.updateByMap(modifyMap); |
| | | ShopDeliveryInfo shopDeliveryInfo = new ShopDeliveryInfo(); |
| | | shopDeliveryInfo.setOrderId(shopOrder.getId()); |
| | | List<ShopDeliveryInfo> infoList = shopDeliveryInfoDao.selectByModel(shopDeliveryInfo); |
| | | if (CollectionUtils.isEmpty(infoList)) { |
| | | logisticsImportVo.setOrderNo(objects.get(0).toString()); |
| | | logisticsImportVo.setLogisticsCompanyCode(objects.get(1).toString()); |
| | | logisticsImportVo.setLogisticsCompany(objects.get(2).toString()); |
| | | logisticsImportVo.setWaybillNo(objects.get(3).toString()); |
| | | logisticsImportVo.setFailReason("未找到发货信息"); |
| | | logisticsImportVos.add(logisticsImportVo); |
| | | logisticsImportVoLists.add(logisticsImportVo); |
| | | }else{ |
| | | shopDeliveryInfo = infoList.get(0); |
| | | shopDeliveryInfo.setOrderNo(orderNo); |
| | | shopDeliveryInfo.setLogisticsCompanyCode(logisticsCompanyCode); |
| | | shopDeliveryInfo.setLogisticsCompany(logisticsCompany); |
| | | shopDeliveryInfo.setWaybillNo(waybillNo); |
| | | shopDeliveryInfo.setUpdateBy(sysUsers.getSuName()); |
| | | shopDeliveryInfo.setLogisticsStatus(AppConstance.LOGISTICS_STATUS_OF_RECEIVE); |
| | | shopDeliveryInfo.setDeliveryTime(new Date()); |
| | | shopDeliveryInfoDao.updateByModel(shopDeliveryInfo); |
| | | |
| | | //发送创建订单的消息 |
| | | rabiitMqTemplate.sendMsg(MQTaskRouting.ORDER_OUT_SOTORE+evn, orderNo); |
| | | //构建需要修改订单信息Map |
| | | Map<String, Object> modifyMap = new HashMap<>(); |
| | | modifyMap.put("id", shopOrder.getId()); |
| | | modifyMap.put("orderStatus", ShopOrder.ORDER_STATUS_WAIT_RECEIVE); |
| | | shopOrderDao.updateByMap(modifyMap); |
| | | |
| | | //发送创建订单的消息 |
| | | asyncMessageManager.sendMsg(AsyncMessageRouting.ORDER_OUT_SOTORE ,"orderNo=%s"); |
| | | |
| | | } |
| | | }else{ |
| | | LogisticsImportVo logisticsImportVo = new LogisticsImportVo(); |
| | | logisticsImportVo.setWaybillNo(orderNo); |
| | | logisticsImportVo.setColNum(j); |
| | | logisticsImportVo.setRemark("第"+j+"行导入失败"); |
| | | logisticsImportVos.add(logisticsImportVo); |
| | | if(ObjectUtil.isEmpty(shopOrder)){ |
| | | logisticsImportVo.setOrderNo(objects.get(0).toString()); |
| | | logisticsImportVo.setLogisticsCompanyCode(objects.get(1).toString()); |
| | | logisticsImportVo.setLogisticsCompany(objects.get(2).toString()); |
| | | logisticsImportVo.setWaybillNo(objects.get(3).toString()); |
| | | logisticsImportVo.setFailReason("未找到订单信息"); |
| | | logisticsImportVos.add(logisticsImportVo); |
| | | logisticsImportVoLists.add(logisticsImportVo); |
| | | }else if(shopOrder.getOrderStatus() != ShopOrder.ORDER_STATUS_WAIT_SEND || |
| | | shopOrder.getOrderStatus() != ShopOrder.ORDER_STATUS_WAIT_RECEIVE ){ |
| | | logisticsImportVo.setOrderNo(objects.get(0).toString()); |
| | | logisticsImportVo.setLogisticsCompanyCode(objects.get(1).toString()); |
| | | logisticsImportVo.setLogisticsCompany(objects.get(2).toString()); |
| | | logisticsImportVo.setWaybillNo(objects.get(3).toString()); |
| | | logisticsImportVo.setFailReason("订单状态不允许发货"); |
| | | logisticsImportVos.add(logisticsImportVo); |
| | | logisticsImportVoLists.add(logisticsImportVo); |
| | | }else{ |
| | | logisticsImportVo.setOrderNo(objects.get(0).toString()); |
| | | logisticsImportVo.setLogisticsCompanyCode(objects.get(1).toString()); |
| | | logisticsImportVo.setLogisticsCompany(objects.get(2).toString()); |
| | | logisticsImportVo.setWaybillNo(objects.get(3).toString()); |
| | | logisticsImportVo.setFailReason("导入失败"); |
| | | logisticsImportVos.add(logisticsImportVo); |
| | | logisticsImportVoLists.add(logisticsImportVo); |
| | | } |
| | | } |
| | | } |
| | | } |