SelfCarController.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. package com.jkcredit.invoice.controller.business;
  2. import cn.afterturn.easypoi.excel.ExcelImportUtil;
  3. import cn.afterturn.easypoi.excel.entity.ImportParams;
  4. import cn.com.taiji.sdk.model.comm.protocol.tts.invoice.server.B2BInvoiceListModel;
  5. import cn.com.taiji.sdk.model.comm.protocol.tts.trade.service.CardTradeModel;
  6. import com.alibaba.fastjson.JSON;
  7. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  8. import com.jkcredit.invoice.annotation.LoginRequired;
  9. import com.jkcredit.invoice.mapper.customer.CustomerRecMapper;
  10. import com.jkcredit.invoice.model.entity.calculate.SelfCarCalculateInfor;
  11. import com.jkcredit.invoice.model.entity.customer.CustomerCarRec;
  12. import com.jkcredit.invoice.model.entity.customer.CustomerRec;
  13. import com.jkcredit.invoice.model.entity.invoice.SelfCarInvoice;
  14. import com.jkcredit.invoice.model.entity.waybill.SelfCarTrade;
  15. import com.jkcredit.invoice.service.calculateinfor.SelfCarCalculateInfoService;
  16. import com.jkcredit.invoice.service.customer.CustomerService;
  17. import com.jkcredit.invoice.service.lowerservice.SelfCarServiceL;
  18. import com.jkcredit.invoice.service.lowerservice.vo.*;
  19. import com.jkcredit.invoice.service.selfcar.SelfCarInvoiceService;
  20. import com.jkcredit.invoice.service.selfcar.SelfCarService;
  21. import com.jkcredit.invoice.service.selfcar.SelfCarTradeService;
  22. import com.jkcredit.invoice.util.RespR;
  23. import io.swagger.annotations.Api;
  24. import io.swagger.annotations.ApiOperation;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.util.StringUtils;
  27. import org.springframework.web.bind.annotation.*;
  28. import org.springframework.web.multipart.MultipartFile;
  29. import java.text.DateFormat;
  30. import java.text.SimpleDateFormat;
  31. import java.util.*;
  32. @Api(tags = "自有车操作")
  33. @RestController
  34. @RequestMapping(value = {"/selfCar"})
  35. /**
  36. * @Description 自有车操作
  37. * @Author mashengyi
  38. * @Date 2022/2/8 18:18
  39. * @Param
  40. * @Return
  41. * @Exception
  42. *
  43. */
  44. public class SelfCarController {
  45. @Autowired
  46. SelfCarServiceL selfCarServiceL;
  47. @Autowired
  48. SelfCarService selfCarService;
  49. @Autowired
  50. SelfCarServiceL selfCarServicel;
  51. @Autowired
  52. SelfCarTradeService selfCarTradeService;
  53. @Autowired
  54. SelfCarInvoiceService selfCarInvoiceService;
  55. @Autowired
  56. SelfCarCalculateInfoService selfCarCalculateInfoService;
  57. @Autowired
  58. CustomerService customerService;
  59. /**
  60. * 解绑etc卡
  61. * @param etcNum 参数集
  62. * @return 用户集合
  63. */
  64. @PostMapping("/selfCarUnBind")
  65. @ApiOperation(value="解绑etc卡", notes="解绑etc卡")
  66. @LoginRequired
  67. public RespR selfCarUnBind(String etcNum) {
  68. try {
  69. RespR respR = selfCarService.selfCarUnBind(etcNum);
  70. return respR;
  71. }catch (Exception e){
  72. e.printStackTrace();
  73. return new RespR(false,e.getMessage());
  74. }
  75. }
  76. /**
  77. * 分页查询自有车交易信息
  78. *
  79. * @param page 参数集
  80. * @return 交易信息
  81. */
  82. @PostMapping("/findTrades")
  83. @ApiOperation(value="分页查询自有车交易信息", notes="分页查询自有车交易信息")
  84. @LoginRequired
  85. public RespR findTrades(Page page, SelfCarTrade selfCarTrade) {
  86. try {
  87. setTimeDue(selfCarTrade);
  88. RespR respR = new RespR(selfCarTradeService.findByPageAndTrade(page, selfCarTrade));
  89. return respR;
  90. }catch (Exception e){
  91. e.printStackTrace();
  92. return new RespR(false,e.getMessage());
  93. }
  94. }
  95. /**
  96. * 分页查询自有车交易信息
  97. *
  98. * @param page 参数集
  99. * @return 交易信息
  100. */
  101. @PostMapping("/findTradesUpper")
  102. @ApiOperation(value="分页查询自有车交易信息", notes="分页查询自有车交易信息")
  103. @LoginRequired
  104. public RespR findTradesUpper(Page page, SelfCarTrade selfCarTrade) {
  105. try {
  106. setTimeDue(selfCarTrade);
  107. if(StringUtils.isEmpty(selfCarTrade.getCompanyName())){
  108. return new RespR(false,"需要输入公司名称");
  109. }
  110. if(StringUtils.isEmpty(selfCarTrade.getCardId())){
  111. return new RespR(false,"需要输入etc卡号");
  112. }
  113. if(StringUtils.isEmpty(selfCarTrade.getExTimeBegin())){
  114. return new RespR(false,"需要交易开始时间");
  115. }
  116. if(StringUtils.isEmpty(selfCarTrade.getExTimeEnd())){
  117. return new RespR(false,"需要输入交易结束时间");
  118. }
  119. //先更新查询信息
  120. TradeRequestVo tradeRequestVo = new TradeRequestVo();
  121. tradeRequestVo.setCustomerName(selfCarTrade.getCustomId());
  122. tradeRequestVo.setCompanyName(selfCarTrade.getCompanyName());
  123. tradeRequestVo.setStartTime(selfCarTrade.getExTimeBegin());
  124. tradeRequestVo.setEndTime(selfCarTrade.getExTimeEnd());
  125. tradeRequestVo.setEtcId(selfCarTrade.getCardId());
  126. tradeRequestVo.setTradeStatus(selfCarTrade.getStatus());
  127. tradeRequestVo.setInterType(1);//0 接口
  128. if(tradeRequestVo.getTradeStatus() ==null){
  129. tradeRequestVo.setTradeStatus(1);
  130. selfCarServiceL.getTradeList(tradeRequestVo);
  131. tradeRequestVo.setTradeStatus(2);
  132. selfCarServiceL.getTradeList(tradeRequestVo);
  133. tradeRequestVo.setTradeStatus(3);
  134. selfCarServiceL.getTradeList(tradeRequestVo);
  135. }else{
  136. selfCarServiceL.getTradeList(tradeRequestVo);
  137. }
  138. RespR respR = new RespR(selfCarTradeService.findByPageAndTrade(page, selfCarTrade));
  139. return respR;
  140. }catch (Exception e){
  141. e.printStackTrace();
  142. return new RespR(false,e.getMessage());
  143. }
  144. }
  145. /**
  146. * 分页查询自有车交易信息
  147. *
  148. * @param selfCarTradesStr
  149. * @return 交易信息
  150. */
  151. @PostMapping("/updateTrades")
  152. @ApiOperation(value="更新交易id状态", notes="更新交易id状态")
  153. @LoginRequired
  154. public void updateTrades( String selfCarTradesStr) {
  155. try {
  156. List<SelfCarTrade> selfCarTrades = JSON.parseArray(selfCarTradesStr,SelfCarTrade.class);
  157. selfCarTradeService.updateTrades(selfCarTrades);
  158. }catch (Exception e){
  159. e.printStackTrace();
  160. }
  161. }
  162. public void setTimeDue(SelfCarTrade selfCarTrade){
  163. if(!StringUtils.isEmpty(selfCarTrade.getAclTimeBegin()) && !"null".equals(selfCarTrade.getAclTimeBegin())){
  164. String [] res = selfCarTrade.getAclTimeBegin().split(",");
  165. selfCarTrade.setAclTimeBegin(res[0]);
  166. selfCarTrade.setAclTimeEnd(res[1].replace("00:00:00","23:59:59"));
  167. }else{
  168. selfCarTrade.setAclTimeBegin(null);
  169. }
  170. if(!StringUtils.isEmpty(selfCarTrade.getExTimeBegin()) && !"null".equals(selfCarTrade.getExTimeBegin())){
  171. String [] res = selfCarTrade.getExTimeBegin().split(",");
  172. selfCarTrade.setExTimeBegin(res[0]);
  173. selfCarTrade.setExTimeEnd(res[1].replace("00:00:00","23:59:59"));
  174. }else{
  175. selfCarTrade.setExTimeBegin(null);
  176. }
  177. }
  178. /**
  179. * 分页查询所有发票信息
  180. *
  181. * @param page 参数集
  182. * @return 交易信息
  183. */
  184. @PostMapping("/findSelfCarInvoices")
  185. @ApiOperation(value="分页查询自有车发票信息", notes="分页查询自有车发票信息")
  186. @LoginRequired
  187. public RespR findSelfCarInvoices(Page page, SelfCarInvoice selfCarInvoice) {
  188. try {
  189. if(!StringUtils.isEmpty(selfCarInvoice.getInvoiceMakeTime()) && !"null".equals(selfCarInvoice.getInvoiceMakeTime())){
  190. String [] res =selfCarInvoice.getInvoiceMakeTime().split(",");
  191. selfCarInvoice.setInvoiceMakeStart(res[0]);
  192. selfCarInvoice.setInvoiceMakeEnd(res[1].replace("00:00:00","23:59:59"));
  193. }
  194. RespR respR = new RespR(selfCarInvoiceService.findByPageAndInvoice(page, selfCarInvoice));
  195. return respR;
  196. }catch (Exception e){
  197. e.printStackTrace();
  198. return new RespR(false,e.getMessage());
  199. }
  200. }
  201. /**
  202. * 分页查询自有车计费信息
  203. *
  204. * @param page 参数集
  205. * @return 用户集合
  206. */
  207. @PostMapping("/findSelfcarCalculateInfo")
  208. @ApiOperation(value="分页查询自有车计费信息", notes="分页查询自有车计费信息")
  209. @LoginRequired
  210. public RespR findSelfcarCalculateInfo(Page page, SelfCarCalculateInfor carCalculateInfor) {
  211. try {
  212. if(!StringUtils.isEmpty(carCalculateInfor.getCalTime()) && !"null".equals(carCalculateInfor.getCalTime())){
  213. String [] res =carCalculateInfor.getCalTime().split(",");
  214. carCalculateInfor.setCalTimeStart(res[0]);
  215. carCalculateInfor.setCalTimeEnd(res[1]);
  216. }
  217. RespR respR = new RespR(selfCarCalculateInfoService.findByPageAndCalculateInfor(page, carCalculateInfor));
  218. return respR;
  219. }catch (Exception e){
  220. e.printStackTrace();
  221. return new RespR(false,e.getMessage());
  222. }
  223. }
  224. /**
  225. * 分页查询自有车计费信息
  226. *
  227. * @param carCalculateInfor
  228. * @return 用户集合
  229. */
  230. @PostMapping("/findSelfcarCalculateInfoSta")
  231. @ApiOperation(value="自有车计费统计信息", notes="自有车计费统计信息")
  232. @LoginRequired
  233. public RespR findSelfcarCalculateInfoSta(SelfCarCalculateInfor carCalculateInfor) {
  234. try {
  235. if(!StringUtils.isEmpty(carCalculateInfor.getCalTime()) && !"null".equals(carCalculateInfor.getCalTime())){
  236. String [] res =carCalculateInfor.getCalTime().split(",");
  237. carCalculateInfor.setCalTimeStart(res[0]);
  238. carCalculateInfor.setCalTimeEnd(res[1]);
  239. }
  240. RespR respR = new RespR(selfCarCalculateInfoService.findSelfcarCalculateInfoSta(carCalculateInfor));
  241. return respR;
  242. }catch (Exception e){
  243. e.printStackTrace();
  244. return new RespR(false,e.getMessage());
  245. }
  246. }
  247. /**
  248. * @param tradeRequestCarNumVo
  249. * @return
  250. */
  251. @PostMapping("/getTradeList")
  252. @ApiOperation(value="获取需要开票的交易Id列表", notes="获取需要开票的交易Id列表")
  253. @LoginRequired
  254. public RespR getTradeList(@RequestBody TradeRequestCarNumVo tradeRequestCarNumVo){
  255. //通过车牌号查询所有的Etc卡号
  256. List<CustomerCarRec> customerCarRecs = selfCarService.getEtcsByCarNum(tradeRequestCarNumVo.getCarNum());
  257. if(customerCarRecs == null || customerCarRecs.size()<=0){
  258. return new RespR(false,"请输入有绑定ETC卡号的车牌");
  259. }
  260. //合并展示
  261. List<CardTradeModel> cardTradeModels = new ArrayList<>();
  262. customerCarRecs.forEach(customerCarRec -> {
  263. TradeRequestVo tradeRequestVo = new TradeRequestVo();
  264. tradeRequestVo.setCompanyName(tradeRequestCarNumVo.getCompanyName());
  265. tradeRequestVo.setCustomerName(tradeRequestCarNumVo.getCustomerName());
  266. DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  267. tradeRequestVo.setStartTime(format.format(new Date(Long.parseLong(tradeRequestCarNumVo.getStartTime()))));
  268. tradeRequestVo.setEndTime(format.format(new Date(Long.parseLong(tradeRequestCarNumVo.getEndTime()))));
  269. tradeRequestVo.setTradeStatus(1);
  270. tradeRequestVo.setEtcId(customerCarRec.getEtcNum());
  271. RespR<List<CardTradeModel>> respRbefore = selfCarServicel.getTradeList(tradeRequestVo);
  272. if(respRbefore.getCode() == 0){
  273. cardTradeModels.addAll(respRbefore.getData());
  274. }
  275. });
  276. return new RespR(cardTradeModels);
  277. }
  278. /**
  279. * @param tradeRequestCarNumVo
  280. * @return
  281. */
  282. @PostMapping("/applTradeList")
  283. @ApiOperation(value="根据车牌号进行开票操作", notes="根据车牌号进行开票操作")
  284. @LoginRequired
  285. public RespR applTradeList(@RequestBody TradeRequestCarNumVo tradeRequestCarNumVo){
  286. String [] cardAndTrades = tradeRequestCarNumVo.getCarIdStr().split(",");
  287. Map<String,InvoiceApplVo> map = new HashMap<>();
  288. for(int i = 0;i<cardAndTrades.length;i++){
  289. if(!StringUtils.isEmpty(cardAndTrades[i])){
  290. String [] cardAndTrade = cardAndTrades[i].split("#");
  291. InvoiceApplVo invoiceApplVo = map.get(cardAndTrade[0]);
  292. if(invoiceApplVo == null){
  293. invoiceApplVo.setCompanyName(tradeRequestCarNumVo.getCompanyName());
  294. invoiceApplVo.setCustomerName(tradeRequestCarNumVo.getCustomerName());
  295. invoiceApplVo.setCardId(cardAndTrade[0]);
  296. invoiceApplVo.setTradeIds(new ArrayList<String>());
  297. invoiceApplVo.getTradeIds().add(cardAndTrade[1]);
  298. map.put(cardAndTrade[0],invoiceApplVo);
  299. }else{
  300. invoiceApplVo.getTradeIds().add(cardAndTrade[1]);
  301. }
  302. }
  303. }
  304. StringBuffer stringBuffer = new StringBuffer();
  305. for(Map.Entry<String,InvoiceApplVo> elm:map.entrySet()){
  306. InvoiceApplVo invoiceApplVo = elm.getValue();
  307. RespR respR = selfCarServicel.applInvoice(invoiceApplVo);
  308. if(respR.getCode() == 1){
  309. stringBuffer.append(invoiceApplVo.getCardId()+"开票申请失败原因:"+respR.getMsg()+"#");
  310. }
  311. }
  312. if(StringUtils.isEmpty(stringBuffer.toString())){
  313. return new RespR(true);
  314. }else{
  315. return new RespR(false,stringBuffer.toString());
  316. }
  317. }
  318. @Autowired
  319. CustomerRecMapper customerRecMapper;
  320. /**
  321. * 查询已经开票信息
  322. *
  323. * @param
  324. * @return
  325. */
  326. @PostMapping("/findSelfcarInvoiceByTime")
  327. @ApiOperation(value="通过时间,车牌号查询开票信息", notes="通过时间,车牌号查询开票信息")
  328. @LoginRequired
  329. public RespR findSelfcarInvoiceByTime(@RequestBody SelfcarInvoiceByTimeVo selfcarInvoiceByTimeVo) {
  330. try {
  331. if(!customerService.checkMoneyEnough(selfcarInvoiceByTimeVo.getCustomerName())){
  332. return new RespR(false,"余额不足");
  333. }
  334. //通过车牌号查询所有的Etc卡号
  335. List<CustomerCarRec> customerCarRecs = selfCarService.getEtcsByCarNum(selfcarInvoiceByTimeVo.getCarNum());
  336. if(customerCarRecs == null || customerCarRecs.size()<=0){
  337. return new RespR(false,"请输入有绑定ETC卡号的车牌");
  338. }
  339. CustomerRec customerRec = new CustomerRec();
  340. customerRec.setCustomerName(selfcarInvoiceByTimeVo.getCustomerName());
  341. customerRec.setCompanyName(selfcarInvoiceByTimeVo.getCompanyName());
  342. CustomerRec customerRec1 = customerRecMapper.selectByCustomerNameAndCompany(customerRec);
  343. if(customerRec1 == null || customerRec1.getRecStatus().intValue() !=1 ){
  344. return new RespR(false,"客户未备案");
  345. }
  346. List<B2BInvoiceListModel> allSelfInvocies = new ArrayList<>();
  347. customerCarRecs.forEach(customerCarRec -> {
  348. SelfCarDueQueryVo selfCarDueQueryVo = new SelfCarDueQueryVo();
  349. selfCarDueQueryVo.setCustomername(selfcarInvoiceByTimeVo.getCustomerName());
  350. selfCarDueQueryVo.setCompanyName(selfcarInvoiceByTimeVo.getCompanyName());
  351. selfCarDueQueryVo.setStartTime(selfcarInvoiceByTimeVo.getStartTime());
  352. selfCarDueQueryVo.setEndTime(selfcarInvoiceByTimeVo.getEndTime());
  353. selfCarDueQueryVo.setCardId(customerCarRec.getEtcNum());
  354. RespR<List<B2BInvoiceListModel>> respR = selfCarServicel.getSelfCarInvoicesByTime(selfCarDueQueryVo,customerRec1);
  355. if(respR.getCode() == 0){
  356. allSelfInvocies.addAll(respR.getData());
  357. }
  358. });
  359. return new RespR(allSelfInvocies);
  360. }catch (Exception e){
  361. e.printStackTrace();
  362. return new RespR(false,e.getMessage());
  363. }
  364. }
  365. /**
  366. * 批量查询自有车交易信息
  367. *
  368. * @param file 参数集
  369. * @return
  370. */
  371. @PostMapping("/batchImportSelfcarTrades")
  372. @ApiOperation(value="批量查询自有车交易信息", notes="批量查询自有车交易信息")
  373. @LoginRequired
  374. public RespR batchImportSelfcarTrades(@RequestParam("file") MultipartFile file) {
  375. try {
  376. ImportParams params = new ImportParams();
  377. params.setTitleRows(1);
  378. params.setHeadRows(1);
  379. List<SelfCarTrade> list = ExcelImportUtil.importExcel(file.getInputStream(), SelfCarTrade.class,params) ;
  380. RespR respR = selfCarTradeService.batchImportSelfcarTrades(list);
  381. return respR;
  382. }catch (Exception e){
  383. e.printStackTrace();
  384. return new RespR(false,e.getMessage());
  385. }
  386. }
  387. /**
  388. * 批量查询自有车发票信息
  389. *
  390. * @param file 参数集
  391. * @return
  392. */
  393. @PostMapping("/batchImportSelfcarInvoices")
  394. @ApiOperation(value="批量查询自有车发票信息", notes="批量查询自有车发票信息")
  395. @LoginRequired
  396. public RespR batchImportSelfcarInvoices(@RequestParam("file") MultipartFile file) {
  397. try {
  398. ImportParams params = new ImportParams();
  399. params.setTitleRows(1);
  400. params.setHeadRows(1);
  401. List<SelfCarInvoice> list = ExcelImportUtil.importExcel(file.getInputStream(), SelfCarInvoice.class,params) ;
  402. RespR respR = selfCarInvoiceService.findImportSelfcarInvoices(list);
  403. return respR;
  404. }catch (Exception e){
  405. e.printStackTrace();
  406. return new RespR(false,e.getMessage());
  407. }
  408. }
  409. }