OrdersIssueAction.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. package com.fuzamei.web;
  2. import java.util.List;
  3. import java.util.Map;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.beans.factory.annotation.Value;
  6. import org.springframework.web.bind.annotation.RequestBody;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import org.springframework.web.bind.annotation.RequestMethod;
  9. import org.springframework.web.bind.annotation.RestController;
  10. import com.fuzamei.constant.HintMSG;
  11. import com.fuzamei.constant.Role;
  12. import com.fuzamei.constant.Status;
  13. import com.fuzamei.entity.Box;
  14. import com.fuzamei.entity.Orders;
  15. import com.fuzamei.entity.Param;
  16. import com.fuzamei.entity.UserDetail;
  17. import com.fuzamei.service.BoxService;
  18. import com.fuzamei.service.OrderService;
  19. import com.fuzamei.service.OrdersIssueService;
  20. import com.fuzamei.service.UserAuthoricationService;
  21. import com.fuzamei.util.JSONUtil;
  22. import com.fuzamei.util.PageDTO;
  23. import com.fuzamei.util.ReadConfUtil;
  24. import com.fuzamei.util.ValidationUtil;
  25. @RestController
  26. @RequestMapping("/ordersIssue")
  27. public class OrdersIssueAction {
  28. @Autowired
  29. private OrdersIssueService ordersIssueService;
  30. @Autowired
  31. private UserAuthoricationService userAuthoricationService;
  32. @Autowired
  33. private OrderService orderService;
  34. @Autowired
  35. private BoxService boxService;
  36. private static final Integer ROWNUM=Integer.parseInt(ReadConfUtil.getProperty("rowNum"));
  37. public static final String ORDER_ID_PATTERN="\\d{8}";
  38. public static void main(String[] args) {
  39. System.out.println("\\d{8}");
  40. }
  41. /**
  42. *
  43. * @Title: queryOrdersByPlanner
  44. * @Description: TODO(由计划员查询订单信息)
  45. {
  46. "userId":"xxx",
  47. "page":"1",
  48. "supplierName":"",
  49. "boxNo":"",
  50. "startTime":"",
  51. "endTime":""
  52. }
  53. * @return Map<String,Object> 返回类型
  54. * @author ylx
  55. * @date 2018年1月24日 下午8:58:24
  56. * @throws
  57. */
  58. @RequestMapping(value="/queryOrdersByPlanner",method=RequestMethod.POST)
  59. public Map<String, Object> queryOrdersByPlanner(@RequestBody Param param){
  60. try {
  61. userAuthoricationService.queryUserAuthority(ValidationUtil.checkAndAssignInt(param.getUserId()), Role.PLANNER);
  62. int page = ValidationUtil.checkMinAndAssignInt(param.getPage(), 1);
  63. Long startTime=ValidationUtil.checkAndAssignDefaultLong(param.getStartTime(), 0L);
  64. Long endTime=ValidationUtil.checkAndAssignDefaultLong(param.getEndTime(), Long.MAX_VALUE);
  65. param.setStartTime(startTime);
  66. if(startTime<=endTime) param.setEndTime(endTime);
  67. else param.setEndTime(Long.MAX_VALUE);
  68. param.setStartPage((page - 1) * ROWNUM);
  69. param.setRowNum(ROWNUM);
  70. PageDTO pageDto = ordersIssueService.queryOrdersByPlanner(param);
  71. return JSONUtil.getJsonMap(200, true, HintMSG.QUERY_SUCCESS, pageDto);
  72. } catch (Exception e) {
  73. return JSONUtil.getJsonMap(500, false, HintMSG.QUERY_FAIL+":"+e.getMessage(), null);
  74. }
  75. }
  76. /**
  77. *
  78. * @Title: queryOrdersBySupplier
  79. * @Description: TODO(供应商查询订单信息)
  80. {
  81. "userId":"",
  82. "page":"1",
  83. "orderId":"",
  84. "boxNo":"",
  85. "statusId":"",
  86. "startTime":"",
  87. "endTime":""
  88. }
  89. * @param @return 设定文件
  90. * @return Map<String,Object> 返回类型
  91. * @author ylx
  92. * @date 2018年1月26日 上午10:34:41
  93. * @throws
  94. */
  95. @RequestMapping(value="/queryOrdersBySupplier",method=RequestMethod.POST)
  96. public Map<String, Object> queryOrdersBySupplier(@RequestBody Param param){
  97. try {
  98. userAuthoricationService.queryUserAuthority(ValidationUtil.checkAndAssignInt(param.getUserId()), Role.SUPPLIER);
  99. int page = ValidationUtil.checkMinAndAssignInt(param.getPage(), 1);
  100. Long startTime=ValidationUtil.checkAndAssignDefaultLong(param.getStartTime(), 0L);
  101. Long endTime=ValidationUtil.checkAndAssignDefaultLong(param.getEndTime(), Long.MAX_VALUE);
  102. param.setStartTime(startTime);
  103. if(startTime<=endTime) param.setEndTime(endTime);
  104. else param.setEndTime(Long.MAX_VALUE);
  105. param.setStartPage((page - 1) * ROWNUM);
  106. param.setRowNum(ROWNUM);
  107. PageDTO pageDto = ordersIssueService.queryOrdersBySupplier(param);
  108. return JSONUtil.getJsonMap(200, true, HintMSG.QUERY_SUCCESS, pageDto);
  109. } catch (Exception e) {
  110. return JSONUtil.getJsonMap(500, false, HintMSG.QUERY_FAIL+":"+e.getMessage(), null);
  111. }
  112. }
  113. /**
  114. *
  115. * @Title: Consignment
  116. * @Description: TODO(供应商点击发货这个动作)
  117. {
  118. "userId":"xxx",
  119. "orderId":"",
  120. "carrierId":""
  121. }
  122. * @param @return 设定文件
  123. * @return Map<String,Object> 返回类型
  124. * @author ylx
  125. * @date 2018年1月26日 上午11:07:58
  126. * @throws
  127. */
  128. @RequestMapping(value="/consignment",method=RequestMethod.POST)
  129. public Map<String, Object> consignment(@RequestBody Param param){
  130. try {
  131. userAuthoricationService.queryUserAuthority(ValidationUtil.checkAndAssignInt(param.getUserId()), Role.SUPPLIER);
  132. userAuthoricationService.queryUserAuthority(ValidationUtil.checkAndAssignInt(param.getCarrierId()), Role.CARRIER);
  133. Orders order = orderService.queryFullOrderByOrderId(ValidationUtil.checkAndAssignInt(param.getOrderId()));
  134. if(order==null) throw new RuntimeException("订单不存在");
  135. if(!Status.UNSEND.equals(order.getStatusId())) throw new RuntimeException(HintMSG.ILLEGAL);
  136. if(!param.getUserId().equals(order.getSupplierId())) throw new RuntimeException(HintMSG.NO_AUTH);
  137. ordersIssueService.consignment(param);
  138. return JSONUtil.getJsonMap(200, true, HintMSG.OPERATION_SUCCESS, null);
  139. } catch (Exception e) {
  140. return JSONUtil.getJsonMap(500, false, HintMSG.OPERATION_FAIL+":"+e.getMessage(), null);
  141. }
  142. }
  143. /**
  144. *
  145. * @Title: addOrder
  146. * @Description: TODO(由计划员增加新订单)
  147. {
  148. "userId":"xxx",
  149. "orderId":"",
  150. "supplierId":"",
  151. "partNo":"",
  152. "boxNo":"",
  153. "inboxQty":""
  154. }
  155. * @param @return 设定文件
  156. * @return Map<String,Object> 返回类型
  157. * @author ylx
  158. * @date 2018年1月25日 下午1:58:45
  159. * @throws
  160. */
  161. @RequestMapping(value="/addOrder",method=RequestMethod.POST)
  162. public Map<String, Object> addOrder(@RequestBody Param param){
  163. try {
  164. orderService.checkIfHasTheSameId(ValidationUtil.checkAndAssignInt(param.getOrderId(),ORDER_ID_PATTERN));
  165. UserDetail userDetail = userAuthoricationService.queryUserDetail(ValidationUtil.checkAndAssignInt(param.getUserId()), Role.PLANNER);//检测当前操作用户权限
  166. List<UserDetail> users = userDetail.getUsers();
  167. int supplierId = ValidationUtil.checkAndAssignInt(param.getSupplierId());
  168. boolean flag=false;
  169. for (UserDetail user : users) {
  170. if(user.getUserId().equals(supplierId)){
  171. flag=true;
  172. break;
  173. }
  174. }
  175. if(!flag) throw new RuntimeException("查无此供应商");
  176. boxService.checkIfHasTheBoxNo(ValidationUtil.checkBlankAndAssignString(param.getBoxNo()));//检测箱号是否存在
  177. ValidationUtil.checkAndAssignInt(param.getInboxQty());
  178. ordersIssueService.addOrder(param);//生成新订单
  179. return JSONUtil.getJsonMap(200, true, HintMSG.OPERATION_SUCCESS, null);
  180. } catch (Exception e) {
  181. return JSONUtil.getJsonMap(500, false, HintMSG.OPERATION_FAIL+":"+e.getMessage(), null);
  182. }
  183. }
  184. /**
  185. *
  186. * @Title: showSuppliersUnderPlanner
  187. * @Description: TODO(当用户添加订单时点击供应商列表时显示该计划员下的所有供应商)
  188. {
  189. "userId":"xxx"
  190. }
  191. * @return Map<String,Object> 返回类型
  192. * @author ylx
  193. * @date 2018年1月25日 下午3:24:56
  194. * @throws
  195. */
  196. @RequestMapping(value="/showSuppliersUnderPlanner",method=RequestMethod.POST)
  197. public Map<String, Object> showSuppliersUnderPlanner(@RequestBody Param param){
  198. try {
  199. UserDetail userDetail = userAuthoricationService.queryUserDetail(ValidationUtil.checkAndAssignInt(param.getUserId()), Role.PLANNER);//检测当前操作用户权限
  200. return JSONUtil.getJsonMap(200, true, HintMSG.QUERY_SUCCESS, userDetail.getUsers());
  201. } catch (Exception e) {
  202. return JSONUtil.getJsonMap(500, false, HintMSG.QUERY_FAIL+":"+e.getMessage(), null);
  203. }
  204. }
  205. /**
  206. *
  207. * @Title: showAllBoxNo
  208. * @Description: TODO(当计划员点击箱号,显示所有箱号)
  209. {
  210. "userId":"xxx"
  211. }
  212. * @param @return 设定文件
  213. * @return Map<String,Object> 返回类型
  214. * @author ylx
  215. * @date 2018年1月25日 下午3:57:17
  216. * @throws
  217. */
  218. @RequestMapping(value="/showAllBoxNo",method=RequestMethod.POST)
  219. public Map<String, Object> showAllBoxNo(@RequestBody Param param){
  220. try {
  221. userAuthoricationService.queryUserAuthority(ValidationUtil.checkAndAssignInt(param.getUserId()), Role.PLANNER);//检测当前操作用户权限
  222. List<Box> boxList = boxService.queryAllBoxInformation();
  223. return JSONUtil.getJsonMap(200, true, HintMSG.QUERY_SUCCESS, boxList);
  224. } catch (Exception e) {
  225. return JSONUtil.getJsonMap(500, false, HintMSG.QUERY_FAIL+":"+e.getMessage(), null);
  226. }
  227. }
  228. /**
  229. *
  230. * @Title: orderTracking
  231. * @Description: TODO(查询订单的跟踪情况)
  232. {
  233. "userId":"xxx",
  234. "orderId":""
  235. }
  236. * @param @return 设定文件
  237. * @return Map<String,Object> 返回类型
  238. * @author ylx
  239. * @date 2018年1月25日 下午7:41:16
  240. * @throws
  241. */
  242. @RequestMapping(value="/orderTracking",method=RequestMethod.POST)
  243. public Map<String, Object> orderTracking(@RequestBody Param param){
  244. try {
  245. UserDetail userDetail = userAuthoricationService.queryUserAuthority(ValidationUtil.checkAndAssignInt(param.getUserId()),Role.PLANNER,Role.SUPPLIER);//检测当前操作用户权限
  246. Orders order = orderService.queryFullOrderByOrderId(ValidationUtil.checkAndAssignInt(param.getOrderId()));
  247. if(Role.PLANNER.equals(userDetail.getRoleName())){
  248. if(!param.getUserId().equals(order.getPlannerId())) throw new RuntimeException(HintMSG.NO_AUTH);
  249. }
  250. if(Role.SUPPLIER.equals(userDetail.getRoleName())){
  251. if(!param.getUserId().equals(order.getSupplierId())) throw new RuntimeException(HintMSG.NO_AUTH);
  252. }
  253. param.setOrder(order);
  254. Map<String, Object> map = ordersIssueService.orderTracking(param);
  255. return JSONUtil.getJsonMap(200, true, HintMSG.QUERY_SUCCESS, map);
  256. } catch (Exception e) {
  257. return JSONUtil.getJsonMap(500, false, HintMSG.QUERY_FAIL+":"+e.getMessage(), null);
  258. }
  259. }
  260. }