935090232@qq.com
2021-04-13 94c48f85ee7956719cbc60d95fffa61f6bdcc81d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
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);
        }
    }
 
 
}