TbBusinessController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. package com.pj.project.tb_business;
  2. import java.util.Date;
  3. import java.util.List;
  4. import cn.dev33.satoken.stp.StpUtil;
  5. import cn.hutool.core.date.DateUtil;
  6. import cn.hutool.core.util.StrUtil;
  7. import com.pj.constants.UserTypeEnum;
  8. import com.pj.project.tb_business_car.TbBusinessCar;
  9. import com.pj.project.tb_business_car.TbBusinessCarService;
  10. import com.pj.project.tb_business_item.TbBusinessItem;
  11. import com.pj.project.tb_business_item.TbBusinessItemService;
  12. import com.pj.project.tb_notices.TbNoticesService;
  13. import com.pj.project.tb_pass_record.TbPassRecord;
  14. import com.pj.project.tb_pass_record.TbPassRecordService;
  15. import com.pj.utils.so.SoMap;
  16. import org.aspectj.weaver.loadtime.Aj;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.transaction.annotation.Transactional;
  19. import org.springframework.web.bind.annotation.*;
  20. import com.pj.utils.sg.*;
  21. import com.pj.project4sp.SP;
  22. import com.pj.current.satoken.StpUserUtil;
  23. import cn.dev33.satoken.annotation.SaCheckPermission;
  24. import javax.annotation.Resource;
  25. /**
  26. * Controller: tb_business -- 入境登记
  27. *
  28. * @author qzy
  29. */
  30. @RestController
  31. @RequestMapping("/TbBusiness/")
  32. public class TbBusinessController {
  33. /**
  34. * 底层 Service 对象
  35. */
  36. @Autowired
  37. TbBusinessService tbBusinessService;
  38. @Resource
  39. private TbBusinessItemService tbBusinessItemService;
  40. @Resource
  41. private TbNoticesService tbNoticesService;
  42. @Resource
  43. private TbBusinessCarService tbBusinessCarService;
  44. @RequestMapping(value = "getMsg")
  45. public AjaxJson getMsg() {
  46. return AjaxJson.getSuccessData(BusinessMessageManager.get(StpUserUtil.getCustomerId()));
  47. }
  48. /**
  49. * 增
  50. */
  51. @RequestMapping("add")
  52. @SaCheckPermission(TbBusiness.PERMISSION_CODE)
  53. @Transactional(rollbackFor = Exception.class)
  54. public AjaxJson add(TbBusiness t) {
  55. return tbBusinessService.addOrUpdate(t);
  56. }
  57. /**
  58. * 删
  59. */
  60. @RequestMapping("delete")
  61. @SaCheckPermission(TbBusiness.PERMISSION_INPUT)
  62. @Transactional(rollbackFor = Exception.class)
  63. public AjaxJson delete(String id) {
  64. TbBusiness db = tbBusinessService.getById(id);
  65. if (db != null) {
  66. tbBusinessService.storeMsg(db.getCustomerId(), "业务订单【" + db.getNo() + "】已删除。" + DateUtil.now() + "。");
  67. }
  68. tbBusinessService.removeById(id);
  69. tbBusinessItemService.removeByBusinessId(id);
  70. tbBusinessCarService.removeByBusinessId(id);
  71. return AjaxJson.getSuccess();
  72. }
  73. /**
  74. * 改
  75. */
  76. @RequestMapping("update")
  77. @SaCheckPermission(TbBusiness.PERMISSION_CODE)
  78. public AjaxJson update(TbBusiness t) {
  79. tbBusinessService.addOrUpdate(t);
  80. return AjaxJson.getSuccess();
  81. }
  82. /**
  83. * 确认业务
  84. */
  85. @RequestMapping("confirm")
  86. @Transactional(rollbackFor = Exception.class)
  87. public AjaxJson confirm() {
  88. if (!StpUtil.hasPermissionAnd(TbBusiness.PERMISSION_CONFIRM) && !
  89. StrUtil.equals(StpUserUtil.getCustomerId(), UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  90. return AjaxJson.getError("无确认业务权限");
  91. }
  92. SoMap so = SoMap.getRequestSoMap();
  93. List<String> ids = so.getListByComma("ids", String.class);
  94. tbBusinessService.confirm(ids);
  95. return AjaxJson.getSuccess();
  96. }
  97. /**
  98. * 确认业务
  99. */
  100. @RequestMapping("adminConfirmPay")
  101. @Transactional(rollbackFor = Exception.class)
  102. public AjaxJson adminConfirmPay() {
  103. if (!StrUtil.equals(StpUserUtil.getCustomerId(), UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  104. return AjaxJson.getError("无确认支付权限");
  105. }
  106. SoMap so = SoMap.getRequestSoMap();
  107. List<String> ids = so.getListByComma("ids", String.class);
  108. String ticket = so.getString("payTicket");
  109. tbBusinessService.adminConfirmPay(ids, ticket);
  110. return AjaxJson.getSuccess();
  111. }
  112. /**
  113. * 手动入场确认 see adminSetIn
  114. */
  115. @RequestMapping("adminConfirmIn")
  116. @Transactional(rollbackFor = Exception.class)
  117. @Deprecated
  118. public AjaxJson adminConfirmIn() {
  119. if (!StrUtil.equals(StpUserUtil.getCustomerId(), UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  120. return AjaxJson.getError("无确认入场权限");
  121. }
  122. SoMap so = SoMap.getRequestSoMap();
  123. String id = so.getString("id");
  124. String inChannel = so.getString("inChannel");
  125. tbBusinessService.adminConfirmIn(id, inChannel);
  126. return AjaxJson.getSuccess();
  127. }
  128. /**
  129. * 查 - 根据id
  130. */
  131. @RequestMapping("getById")
  132. public AjaxJson getById(String id) {
  133. TbBusiness t = tbBusinessService.getById(id);
  134. List<TbBusinessItem> items = tbBusinessItemService.findByBusinessId(id);
  135. items.forEach(tbBusinessItem -> tbBusinessItem.setGoodsName(t.getGoodsName()).setCardNo(t.getCardNo()).setChinaCarNo(t.getChinaCarNo()));
  136. t.setItems(items);
  137. List<TbBusinessCar> cars = tbBusinessCarService.findByBusinessId(id);
  138. t.setCars(cars);
  139. return AjaxJson.getSuccessData(t);
  140. }
  141. /**
  142. * 查集合 - 根据条件(参数为空时代表忽略指定条件)
  143. */
  144. @RequestMapping("getList")
  145. public AjaxJson getList() {
  146. System.out.println(StrUtil.subBefore("c_2222_fhjk","_",true));
  147. SoMap so = SoMap.getRequestSoMap();
  148. String currentCustomerId = StpUserUtil.getCustomerId();
  149. if (!currentCustomerId.equals(UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  150. so.put("customerId", currentCustomerId);
  151. }
  152. List<TbBusiness> list = tbBusinessService.getList(so.startPage());
  153. return AjaxJson.getPageData(so.getDataCount(), list);
  154. }
  155. /**
  156. * 改
  157. */
  158. @RequestMapping("pay")
  159. public AjaxJson pay() {
  160. if (!StpUtil.hasPermissionAnd("tb-business-pay") && !
  161. StrUtil.equals(StpUserUtil.getCustomerId(), UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  162. return AjaxJson.getError("无支付权限");
  163. }
  164. SoMap so = SoMap.getRequestSoMap();
  165. String id = so.getString("id");
  166. String payTicket = so.getString("payTicket");
  167. tbBusinessService.pay(id, payTicket);
  168. return AjaxJson.getSuccess();
  169. }
  170. @RequestMapping("adminSetIn")
  171. public AjaxJson adminSetIn() {
  172. if (!StrUtil.equals(StpUserUtil.getCustomerId(), UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  173. return AjaxJson.getError("无入场权限");
  174. }
  175. SoMap so = SoMap.getRequestSoMap();
  176. String id = so.getString("id");
  177. Date inTime = so.getDateTime("realInTime");
  178. Date chinaCarInTime = so.getDateTime("chinaCarInTime");
  179. TbBusiness tbBusiness = tbBusinessService.getById(id);
  180. tbBusiness.setChinaCarInTime(chinaCarInTime).setRealInTime(inTime).setAdminConfirmIn(1);
  181. tbBusinessService.updateById(tbBusiness);
  182. //更新境外车入场记录
  183. //更新中国车入场记录
  184. //发送消息
  185. String text = "您的车辆已入场,业务单号[" + tbBusiness.getNo() + "]";
  186. tbNoticesService.sendNotice(tbBusiness.getId(), tbBusiness.getNo(), tbBusiness.getCustomerId(), text);
  187. return AjaxJson.getSuccess();
  188. }
  189. @RequestMapping("adminOut")
  190. public AjaxJson adminOut() {
  191. if (!StrUtil.equals(StpUserUtil.getCustomerId(), UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  192. return AjaxJson.getError("无离场权限");
  193. }
  194. SoMap so = SoMap.getRequestSoMap();
  195. String id = so.getString("id");
  196. TbBusiness business = tbBusinessService.getById(id);
  197. Date outTime = so.getDateTime("outDayTime");
  198. if (business.getRealInTime().getTime() > outTime.getTime()) {
  199. return AjaxJson.getError("离场时间须大于出场时间");
  200. }
  201. business.setOutDayTime(outTime);
  202. tbBusinessService.calculationPartMoney("越南车", business);
  203. tbBusinessService.updateById(business);
  204. Date chinaCarOutTime = so.getDateTime("chinaCarOutTime");
  205. if (chinaCarOutTime.getTime() < business.getChinaCarInTime().getTime()) {
  206. return AjaxJson.getError("离场时间须大于出场时间");
  207. }
  208. business.setChinaCarOutTime(chinaCarOutTime);
  209. tbBusinessService.calculationPartMoney("中国车", business);
  210. business.setAdminConfirmOut(1);
  211. tbBusinessService.updateById(business);
  212. //更新境外车出场记录
  213. //更新中国车出场记录
  214. tbBusinessService.storeMsg(business.getCustomerId(), "业务订单【" + business.getNo() + "】已完成作业离场" + DateUtil.now() + "。");
  215. //发送消息
  216. String text = "您的车辆已离场,业务单号[" + business.getNo() + "]";
  217. tbNoticesService.sendNotice(business.getId(), business.getNo(), business.getCustomerId(), text);
  218. return AjaxJson.getSuccess();
  219. }
  220. @RequestMapping("calJwPartMoney")
  221. public AjaxJson calJwPartMoney(TbBusiness business) {
  222. if (!StrUtil.equals(StpUserUtil.getCustomerId(), UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  223. return AjaxJson.getError("无生成账单权限");
  224. }
  225. tbBusinessService.calculationPartMoney("越南车", business);
  226. return AjaxJson.getSuccessData(business);
  227. }
  228. @RequestMapping("calChinaPartMoney")
  229. public AjaxJson calChinaPartMoney(TbBusiness business) {
  230. if (!StrUtil.equals(StpUserUtil.getCustomerId(), UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  231. return AjaxJson.getError("无生成账单权限");
  232. }
  233. tbBusinessService.calculationPartMoney("中国车", business);
  234. return AjaxJson.getSuccessData(business);
  235. }
  236. @RequestMapping("complete")
  237. public AjaxJson complete(TbBusiness business) {
  238. if (!StrUtil.equals(StpUserUtil.getCustomerId(), UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  239. return AjaxJson.getError("无生成账单权限");
  240. }
  241. business.setComplete(1);
  242. tbBusinessService.updateById(business);
  243. tbBusinessService.storeMsg(business.getCustomerId(), "业务订单【" + business.getNo() + "】账单已生成!" + DateUtil.now() + "。");
  244. //发送消息
  245. String text = "您的账单已生成,业务单号[" + business.getNo() + "]";
  246. tbNoticesService.sendNotice(business.getId(), business.getNo(), business.getCustomerId(), text);
  247. return AjaxJson.getSuccessData(business);
  248. }
  249. @RequestMapping("uploadReport")
  250. public AjaxJson uploadReport(@RequestBody TbBusiness tbBusiness){
  251. tbBusinessService.uploadReport(tbBusiness);
  252. return AjaxJson.getSuccess();
  253. }
  254. // ------------------------- 前端接口 -------------------------
  255. }