TbBusinessController.java 11 KB

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