选装售后
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

FssPaccountPayServiceImpl.java 19KB

pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 8 mēnešiem
pirms 8 mēnešiem
pirms 8 mēnešiem
pirms 8 mēnešiem
pirms 1 gada
pirms 1 gada
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. package com.qtzl.alterSales.manager.service;
  2. import cn.com.taiji.common.manager.net.http.ServiceHandleException;
  3. import cn.hutool.core.bean.BeanUtil;
  4. import com.alibaba.fastjson.JSON;
  5. import com.google.common.collect.Lists;
  6. import com.qtzl.alterSales.dao.entity.primary.AflApPayOrder;
  7. import com.qtzl.alterSales.dao.entity.primary.FssPaccountPay;
  8. import com.qtzl.alterSales.dao.entity.primary.WechatBillPayApply;
  9. import com.qtzl.alterSales.dao.entity.primary.WechatBillPaySuccess;
  10. import com.qtzl.alterSales.dao.entity.second.AflPaccountRefundCount;
  11. import com.qtzl.alterSales.dao.repo.jpa.primary.AflApPayOrderRepo;
  12. import com.qtzl.alterSales.dao.repo.jpa.primary.AflSupplementaryPayOrderRepo;
  13. import com.qtzl.alterSales.dao.repo.jpa.primary.FssPaccountPayRepo;
  14. import com.qtzl.alterSales.dao.repo.jpa.primary.FssPaccountRefundRepo;
  15. import com.qtzl.alterSales.dao.repo.jpa.primary.WechatBillPayApplyRepo;
  16. import com.qtzl.alterSales.dao.repo.jpa.primary.WechatBillPaySuccessRepo;
  17. import com.qtzl.alterSales.dao.repo.jpa.second.AflPaccountRefundCountRepo;
  18. import com.qtzl.alterSales.manager.enums.VehiclePlateColorEnum;
  19. import com.qtzl.alterSales.manager.model.protocol.UcServiceError;
  20. import com.qtzl.alterSales.manager.model.protocol.sales.FssPaccountPayResultFindByPayIdResponse;
  21. import com.qtzl.alterSales.manager.vo.AflPaccountRefundCountFindVo;
  22. import com.qtzl.alterSales.manager.vo.VehicleAgreementNumBillsVo;
  23. import org.apache.commons.lang3.StringUtils;
  24. import org.slf4j.Logger;
  25. import org.slf4j.LoggerFactory;
  26. import org.springframework.beans.BeanUtils;
  27. import org.springframework.stereotype.Service;
  28. import org.springframework.util.CollectionUtils;
  29. import javax.annotation.Resource;
  30. import java.time.LocalDate;
  31. import java.time.LocalDateTime;
  32. import java.util.ArrayList;
  33. import java.util.List;
  34. import java.util.Map;
  35. import java.util.UUID;
  36. /***
  37. * <p>
  38. * 选装-原始流水 service
  39. * </p>
  40. * @author hou yi
  41. * {@code @date} 2023/10/12 11:43
  42. **/
  43. @Service
  44. public class FssPaccountPayServiceImpl implements FssPaccountPayService {
  45. private static final Logger log = LoggerFactory.getLogger(FssPaccountPayServiceImpl.class);
  46. @Resource
  47. private FssPaccountPayRepo paccountPayRepo;
  48. @Resource
  49. private AflPaccountRefundCountRepo aflPaccountRefundCountRepo;
  50. @Resource
  51. private FssPaccountRefundRepo fssPaccountRefundRepo;
  52. @Resource
  53. private AflSupplementaryPayOrderRepo supplementaryPayOrderRepo;
  54. @Resource
  55. private WechatBillPayApplyRepo wechatBillPayApplyRepo;
  56. @Resource
  57. private WechatBillPaySuccessRepo successRepo;
  58. @Resource
  59. private AflApPayOrderRepo apPayOrderRepo;
  60. @Override
  61. public List<VehicleAgreementNumBillsVo> getAgreementBills(String plateNumber, Integer plateColor) throws ServiceHandleException {
  62. if (StringUtils.isEmpty(plateNumber) || null == plateColor) {
  63. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("请指定车牌号、车牌颜色");
  64. }
  65. List<FssPaccountPay> agreementBills = paccountPayRepo.findByVehicleId(plateNumber + "_" + plateColor);
  66. if (CollectionUtils.isEmpty(agreementBills)) {
  67. return Lists.newArrayList();
  68. }
  69. /* // 过滤掉已生成补缴单的流水
  70. final List<String> payIds = agreementBills.stream().map(FssPaccountPay::getPayId).toList();
  71. final List<AflSupplementaryPayOrder> orders = supplementaryPayOrderRepo.findAll((root, query, cb) -> query
  72. .where(
  73. root.<String>get("payId").in(payIds)
  74. ).getRestriction());
  75. if (!CollectionUtils.isEmpty(orders)) {
  76. final List<String> orderPayIds = orders.stream().map(AflSupplementaryPayOrder::getPayId).toList();
  77. agreementBills = agreementBills.stream().filter(vo -> !orderPayIds.contains(vo.getPayId())).toList();
  78. }*/
  79. return toVo(agreementBills);
  80. }
  81. @Override
  82. public List<VehicleAgreementNumBillsVo> findByPayId(List<String> payIds) {
  83. if (CollectionUtils.isEmpty(payIds)) {
  84. return Lists.newArrayList();
  85. }
  86. return toVo(paccountPayRepo.findByPayIdIn(payIds));
  87. }
  88. @Override
  89. public void count(int day) throws ServiceHandleException {
  90. // 获取当前日期前一天的日期
  91. LocalDate localDate = LocalDate.now().minusDays(day);//1代表提前多少天
  92. String yesterday = localDate.toString();
  93. System.out.println("当前导入记录日期=" + yesterday);
  94. Integer i = aflPaccountRefundCountRepo.findByToDay(yesterday.replaceAll("-", ""));
  95. if (i != null && i > 0) {
  96. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("当前n+" + day + "天记录已存在");
  97. }
  98. List<Map<String, Object>> countTotal = paccountPayRepo.findCountTotal(yesterday + " 00:00:00", yesterday + " " +
  99. "23:59:59");
  100. List<AflPaccountRefundCountFindVo> list = new ArrayList<AflPaccountRefundCountFindVo>();
  101. for (Map<String, Object> stringObjectMap : countTotal) {
  102. AflPaccountRefundCountFindVo aflPaccountRefundCountVo =
  103. JSON.parseObject(JSON.toJSONString(stringObjectMap), AflPaccountRefundCountFindVo.class);
  104. list.add(aflPaccountRefundCountVo);
  105. }
  106. if (list == null || list.size() < 1) {
  107. throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("当前n+" + day + "天记录无数据");
  108. }
  109. log.info("本次处理数据:{}", JSON.toJSON(list));
  110. AflPaccountRefundCount bydAflPaccountRefundCount = null;
  111. for (AflPaccountRefundCountFindVo aflPaccountRefundCountVo : list) {
  112. AflPaccountRefundCount aflPaccountRefundCount = new AflPaccountRefundCount();
  113. Long refundMoney = fssPaccountRefundRepo.findByCountRefundMoney(aflPaccountRefundCountVo.getAgentId(),
  114. aflPaccountRefundCountVo.getAccountDate());
  115. BeanUtils.copyProperties(aflPaccountRefundCountVo, aflPaccountRefundCount);
  116. aflPaccountRefundCount.setRefundMoney(refundMoney);
  117. if (!StringUtils.isEmpty(aflPaccountRefundCountVo.getAccountDate())) {
  118. String accountDate = aflPaccountRefundCountVo.getAccountDate().replaceAll("-", "");
  119. aflPaccountRefundCount.setAccountDate(Integer.parseInt(accountDate));
  120. }
  121. if ("52010188999".equals(aflPaccountRefundCount.getAgentId()) && aflPaccountRefundCount.getAccountDate() != null) {
  122. bydAflPaccountRefundCount = aflPaccountRefundCount;
  123. AflPaccountRefundCount bydNewAflPaccountRefundCount = aflPaccountRefundCountRepo.finByDateAndAgentId(
  124. "52010188930", aflPaccountRefundCount.getAccountDate());
  125. if (bydNewAflPaccountRefundCount != null) {
  126. if (bydAflPaccountRefundCount.getMoneyTotal() != null) {
  127. bydNewAflPaccountRefundCount.setMoneyTotal(bydNewAflPaccountRefundCount.getMoneyTotal() + bydAflPaccountRefundCount.getMoneyTotal());
  128. }
  129. if (bydAflPaccountRefundCount.getRefundMoney() != null) {
  130. bydNewAflPaccountRefundCount.setRefundMoney(bydNewAflPaccountRefundCount.getRefundMoney() + bydAflPaccountRefundCount.getRefundMoney());
  131. }
  132. if (bydAflPaccountRefundCount.getCollectMoney() != null) {
  133. bydNewAflPaccountRefundCount.setCollectMoney(bydNewAflPaccountRefundCount.getCollectMoney() + bydAflPaccountRefundCount.getCollectMoney());
  134. }
  135. if (bydAflPaccountRefundCount.getNumberTotal() != null) {
  136. bydNewAflPaccountRefundCount.setNumberTotal(bydNewAflPaccountRefundCount.getNumberTotal() + bydAflPaccountRefundCount.getNumberTotal());
  137. }
  138. aflPaccountRefundCountRepo.save(bydNewAflPaccountRefundCount);
  139. }
  140. continue;
  141. }
  142. if ("52010188930".equals(aflPaccountRefundCount.getAgentId()) && bydAflPaccountRefundCount != null) {
  143. if (bydAflPaccountRefundCount.getMoneyTotal() != null) {
  144. aflPaccountRefundCount.setMoneyTotal(aflPaccountRefundCount.getMoneyTotal() + bydAflPaccountRefundCount.getMoneyTotal());
  145. }
  146. if (bydAflPaccountRefundCount.getRefundMoney() != null) {
  147. aflPaccountRefundCount.setRefundMoney(aflPaccountRefundCount.getRefundMoney() + bydAflPaccountRefundCount.getRefundMoney());
  148. }
  149. if (bydAflPaccountRefundCount.getCollectMoney() != null) {
  150. aflPaccountRefundCount.setCollectMoney(aflPaccountRefundCount.getCollectMoney() + bydAflPaccountRefundCount.getCollectMoney());
  151. }
  152. if (bydAflPaccountRefundCount.getNumberTotal() != null) {
  153. aflPaccountRefundCount.setCollectMoney(aflPaccountRefundCount.getCollectMoney() + bydAflPaccountRefundCount.getCollectMoney());
  154. }
  155. }
  156. aflPaccountRefundCount.setId(UUID.randomUUID().toString().replace("-", ""));
  157. aflPaccountRefundCount.setUpdateTime(LocalDateTime.now());
  158. aflPaccountRefundCount.setInsertTime(LocalDateTime.now());
  159. aflPaccountRefundCountRepo.save(aflPaccountRefundCount);
  160. }
  161. }
  162. /**
  163. * 更新统计
  164. * @param day
  165. * @throws ServiceHandleException
  166. */
  167. @Override
  168. public void newCount(int day) throws ServiceHandleException {
  169. // 获取当前日期前一天的日期
  170. //1代表提前多少天
  171. LocalDate localDate = LocalDate.now().minusDays(day);
  172. String yesterday = localDate.toString();
  173. log.info("当前导入记录日期="+yesterday);
  174. List<Map<String, Object>> countTotal = paccountPayRepo.findCountTotal(yesterday+" 00:00:00",yesterday+" 23:59:59");
  175. List<AflPaccountRefundCountFindVo> list = new ArrayList<AflPaccountRefundCountFindVo>();
  176. for (Map<String, Object> stringObjectMap : countTotal) {
  177. AflPaccountRefundCountFindVo aflPaccountRefundCountVo = JSON.parseObject(JSON.toJSONString(stringObjectMap), AflPaccountRefundCountFindVo.class);
  178. list.add(aflPaccountRefundCountVo);
  179. }
  180. if (list==null||list.size()<1){
  181. log.error("当前n+"+day+"天记录无数据");
  182. return;
  183. // throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("当前n+"+day+"天记录无数据");
  184. }
  185. log.info("本次处理数据:{}", JSON.toJSON(list));
  186. AflPaccountRefundCount bydAflPaccountRefundCount = null;
  187. for (AflPaccountRefundCountFindVo aflPaccountRefundCountVo : list) {
  188. String accountDate =null;
  189. if (!StringUtils.isEmpty(aflPaccountRefundCountVo.getAccountDate())){
  190. accountDate=aflPaccountRefundCountVo.getAccountDate().replaceAll("-","");
  191. }
  192. AflPaccountRefundCount aflPaccountRefundCount= null;
  193. if("52010188999".equals(aflPaccountRefundCountVo.getAgentId())&&StringUtils.isNotEmpty(accountDate)){
  194. aflPaccountRefundCount= aflPaccountRefundCountRepo.finByDateAndAgentId("52010188930",Integer.valueOf(accountDate));
  195. }else {
  196. aflPaccountRefundCount= aflPaccountRefundCountRepo.finByDateAndAgentId(aflPaccountRefundCountVo.getAgentId(), StringUtils.isEmpty(accountDate) ? null : Integer.parseInt(accountDate));
  197. }
  198. if (aflPaccountRefundCount==null){
  199. aflPaccountRefundCount = new AflPaccountRefundCount();
  200. }
  201. Long refundMoney = fssPaccountRefundRepo.findByCountRefundMoney(aflPaccountRefundCountVo.getAgentId(),aflPaccountRefundCountVo.getAccountDate());
  202. aflPaccountRefundCountVo.setId(aflPaccountRefundCount.getId());
  203. BeanUtils.copyProperties(aflPaccountRefundCountVo,aflPaccountRefundCount);
  204. aflPaccountRefundCount.setRefundMoney(refundMoney);
  205. if (!StringUtils.isEmpty(aflPaccountRefundCountVo.getAccountDate())){
  206. String accountDateStr=aflPaccountRefundCountVo.getAccountDate().replaceAll("-","");
  207. aflPaccountRefundCount.setAccountDate(Integer.valueOf(accountDateStr));
  208. }
  209. if ("52010188999".equals(aflPaccountRefundCount.getAgentId())&&aflPaccountRefundCount.getAccountDate()!=null){
  210. bydAflPaccountRefundCount=aflPaccountRefundCount;
  211. AflPaccountRefundCount bydNewAflPaccountRefundCount= aflPaccountRefundCountRepo.finByDateAndAgentId("52010188930",aflPaccountRefundCount.getAccountDate());
  212. if (bydNewAflPaccountRefundCount!=null){
  213. if (bydAflPaccountRefundCount.getMoneyTotal()!=null){
  214. bydNewAflPaccountRefundCount.setMoneyTotal(bydNewAflPaccountRefundCount.getMoneyTotal()+bydAflPaccountRefundCount.getMoneyTotal());
  215. }
  216. if (bydAflPaccountRefundCount.getRefundMoney()!=null){
  217. bydNewAflPaccountRefundCount.setRefundMoney(bydNewAflPaccountRefundCount.getRefundMoney()+bydAflPaccountRefundCount.getRefundMoney());
  218. }
  219. if (bydAflPaccountRefundCount.getCollectMoney()!=null){
  220. bydNewAflPaccountRefundCount.setCollectMoney(bydNewAflPaccountRefundCount.getCollectMoney()+bydAflPaccountRefundCount.getCollectMoney());
  221. }
  222. if (bydAflPaccountRefundCount.getNumberTotal()!=null){
  223. bydNewAflPaccountRefundCount.setNumberTotal(bydNewAflPaccountRefundCount.getNumberTotal()+bydAflPaccountRefundCount.getNumberTotal());
  224. }
  225. aflPaccountRefundCountRepo.save(bydNewAflPaccountRefundCount);
  226. }
  227. continue;
  228. }
  229. if ("52010188930".equals(aflPaccountRefundCount.getAgentId())&&bydAflPaccountRefundCount!=null){
  230. if (bydAflPaccountRefundCount.getMoneyTotal()!=null){
  231. aflPaccountRefundCount.setMoneyTotal(aflPaccountRefundCount.getMoneyTotal()+bydAflPaccountRefundCount.getMoneyTotal());
  232. }
  233. if (bydAflPaccountRefundCount.getRefundMoney()!=null){
  234. aflPaccountRefundCount.setRefundMoney(aflPaccountRefundCount.getRefundMoney()+bydAflPaccountRefundCount.getRefundMoney());
  235. }
  236. if (bydAflPaccountRefundCount.getCollectMoney()!=null){
  237. aflPaccountRefundCount.setCollectMoney(aflPaccountRefundCount.getCollectMoney()+bydAflPaccountRefundCount.getCollectMoney());
  238. }
  239. if (bydAflPaccountRefundCount.getNumberTotal()!=null){
  240. aflPaccountRefundCount.setCollectMoney(aflPaccountRefundCount.getCollectMoney()+bydAflPaccountRefundCount.getCollectMoney());
  241. }
  242. }
  243. if (StringUtils.isEmpty(aflPaccountRefundCount.getId())){
  244. aflPaccountRefundCount.setId(UUID.randomUUID().toString().replace("-", ""));
  245. aflPaccountRefundCount.setInsertTime(LocalDateTime.now());
  246. }
  247. aflPaccountRefundCount.setUpdateTime(LocalDateTime.now());
  248. aflPaccountRefundCountRepo.save(aflPaccountRefundCount);
  249. }
  250. }
  251. private List<VehicleAgreementNumBillsVo> toVo(List<FssPaccountPay> payList) {
  252. if (CollectionUtils.isEmpty(payList)) {
  253. return Lists.newArrayList();
  254. }
  255. List<VehicleAgreementNumBillsVo> billsVos = Lists.newArrayList();
  256. VehicleAgreementNumBillsVo billsVo;
  257. for (FssPaccountPay bill : payList) {
  258. final LocalDateTime firstInsertTime = wechatBillPayApplyRepo.getFirstInsertTime(bill.getPayId());
  259. if (null == firstInsertTime) {
  260. // 过滤掉没有// 过滤掉没有轮扣过的流水
  261. continue;
  262. }
  263. billsVo = new VehicleAgreementNumBillsVo(bill.getPayId(), bill.getSceneTp(), bill.getReceiptAmt(),
  264. bill.getChargeTime());
  265. // 处理车牌号、车牌颜色
  266. if (!StringUtils.isEmpty(bill.getVehicleId()) && bill.getVehicleId().contains("_")) {
  267. final String[] vehicle = bill.getVehicleId().split("_");
  268. billsVo.setPlateNumber(vehicle[0]);
  269. billsVo.setPlateNumberColor(VehiclePlateColorEnum.find(Integer.parseInt(vehicle[1])).getColor());
  270. }
  271. // 处理出入口站名、停车场名称
  272. if (!StringUtils.isEmpty(bill.getTitle()) && null != bill.getSceneTp()) {
  273. final String[] titleSplit = bill.getTitle().split("[,,]");
  274. if (titleSplit.length != 5) {
  275. continue;
  276. }
  277. if (bill.getSceneTp().equals(2)) {
  278. // 停车场流水
  279. billsVo.setParkingLotName(titleSplit[3]);
  280. } else {
  281. // 非停车场流水的, 按照通行流水处理
  282. billsVo.setInboundName(titleSplit[2]);
  283. billsVo.setOutboundName(titleSplit[3]);
  284. }
  285. }
  286. billsVos.add(billsVo);
  287. }
  288. return billsVos;
  289. }
  290. @Override
  291. public FssPaccountPayResultFindByPayIdResponse findPaccountPayResultByPayId(String payId) throws ServiceHandleException {
  292. FssPaccountPay fssPaccountPay = paccountPayRepo.findByPayId(payId);
  293. if (fssPaccountPay == null) {
  294. throw UcServiceError.NOT_FOUND_DATA.toHandleException("未查询到数据");
  295. }
  296. FssPaccountPayResultFindByPayIdResponse response = new FssPaccountPayResultFindByPayIdResponse();
  297. BeanUtil.copyProperties(fssPaccountPay, response);
  298. response.setPayStatus(fssPaccountPay.getStatus());
  299. // 请款中的数据,查看是否存在扣款失败原因
  300. if (fssPaccountPay.getStatus().equals(2)) {
  301. final LocalDateTime firstInsertTime = wechatBillPayApplyRepo.getFirstInsertTime(payId);
  302. final WechatBillPayApply payApply = null == firstInsertTime ?
  303. null : wechatBillPayApplyRepo.findByPayIdAndInsertTime(payId, firstInsertTime);
  304. if (null != payApply) {
  305. response.setPayMsg(StringUtils.isEmpty(payApply.getErrCodeDes()) ? payApply.getResErrCodeDes() :
  306. payApply.getErrCodeDes());
  307. response.setWxOrderId(payApply.getOutTradeNo());
  308. }
  309. }
  310. //扣款成功,需返回微信支付订单号
  311. if (fssPaccountPay.getStatus().equals(1) && StringUtils.isNotBlank(fssPaccountPay.getWxOrderId())) {
  312. WechatBillPaySuccess paySuccess = successRepo.findByOutTradeNo(fssPaccountPay.getWxOrderId());
  313. if (null != paySuccess) {
  314. response.setTransactionId(paySuccess.getTransactionId());
  315. } else {
  316. AflApPayOrder aflApPayOrder = apPayOrderRepo.findByOrderNo(fssPaccountPay.getWxOrderId());
  317. if (null != aflApPayOrder) {
  318. response.setTransactionId(aflApPayOrder.getTransactionId());
  319. }
  320. }
  321. }
  322. return response;
  323. }
  324. }