package com.fuzamei.web; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import com.fuzamei.constant.HintMSG; import com.fuzamei.constant.Role; import com.fuzamei.constant.Status; import com.fuzamei.entity.Orders; import com.fuzamei.entity.Params; import com.fuzamei.entity.TallyOrder; import com.fuzamei.service.CargoTallyService; import com.fuzamei.service.OrderService; import com.fuzamei.service.UserAuthoricationService; import com.fuzamei.util.JSONUtil; import com.fuzamei.util.PageDTO; import com.fuzamei.util.ReadConfUtil; import com.fuzamei.util.ValidationUtil; @RestController @RequestMapping(path="/cargoTally") public class CargoTallyAction { @Autowired private CargoTallyService cargoTallyService; @Autowired private UserAuthoricationService userAuthoricationService; @Autowired private HttpServletRequest req; @Autowired private OrderService orderService; /** * * @Title: queryOrdersByReceiver * @Description: TODO(收货员查询订单信息) { "tokenId":"xxx", "page":"1", "orderId":"", "carNo":"", "startTime":"", "endTime":"" } * @params @return 设定文件 * @return Map 返回类型 * @author ylx * @date 2018年1月26日 下午2:12:02 * @throws */ @RequestMapping(value="/queryOrdersByReceiver",method=RequestMethod.POST) public Map queryOrdersByReceiver(@RequestBody Params params){ try { String userId = req.getHeader("Authorization").split("&")[1]; userAuthoricationService.queryUserAuthority(ValidationUtil.checkAndAssignInt(userId), Role.STOCKER); int page = ValidationUtil.checkMinAndAssignInt(params.getPage(), 1); int rowNum = ValidationUtil.checkMinAndAssignInt(params.getRowNum(), 1); Long startTime=ValidationUtil.checkAndAssignDefaultLong(params.getStartTime(), 0L); Long endTime=ValidationUtil.checkAndAssignDefaultLong(params.getEndTime(), Long.MAX_VALUE); params.setStartTime(startTime); if(startTime<=endTime) params.setEndTime(endTime); else params.setEndTime(Long.MAX_VALUE); params.setStartPage((page - 1) * rowNum); params.setRowNum(rowNum); PageDTO pageDto = cargoTallyService.queryOrdersByReceiver(params); return JSONUtil.getJsonMap(200, true, HintMSG.QUERY_SUCCESS, pageDto); } catch (Exception e) { return JSONUtil.getJsonMap(500, false, HintMSG.QUERY_FAIL+":"+e.getMessage(), null); } } /** * * @Title: searchNewOrderByOrderId * @Description: TODO(售货员根据订单号点击下一步查询最新的点货订单) { "tokenId":"", "orderId":"" } * @params @return 设定文件 * @return Map 返回类型 * @author ylx * @date 2018年1月26日 下午2:24:02 * @throws */ @RequestMapping(value="/searchNewOrderByOrderId",method=RequestMethod.POST) public Map searchNewOrderByOrderId(@RequestBody Params params){ try { String userId = req.getHeader("Authorization").split("&")[1]; userAuthoricationService.queryUserAuthority(ValidationUtil.checkAndAssignInt(userId), Role.STOCKER); Orders order = orderService.queryFullOrderByOrderId(ValidationUtil.checkAndAssignInt(params.getOrderId())); if(order==null) throw new RuntimeException("订单不存在"); if(!Status.DELIVERING.equals(order.getStatusId())) throw new RuntimeException("非法操作"); params.setOrder(order); TallyOrder tallyOrder=cargoTallyService.searchNewOrderByOrderId(params); return JSONUtil.getJsonMap(200, true, HintMSG.QUERY_SUCCESS, tallyOrder); } catch (Exception e) { return JSONUtil.getJsonMap(500, false, HintMSG.QUERY_FAIL+":"+e.getMessage(), null); } } /** * * @Title: confirmOrReject * @Description: TODO(收货员点击确认点货或拒收操作) { "tokenId":"", "orderId":"", "confirmId":"" } * @params @return 设定文件 * @return Map 返回类型 * @author ylx * @date 2018年1月26日 下午2:35:06 * @throws */ @RequestMapping(value="/confirmOrReject",method=RequestMethod.POST) public Map confirmOrReject(@RequestBody Params params){ try { String userId = req.getHeader("Authorization").split("&")[1]; userAuthoricationService.queryUserAuthority(ValidationUtil.checkAndAssignInt(userId), Role.STOCKER); ValidationUtil.checkRangeAndAssignInt(params.getConfirmId(), 0, 1);//确认id只能是0和1 Orders order = orderService.queryFullOrderByOrderId(ValidationUtil.checkAndAssignInt(params.getOrderId())); if(order==null) throw new RuntimeException("订单不存在"); if(!Status.DELIVERING.equals(order.getStatusId())) throw new RuntimeException("非法操作"); cargoTallyService.confirmOrReject(params); return JSONUtil.getJsonMap(200, true, HintMSG.OPERATION_SUCCESS, null); } catch (Exception e) { return JSONUtil.getJsonMap(500, false, HintMSG.OPERATION_FAIL+":"+e.getMessage(), null); } } /** * * @Title: orderTracking * @Description: TODO(收货员查询订单跟踪信息) { "tokenId":"", "orderId":"" } * @params @return 设定文件 * @return Map 返回类型 * @author ylx * @date 2018年1月26日 下午2:48:12 * @throws */ @RequestMapping(value="/orderTracking",method=RequestMethod.POST) public Map orderTracking(@RequestBody Params params){ try { String userId = req.getHeader("Authorization").split("&")[1]; userAuthoricationService.queryUserAuthority(ValidationUtil.checkAndAssignInt(userId),Role.STOCKER);//检测当前操作用户权限 Orders order = orderService.queryFullOrderByOrderId(ValidationUtil.checkAndAssignInt(params.getOrderId())); if(!params.getUserId().equals(order.getReceiverId())) throw new RuntimeException("无权查看"); params.setOrder(order); Map map = cargoTallyService.orderTracking(params); return JSONUtil.getJsonMap(200, true, HintMSG.QUERY_SUCCESS, map); } catch (Exception e) { return JSONUtil.getJsonMap(500, false, HintMSG.QUERY_FAIL+":"+e.getMessage(), null); } } }