TbBusinessController.java 12 KB

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