SettlementDocumentaryFeesServiceImpl.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. package com.ydtech.modules.fnc.service.impl;
  2. import com.alibaba.fastjson.JSON;
  3. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  6. import com.github.pagehelper.PageHelper;
  7. import com.github.pagehelper.PageInfo;
  8. import com.google.gson.Gson;
  9. import com.ydtech.core.page.HttpResult;
  10. import com.ydtech.modules.base.controller.BaseController;
  11. import com.ydtech.modules.fnc.dao.InsPlyIncomeMapper;
  12. import com.ydtech.modules.fnc.dao.SettlementDocumentaryFeesMapper;
  13. import com.ydtech.modules.fnc.entity.InsPlyIncome;
  14. import com.ydtech.modules.fnc.entity.SettlementDocumentaryFeesEntity;
  15. import com.ydtech.modules.fnc.entity.SettlementDocumentaryLogEntity;
  16. import com.ydtech.modules.fnc.service.SettlementDocumentaryFeesService;
  17. import com.ydtech.modules.fnc.service.SettlementDocumentaryLogService;
  18. import com.ydtech.modules.fnc.vo.InsPlyIncomeVo;
  19. import com.ydtech.modules.fnc.vo.SettlementDocumentaryFeesVo;
  20. import com.ydtech.modules.order.entity.BasePageResult;
  21. import com.ydtech.modules.order.entity.InsOrders;
  22. import org.apache.commons.lang3.ObjectUtils;
  23. import org.apache.commons.lang3.StringUtils;
  24. import org.springframework.beans.BeanUtils;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.stereotype.Service;
  27. import org.springframework.transaction.annotation.Transactional;
  28. import java.math.BigDecimal;
  29. import java.util.Date;
  30. import java.util.HashMap;
  31. import java.util.List;
  32. @Service
  33. public class SettlementDocumentaryFeesServiceImpl extends ServiceImpl<SettlementDocumentaryFeesMapper, SettlementDocumentaryFeesEntity> implements SettlementDocumentaryFeesService {
  34. @Autowired
  35. private SettlementDocumentaryLogService settlementDocumentaryLogService;
  36. @Autowired
  37. private InsPlyIncomeMapper insPlyIncomeMapper;
  38. @Override
  39. public HttpResult<BasePageResult<SettlementDocumentaryFeesEntity>> querySettle(SettlementDocumentaryFeesVo settlementDocumentaryFeesVo) {
  40. try {
  41. HashMap<String, Object> params = new HashMap<>();
  42. params.put("pageNum", settlementDocumentaryFeesVo.getPageNum());
  43. params.put("pageSize", settlementDocumentaryFeesVo.getPageSize());
  44. if (StringUtils.isNotEmpty(settlementDocumentaryFeesVo.getHandlingFeesStatus())) {
  45. params.put("handlingFeesStatus", settlementDocumentaryFeesVo.getHandlingFeesStatus());
  46. }
  47. if (StringUtils.isNotEmpty(settlementDocumentaryFeesVo.getAgreementType())) {
  48. params.put("agreementType", settlementDocumentaryFeesVo.getAgreementType());
  49. }
  50. if (StringUtils.isNotEmpty(settlementDocumentaryFeesVo.getIsNotCar())) {
  51. params.put("isNotCar", settlementDocumentaryFeesVo.getIsNotCar());
  52. }
  53. if (StringUtils.isNotEmpty(settlementDocumentaryFeesVo.getPartnerCompaniesId())) {
  54. params.put("partnerCompaniesId", settlementDocumentaryFeesVo.getPartnerCompaniesId());
  55. }
  56. if (StringUtils.isNotEmpty(settlementDocumentaryFeesVo.getParentId())) {
  57. params.put("parentId", settlementDocumentaryFeesVo.getParentId());
  58. }
  59. PageInfo<List<SettlementDocumentaryFeesEntity>> pageHelper = null;
  60. List<SettlementDocumentaryFeesEntity> list = this.baseMapper.querySettle(params);
  61. pageHelper = new PageInfo(list);
  62. BasePageResult<SettlementDocumentaryFeesEntity> pageResult = new BasePageResult<SettlementDocumentaryFeesEntity>(settlementDocumentaryFeesVo.getPageNum(), settlementDocumentaryFeesVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  63. return HttpResult.ok(pageResult);
  64. } catch (Exception e) {
  65. e.printStackTrace();
  66. return HttpResult.error("查询异常");
  67. }
  68. }
  69. @Override
  70. @Transactional
  71. public HttpResult inertSettle(SettlementDocumentaryFeesVo settlementDocumentaryFeesVo) {
  72. int i = this.compareAmount(settlementDocumentaryFeesVo.getTotalAmount(), settlementDocumentaryFeesVo.getSettlementAmount());
  73. if (i < 0) {
  74. return HttpResult.error("结算金额大于总金额,请重新结算");
  75. }
  76. SettlementDocumentaryFeesEntity settlementDocumentaryFeesEntity = new SettlementDocumentaryFeesEntity();
  77. BeanUtils.copyProperties(settlementDocumentaryFeesVo, settlementDocumentaryFeesEntity);
  78. baseMapper.insert(settlementDocumentaryFeesEntity);
  79. // 生成跟单费结算记录
  80. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  81. settlementDocumentaryLogEntity.setAmount(settlementDocumentaryFeesVo.getSettlementAmount()); // 结算金额
  82. settlementDocumentaryLogEntity.setSettlementDocumentaryId(settlementDocumentaryFeesEntity.getId()); // 关联id
  83. settlementDocumentaryLogEntity.setAmountType("2"); //跟单费结算
  84. settlementDocumentaryLogEntity.setCreateTime(new Date());
  85. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  86. return HttpResult.ok("结算成功");
  87. }
  88. @Override
  89. @Transactional
  90. public HttpResult documentarySettle(SettlementDocumentaryFeesVo settlementDocumentaryFeesVo) {
  91. SettlementDocumentaryFeesEntity settlementDocumentaryFeesEntity = baseMapper.selectById(settlementDocumentaryFeesVo.getId());
  92. if (settlementDocumentaryFeesVo.getSettlementAmount() != null && ObjectUtils.isNotEmpty(settlementDocumentaryFeesEntity)) {
  93. int i = this.compareAmount(settlementDocumentaryFeesEntity.getUnsettledAmount(), settlementDocumentaryFeesVo.getSettlementAmount());
  94. if (i < 0) {
  95. return HttpResult.error("结算金额大于未结算金额,请重新结算");
  96. }
  97. settlementDocumentaryFeesEntity.setSettlementAmount(settlementDocumentaryFeesEntity.getSettlementAmount().add(settlementDocumentaryFeesVo.getSettlementAmount()));
  98. settlementDocumentaryFeesEntity.setUnsettledAmount(settlementDocumentaryFeesEntity.getTotalAmount().subtract(settlementDocumentaryFeesEntity.getSettlementAmount())); //未结算金额
  99. baseMapper.updateById(settlementDocumentaryFeesEntity);
  100. // 记录
  101. // 生成跟单费结算记录
  102. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  103. settlementDocumentaryLogEntity.setAmount(settlementDocumentaryFeesVo.getSettlementAmount()); // 结算金额
  104. settlementDocumentaryLogEntity.setSettlementDocumentaryId(settlementDocumentaryFeesEntity.getId()); // 关联id
  105. settlementDocumentaryLogEntity.setAmountType("2"); //跟单费结算
  106. settlementDocumentaryLogEntity.setCreateTime(new Date());
  107. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  108. return HttpResult.ok("修改成功");
  109. }
  110. return null;
  111. }
  112. /**
  113. * @param invoiceIds 结算表的id
  114. * @return 返回开票号 开票金额 开票时间
  115. */
  116. @Override
  117. public List<HashMap<String, Object>> getOtherSettldetail(HashMap<String, Object> params) {
  118. return baseMapper.getOtherSettldetail(params);
  119. }
  120. /**
  121. * @param ids 开票ids
  122. * @param invoicingMethod 开票方式 0 保司开票 1 掌柜开票
  123. * @param taxPoints 税点
  124. */
  125. @Override
  126. public void batchByInvoice(String ids, String invoicingMethod, BigDecimal taxPoints, BigDecimal invoicCommissionFeevalue) {
  127. /**
  128. * 跟单开票处新增开票方式:保司开票/掌柜开票
  129. *
  130. * 如果是保司开票,需要填写税点,后续在结算时,税收成本算做支出项,进账金额=开票金额*(1-税点),但统计应收金额
  131. * ,开票金额,已收金额,开票未进账金额均按照不扣税点的金额核算。
  132. *
  133. * 如果是掌柜开票,需要填写税点,但后续结算时,进账金额=开票金额。
  134. *
  135. * */
  136. // 结算金额 收款金额=开票金额*(1-税点)
  137. HashMap<String, Object> params = new HashMap<>();
  138. params.put("ids", ids.split(","));
  139. baseMapper.batchByInvoice(params);
  140. }
  141. @Override
  142. public List<HashMap<String, Object>> getInvoicIds(HashMap<String, Object> params) {
  143. return baseMapper.getInvoicIds(params);
  144. }
  145. @Override
  146. public SettlementDocumentaryFeesEntity getByParentSettlementAmount(String id) {
  147. return baseMapper.getByParentSettlementAmount(id);
  148. }
  149. /**
  150. * 作废开票 settlementStatus 为3表示为作废开票
  151. *
  152. * @param settlementDocumentaryFeesVo
  153. */
  154. @Override
  155. public void voidInvoicing(SettlementDocumentaryFeesVo settlementDocumentaryFeesVo) {
  156. SettlementDocumentaryFeesEntity oldSettlementDocumentaryFeesEntity = baseMapper.selectById(settlementDocumentaryFeesVo.getId());
  157. String taskId = oldSettlementDocumentaryFeesEntity.getTaskId();
  158. HashMap<String, Object> params = new HashMap<>();
  159. params.put("taskId", taskId);
  160. List<InsPlyIncome> insPlyIncomes = insPlyIncomeMapper.queryNew(params);
  161. for (InsPlyIncome item : insPlyIncomes) {
  162. LambdaUpdateWrapper<InsPlyIncome> wrapper = new LambdaUpdateWrapper<>();
  163. wrapper.eq(InsPlyIncome::getId, item.getId());
  164. wrapper.set(InsPlyIncome::getHandlingFeesStatus, "0");
  165. wrapper.set(InsPlyIncome::getTaskId, null);
  166. insPlyIncomeMapper.update(item, wrapper);
  167. }
  168. SettlementDocumentaryFeesEntity settlementDocumentaryFeesEntity = new SettlementDocumentaryFeesEntity();
  169. BeanUtils.copyProperties(settlementDocumentaryFeesVo, settlementDocumentaryFeesEntity);
  170. settlementDocumentaryFeesEntity.setSettlementStatus("3"); // 3 为作废
  171. baseMapper.updateById(settlementDocumentaryFeesEntity);
  172. }
  173. private int compareAmount(BigDecimal settlementAmount, BigDecimal settlementAmount1) {
  174. return settlementAmount.compareTo(settlementAmount1);
  175. }
  176. }