| package com.matrix.system.shopXcx.action; | 
|   | 
| import com.matrix.component.rabbitmq.RabiitMqTemplate; | 
| import com.matrix.core.anotations.RemoveRequestToken; | 
| import com.matrix.core.anotations.SaveRequestToken; | 
| import com.matrix.core.constance.MatrixConstance; | 
| import com.matrix.core.constance.SystemErrorCode; | 
| import com.matrix.core.constance.SystemMessageCode; | 
| import com.matrix.core.exception.GlobleException; | 
| import com.matrix.core.pojo.AjaxResult; | 
| import com.matrix.core.pojo.PaginationVO; | 
| import com.matrix.core.tools.ModelUtils; | 
| import com.matrix.core.tools.StringUtils; | 
| import com.matrix.core.tools.WebUtil; | 
| import com.matrix.system.common.bean.SysUsers; | 
| import com.matrix.system.common.bean.SystemDictionary; | 
| import com.matrix.system.common.constance.AppConstance; | 
| import com.matrix.system.common.dao.CustomerDataDictionaryDao; | 
| import com.matrix.system.common.dao.SystemDictionaryDao; | 
| import com.matrix.system.hive.action.BaseController; | 
| import com.matrix.system.shopXcx.api.tools.WxShopOrderUtil; | 
| import com.matrix.system.shopXcx.bean.ShopDeliveryInfo; | 
| import com.matrix.system.shopXcx.bean.ShopOrder; | 
| import com.matrix.system.shopXcx.dao.ShopDeliveryInfoDao; | 
| import com.matrix.system.shopXcx.dao.ShopLogisticsInfoDao; | 
| import com.matrix.system.shopXcx.dao.ShopOrderDao; | 
| import com.matrix.system.shopXcx.mqTask.MQTaskRouting; | 
| 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.PathVariable; | 
| import org.springframework.web.bind.annotation.RequestMapping; | 
| import org.springframework.web.bind.annotation.ResponseBody; | 
| import org.springframework.web.servlet.ModelAndView; | 
|   | 
| import java.util.Date; | 
| import java.util.HashMap; | 
| import java.util.List; | 
| import java.util.Map; | 
|   | 
| /** | 
|  * @author pengliang | 
|  * @description 发货信息表 | 
|  * @date 2019-06-17 17:54 | 
|  */ | 
| @Controller | 
| @RequestMapping(value = "admin/shopDeliveryInfo") | 
| public class ShopDeliveryInfoAction extends BaseController { | 
|   | 
|     @Autowired | 
|     private ShopDeliveryInfoDao shopDeliveryInfoDao; | 
|     @Autowired | 
|     private ShopOrderDao shopOrderDao; | 
|     @Autowired | 
|     private CustomerDataDictionaryDao dataDictionaryDao; | 
|   | 
|     @Autowired | 
|     SystemDictionaryDao systemDictionaryDao; | 
|   | 
|   | 
|     @Autowired | 
|     private WxShopOrderUtil wxShopOrderUtil; | 
|     @Autowired | 
|     private ShopLogisticsInfoDao shopLogisticsInfoDao; | 
|   | 
|     @Autowired | 
|     private RabiitMqTemplate rabiitMqTemplate; | 
|   | 
|     //记录编辑前的值Before_Edit_Value | 
|     public static final String BEV = "ShopDeliveryInfo_BEV"; | 
|   | 
|     @Value("${evn}") | 
|     private String evn; | 
|   | 
|     /** | 
|      * 列表显示 | 
|      */ | 
|     @RequestMapping(value = "/showList") | 
|     public @ResponseBody | 
|     AjaxResult showList(ShopDeliveryInfo shopDeliveryInfo, PaginationVO pageVo) { | 
|         SysUsers sysUsers = getMe(); | 
|         pageVo.setSort("create_time"); | 
|         pageVo.setOrder("desc"); | 
|         shopDeliveryInfo.setCompanyId(sysUsers.getCompanyId()); | 
|         List<ShopDeliveryInfo> dataList = shopDeliveryInfoDao.selectInPage(shopDeliveryInfo, pageVo); | 
|         AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, dataList, | 
|                 shopDeliveryInfoDao.selectTotalRecord(shopDeliveryInfo)); | 
|         return result; | 
|     } | 
|   | 
|     /** | 
|      * 开始发货 | 
|      * | 
|      * @return | 
|      */ | 
|     @RequestMapping(value = "/sendGoods/{id}") | 
|     public @ResponseBody | 
|     AjaxResult sendGoods(@PathVariable("id") Integer id) { | 
|         ShopOrder order = shopOrderDao.selectById(id); | 
|         if (ShopOrder.ORDER_STATUS_WAIT_SEND == order.getOrderStatus()) { | 
|             //构建需要修改订单信息Map | 
|             Map<String, Object> modifyMap = new HashMap<>(); | 
|             modifyMap.put("id", id); | 
|             modifyMap.put("orderStatus", ShopOrder.ORDER_STATUS_WAIT_RECEIVE); | 
|             shopOrderDao.updateByMap(modifyMap); | 
|             return new AjaxResult(AjaxResult.STATUS_SUCCESS, "发货成功"); | 
|         } else { | 
|             return new AjaxResult(AjaxResult.STATUS_FAIL, "订单不是待配送状态"); | 
|         } | 
|     } | 
|   | 
|     /** | 
|      * 完成配送 | 
|      * | 
|      * @return | 
|      */ | 
|     @RequestMapping(value = "/sendGoodsOver/{id}") | 
|     public @ResponseBody | 
|     AjaxResult sendGoodsOver(@PathVariable("id") Integer id) { | 
|         ShopOrder order = shopOrderDao.selectById(id); | 
|         if (ShopOrder.ORDER_STATUS_WAIT_RECEIVE == order.getOrderStatus()) { | 
|             //构建需要修改订单信息Map | 
|             Map<String, Object> modifyMap = new HashMap<>(); | 
|             modifyMap.put("id", id); | 
|             modifyMap.put("orderStatus", ShopOrder.ORDER_STATUS_WAIT_REMARK); | 
|             shopOrderDao.updateByMap(modifyMap); | 
|             return new AjaxResult(AjaxResult.STATUS_SUCCESS, "配送成功"); | 
|         } else { | 
|             return new AjaxResult(AjaxResult.STATUS_FAIL, "订单不是待收货状态"); | 
|         } | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 新增订单发货信息-带物流公司暂时用不到 | 
|      */ | 
|     @RequestMapping(value = "/addShopDeliveryInfo") | 
|     public @ResponseBody | 
|     AjaxResult addShopDeliveryInfo(ShopDeliveryInfo deliveryInfo) { | 
|         SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|         ShopDeliveryInfo param = new ShopDeliveryInfo(); | 
|         param.setOrderId(deliveryInfo.getOrderId()); | 
|         List<ShopDeliveryInfo> infoList = shopDeliveryInfoDao.selectByModel(param); | 
|         if (CollectionUtils.isEmpty(infoList) && infoList.size() != 1) { | 
|             return new AjaxResult(AjaxResult.STATUS_FAIL, "发货错误,请联系管理员!"); | 
|         } | 
|         ShopDeliveryInfo info = infoList.get(0); | 
|   | 
|         SystemDictionary comInfo = systemDictionaryDao.selectByCode(deliveryInfo.getComId()); | 
|         if (comInfo == null) { | 
|             return new AjaxResult(AjaxResult.STATUS_FAIL, "没有找到物流公司信息!"); | 
|         } | 
|         info.setLogisticsCompany(comInfo.getName()); | 
|         info.setLogisticsCompanyCode(comInfo.getCode()); | 
|         info.setWaybillNo(deliveryInfo.getWaybillNo()); | 
|         info.setUpdateBy(user.getSuName()); | 
|         info.setRemarks(deliveryInfo.getRemarks()); | 
|         info.setLogisticsStatus(AppConstance.LOGISTICS_STATUS_OF_RECEIVE); | 
|         info.setDeliveryTime(new Date()); | 
|         shopDeliveryInfoDao.updateByModel(info); | 
|   | 
|         //构建需要修改订单信息Map | 
|         Map<String, Object> modifyMap = new HashMap<>(); | 
|         modifyMap.put("id", deliveryInfo.getOrderId()); | 
|         modifyMap.put("orderStatus", ShopOrder.ORDER_STATUS_WAIT_RECEIVE); | 
|         shopOrderDao.updateByMap(modifyMap); | 
|   | 
|         //发送创建订单的消息 | 
|         rabiitMqTemplate.sendMsg(MQTaskRouting.ORDER_OUT_SOTORE+evn, shopOrderDao.selectById(deliveryInfo.getOrderId()).getOrderNo()); | 
|   | 
|   | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, "发货成功"); | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 修改 | 
|      */ | 
|     @RemoveRequestToken | 
|     @RequestMapping(value = "/modifyShopDeliveryInfo") | 
|     public @ResponseBody | 
|     AjaxResult modifyShopDeliveryInfo(ShopDeliveryInfo newShopDeliveryInfo) { | 
|         ShopDeliveryInfo oldShopDeliveryInfo = WebUtil.getSessionAttribute(BEV); | 
|         int i = 0; | 
|         Map<String, Object> modifyMap = null; | 
|         try { | 
|             if (!ModelUtils.isModified(oldShopDeliveryInfo, newShopDeliveryInfo)) { | 
|                 i = MatrixConstance.DML_SUCCESSS; | 
|             } | 
|             modifyMap = ModelUtils.comparePojo2Map(oldShopDeliveryInfo, newShopDeliveryInfo); | 
|         } catch (Exception e) { | 
|             throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, newShopDeliveryInfo); | 
|         } | 
|         if (modifyMap.size() > 0) { | 
|             modifyMap.put("id", oldShopDeliveryInfo.getId()); | 
|             shopDeliveryInfoDao.updateByMap(modifyMap); | 
|         } | 
|         i = MatrixConstance.DML_SUCCESSS; | 
|         WebUtil.removeSessionAttribute(BEV); | 
|         if (i > 0) { | 
|             return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.UPDATE_SUCCES, "发货信息表"); | 
|         } else { | 
|             throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL); | 
|         } | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 进入修改快递信息界面 | 
|      */ | 
|     @SaveRequestToken | 
|     @RequestMapping(value = "/editDeliveryInfoForm") | 
|     public ModelAndView editDeliveryInfoForm(Integer orderId) { | 
|         ModelAndView modelAndView = new ModelAndView("admin/shop/order-editSendPackage-form"); | 
|         ShopDeliveryInfo shopDeliveryInfo = shopDeliveryInfoDao.selectByOrderId(orderId); | 
|         modelAndView.addObject("obj", shopDeliveryInfo); | 
|         return modelAndView; | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 修改快递信息 | 
|      */ | 
|     @Transactional(rollbackFor = Exception.class) | 
|     @SaveRequestToken | 
|     @RequestMapping(value = "/editDeliveryInfo") | 
|     public @ResponseBody | 
|     AjaxResult editDeliveryInfo(ShopDeliveryInfo shopDeliveryInfo) { | 
|         Map<String, Object> modifyMap = new HashMap<>(); | 
|         modifyMap.put("id", shopDeliveryInfo.getId()); | 
|   | 
|         SystemDictionary systemDictionary = systemDictionaryDao.selectByCode(shopDeliveryInfo.getLogisticsCompanyCode()); | 
|         modifyMap.put("logisticsCompanyCode", shopDeliveryInfo.getLogisticsCompanyCode()); | 
|         modifyMap.put("logisticsCompany", systemDictionary.getName()); | 
|         modifyMap.put("waybillNo", shopDeliveryInfo.getWaybillNo()); | 
|         modifyMap.put("remarks", shopDeliveryInfo.getRemarks()); | 
|         modifyMap.put("logisticsStatus", 0); | 
|         modifyMap.put("pickUpStatus", 1); | 
|         shopDeliveryInfoDao.updateByMap(modifyMap); | 
|         shopLogisticsInfoDao.deleteByDelieryId(shopDeliveryInfo.getId()); | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, "修改成功"); | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 进入修改界面 | 
|      */ | 
|     @SaveRequestToken | 
|     @RequestMapping(value = "/editForm") | 
|     public ModelAndView editForm(Integer id) { | 
|         ShopDeliveryInfo shopDeliveryInfo = new ShopDeliveryInfo(); | 
|         ModelAndView modelAndView = new ModelAndView("admin/shopDeliveryInfo-form"); | 
|         if (id != null) { | 
|             shopDeliveryInfo = shopDeliveryInfoDao.selectById(id); | 
|             WebUtil.setSessionAttribute(BEV, shopDeliveryInfo); | 
|         } | 
|         modelAndView.addObject("obj", shopDeliveryInfo); | 
|         return modelAndView; | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 删除 | 
|      */ | 
|     @RequestMapping(value = "/del") | 
|     public @ResponseBody | 
|     AjaxResult del(String keys) { | 
|         List<String> ids = StringUtils.strToCollToString(keys, ","); | 
|         int i = shopDeliveryInfoDao.deleteByIds(ids); | 
|         if (i > 0) { | 
|             return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.DELETE_SUCCES, i); | 
|         } else { | 
|             throw new GlobleException(SystemErrorCode.DATA_DELETE_FAIL); | 
|         } | 
|     } | 
|   | 
|   | 
| } |