TFeeServiceImpl.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. package com.ruoyi.finance.service.impl;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.ruoyi.approvalFlow.domain.AuditItems;
  5. import com.ruoyi.approvalFlow.service.impl.AuditItemsServiceImpl;
  6. import com.ruoyi.basicData.domain.TCorps;
  7. import com.ruoyi.basicData.domain.TFees;
  8. import com.ruoyi.basicData.mapper.TCorpsMapper;
  9. import com.ruoyi.basicData.mapper.TFeesMapper;
  10. import com.ruoyi.common.core.domain.AjaxResult;
  11. import com.ruoyi.common.core.domain.model.LoginUser;
  12. import com.ruoyi.common.utils.DateUtils;
  13. import com.ruoyi.common.utils.StringUtils;
  14. import com.ruoyi.finance.domain.TFee;
  15. import com.ruoyi.finance.domain.TFeeDo;
  16. import com.ruoyi.finance.domain.TWareHouseFees;
  17. import com.ruoyi.finance.mapper.TFeeDoMapper;
  18. import com.ruoyi.finance.mapper.TFeeMapper;
  19. import com.ruoyi.finance.service.ITFeeService;
  20. import com.ruoyi.system.domain.SysConfig;
  21. import com.ruoyi.system.mapper.SysConfigMapper;
  22. import com.ruoyi.warehouseBusiness.domain.*;
  23. import com.ruoyi.warehouseBusiness.mapper.BillnoDelMapper;
  24. import com.ruoyi.warehouseBusiness.mapper.TWarehouseBillsMapper;
  25. import com.ruoyi.warehouseBusiness.mapper.TWarehousebillsfeesMapper;
  26. import com.ruoyi.warehouseBusiness.service.impl.BillnoSerialServiceImpl;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.stereotype.Service;
  29. import org.springframework.transaction.annotation.Transactional;
  30. import org.springframework.transaction.interceptor.TransactionAspectSupport;
  31. import java.math.BigDecimal;
  32. import java.util.*;
  33. /**
  34. * 财务数据主Service业务层处理
  35. *
  36. * @author ruoyi
  37. * @date 2021-01-18
  38. */
  39. @Service
  40. public class TFeeServiceImpl implements ITFeeService {
  41. @Autowired
  42. private TFeeMapper tFeeMapper;
  43. @Autowired
  44. private TFeeDoMapper tFeeDoMapper;
  45. @Autowired
  46. private BillnoSerialServiceImpl billnoSerialServiceImpl;
  47. @Autowired
  48. private BillnoDelMapper billnoDelMapper;
  49. @Autowired
  50. private TCorpsMapper tCorpsMapper;
  51. @Autowired
  52. private TFeesMapper tFeesMapper;
  53. @Autowired
  54. private TWarehouseBillsMapper tWarehouseBillsMapper;
  55. @Autowired
  56. private TWarehousebillsfeesMapper tWarehousebillsfeesMapper;
  57. @Autowired
  58. private SysConfigMapper sysConfigMapper;
  59. @Autowired
  60. private AuditItemsServiceImpl auditItemsService;
  61. /**
  62. * 查询财务数据主
  63. *
  64. * @param fId 财务数据主ID
  65. * @return 财务数据主
  66. */
  67. @Override
  68. public Map<String, Object> selectTFeeById(Long fId) {
  69. Map<String, Object> map = new HashMap<>();
  70. // 客户表
  71. List<Long> corpsId = new ArrayList<>();
  72. // 费用
  73. List<Long> feesId = new ArrayList<>();
  74. TFee tFee=tFeeMapper.selectTFeeById(fId);
  75. if (StringUtils.isNotNull(tFee.getfCorpid())) {
  76. corpsId.add(tFee.getfCorpid());
  77. }
  78. corpsId.add(tFee.getfCorpid());
  79. // 查询从表数据
  80. TFeeDo tFeeDo = new TFeeDo();
  81. tFeeDo.setfPid(fId);
  82. List<TFeeDo> tFeeDoList= tFeeDoMapper.selectTFeeDoList(tFeeDo);
  83. List<Map<String, Object>> feeDoList=new ArrayList<>();
  84. if (StringUtils.isNotEmpty(tFeeDoList)) {
  85. for (TFeeDo fees : tFeeDoList) {
  86. Map<String, Object> map1 = new HashMap<>();
  87. feesId.add(fees.getfFeeid());
  88. // 查询主表
  89. TWarehouseBills tWarehousebills = tWarehouseBillsMapper.selectTWarehousebillsById(fees.getfSrcpid());
  90. // 费用名称
  91. TFees tFees= tFeesMapper.selectTFeesById(fees.getfFeeid());
  92. map1.put("fId",fees.getfId());
  93. map1.put("fSrcid",fees.getfSrcid());
  94. map1.put("fSrcpid",fees.getfSrcpid());
  95. map1.put("fMblno",tWarehousebills.getfMblno());
  96. map1.put("fBscorpno",tWarehousebills.getfBscorpno());
  97. map1.put("fProductName",tWarehousebills.getfProductName());
  98. map1.put("fBsdate",tWarehousebills.getfBsdate());
  99. map1.put("fFeeid",fees.getfFeeid());
  100. map1.put("fFeeName",tFees.getfName());
  101. map1.put("fSrcdc",fees.getfSrcdc());
  102. map1.put("fAmt",fees.getfAmt());
  103. map1.put("fAmtdr",fees.getfAmtdr());
  104. map1.put("fRemarks",fees.getfRemarks());
  105. if(tWarehousebills.getfBilltype().equals("SJRK")){
  106. map1.put("fBilltype","入库");
  107. } else if(tWarehousebills.getfBilltype().equals("SJCK")){
  108. map1.put("fBilltype","出库");
  109. } else if(tWarehousebills.getfBilltype().equals("CKDB")){
  110. map1.put("fBilltype","调拨");
  111. } else if(tWarehousebills.getfBilltype().equals("HQZY")){
  112. map1.put("fBilltype","货权转移");
  113. }
  114. feeDoList.add(map1);
  115. }
  116. }
  117. List<TCorps> corpsList = new ArrayList<>();
  118. List<Long> corpsIdList = StringUtils.integerDeduplication(corpsId);
  119. for (Long corpId : corpsIdList) {
  120. TCorps corps = tCorpsMapper.selectTCorpsById(corpId);
  121. if (StringUtils.isNotNull(corps)) {
  122. corpsList.add(corps);
  123. }
  124. }
  125. List<TFees> feesList = new ArrayList<>();
  126. List<Long> longList = StringUtils.integerDeduplication(feesId);
  127. for (Long fees : longList) {
  128. TFees tFees = tFeesMapper.selectTFeesById(fees);
  129. if (StringUtils.isNotNull(tFees)) {
  130. feesList.add(tFees);
  131. }
  132. }
  133. map.put("tFee",tFee);
  134. map.put("corps",corpsList);
  135. map.put("feesList", feesList);
  136. map.put("feeDoList",feeDoList);
  137. return map;
  138. }
  139. /**
  140. * 查询财务数据主列表
  141. *
  142. * @param tFee 财务数据主
  143. * @return 财务数据主
  144. */
  145. @Override
  146. public List<TFee> selectTFeeList(TFee tFee) {
  147. return tFeeMapper.selectTFeeList(tFee);
  148. }
  149. @Override
  150. public List<Map<String, Object>> selectTFeeList1(TFee tFee) {
  151. return tFeeMapper.selectTFeeList1(tFee);
  152. }
  153. /**
  154. * 新增财务数据主
  155. *
  156. * @param tFee 财务数据主
  157. * @return 结果
  158. */
  159. @Override
  160. public int insertTFee(TFee tFee) {
  161. tFee.setCreateTime(DateUtils.getNowDate());
  162. return tFeeMapper.insertTFee(tFee);
  163. }
  164. /**
  165. * 新增对账 、收费、
  166. * @param tfee
  167. * @param tfeeDo
  168. * @param loginUser
  169. * @param fBilltype
  170. * @return
  171. */
  172. @Override
  173. public AjaxResult insertTFeeTFeeDo(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  174. Long fPid = null;
  175. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  176. if (StringUtils.isNull(tFee.getfId())) {
  177. // 如果是新数据
  178. tFee.setCreateBy(loginUser.getUser().getUserName());
  179. tFee.setfBilltype(fBilltype);
  180. // 业务编码
  181. Date time = new Date();
  182. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  183. tFee.setfBillno(billNo);
  184. tFeeMapper.insertTFee(tFee);
  185. fPid = tFee.getfId();
  186. } else {
  187. fPid = tFee.getfId();
  188. tFee.setUpdateBy(loginUser.getUser().getUserName());
  189. tFee.setUpdateTime(new Date());
  190. tFeeMapper.updateTFee(tFee);
  191. // 删除从表
  192. tFeeDoMapper.deleteByFPid(fPid);
  193. }
  194. // 财务从表
  195. if (StringUtils.isNotNull(tfeeDo)) {
  196. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  197. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  198. for (TFeeDo tFeeDo : tFeeDoList) {
  199. tFeeDo.setfPid(fPid);
  200. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  201. tFeeDo.setCreateTime(new Date());
  202. tFeeDoMapper.insertTFeeDo(tFeeDo);
  203. }
  204. }
  205. return AjaxResult.success();
  206. }
  207. /**
  208. * 修改财务数据主
  209. *
  210. * @param tFee 财务数据主
  211. * @return 结果
  212. */
  213. @Override
  214. public int updateTFee(TFee tFee) {
  215. tFee.setUpdateTime(DateUtils.getNowDate());
  216. return tFeeMapper.updateTFee(tFee);
  217. }
  218. /**
  219. * 批量删除财务数据主
  220. *
  221. * @param fIds 需要删除的财务数据主ID
  222. * @return 结果
  223. */
  224. @Override
  225. public int deleteTFeeByIds(Long[] fIds) {
  226. // 取出业务编号、 放入 billno_del
  227. for (Long id : fIds) {
  228. // 1、查询主表信息
  229. TFee tFee = tFeeMapper.selectTFeeById(id);
  230. // 2、业务编号、客存编号 放入 billno_del
  231. BillnoDel billnoDel = new BillnoDel();
  232. billnoDel.setBillType(tFee.getfBilltype());
  233. billnoDel.setBillNo(tFee.getfBillno());
  234. billnoDelMapper.insertBillnoDel(billnoDel);
  235. }
  236. return tFeeMapper.deleteTFeeByIds(fIds);
  237. }
  238. /**
  239. * 删除财务数据主信息
  240. *
  241. * @param fId 财务数据主ID
  242. * @return 结果
  243. */
  244. @Override
  245. public int deleteTFeeById(Long fId) {
  246. return tFeeMapper.deleteTFeeById(fId);
  247. }
  248. @Override
  249. public List<Map<String, Object>> warehouseBillsFeesList(TWareHouseFees tWareHouseFees) {
  250. List<Map<String, Object>> maps =new ArrayList<Map<String, Object>>();
  251. Map<String, Object> map = new HashMap<>();
  252. map.put("tWareHouseFees", tWareHouseFees);
  253. List<Map<String, Object>> mapList = tFeeMapper.warehouseBillsFeesList(map);
  254. if (mapList != null && mapList.size() > 0) {
  255. String fAmtdr = null; // 金额
  256. String fAmt = null; // 结算
  257. for (Map<String, Object> m : mapList) {
  258. for (String k : m.keySet()) {
  259. if (k.equals("fAmtdr")) {
  260. fAmtdr = m.get(k).toString();
  261. }
  262. if (k.equals("fAmt")) {
  263. fAmt = m.get(k).toString();
  264. }
  265. }
  266. BigDecimal result = calculation1(fAmtdr, fAmt);
  267. m.put("fAmtdr",result);
  268. m.put("fAmt",result);
  269. maps.add(m);
  270. }
  271. }
  272. return maps;
  273. }
  274. public static BigDecimal calculation1(String fTotalgross, String fGrossweightblc) {
  275. BigDecimal num1 = new BigDecimal(fTotalgross);
  276. BigDecimal num2 = new BigDecimal(fGrossweightblc);
  277. BigDecimal result = num1.subtract(num2);
  278. return result.setScale(2, BigDecimal.ROUND_HALF_UP);
  279. }
  280. @Override
  281. @Transactional
  282. public AjaxResult confirm(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  283. // 更新 主表、从表
  284. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  285. tFee.setUpdateBy(loginUser.getUser().getUserName());
  286. tFee.setUpdateTime(new Date());
  287. tFeeMapper.updateTFee(tFee);
  288. // 删除从表
  289. tFeeDoMapper.deleteByFPid(tFee.getfId());
  290. // 财务从表
  291. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  292. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  293. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  294. for (TFeeDo tFeeDo : tFeeDoList) {
  295. tFeeDo.setfPid(tFee.getfId());
  296. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  297. tFeeDo.setCreateTime(new Date());
  298. tFeeDoMapper.insertTFeeDo(tFeeDo);
  299. // 跟新费用明细
  300. int m = updateBillsFees(tFee.getfId(),tFeeDo,fBilltype);
  301. if (m == 0) {
  302. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  303. return AjaxResult.error("更新费用明细失败");
  304. }
  305. }
  306. }
  307. // 这里加个判断取系统参数来确定是否需要启用审批流
  308. String key = "";
  309. boolean isApprove = false;
  310. long actId = 0L;
  311. if ("DZ".equals(fBilltype)) {
  312. actId = 210L;
  313. key = "warehouse.contrast.ApprovalFlow";
  314. } else if ("SF".equals(fBilltype)) {
  315. actId = 220L;
  316. key = "warehouse.charge.ApprovalFlow";
  317. } else if ("FF".equals(fBilltype)) {
  318. actId = 230L;
  319. key = "warehouse.payment.ApprovalFlow";
  320. }
  321. SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique(key);
  322. if (StringUtils.isNull(sysConfig)) {
  323. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  324. return AjaxResult.error("系统参数异常,未找到开启审批流参数");
  325. }
  326. if ("0".equals(sysConfig.getConfigValue())) {
  327. isApprove = true;
  328. }
  329. if (isApprove) {
  330. AuditItems auditItems = new AuditItems();
  331. auditItems.setLevelId(0L);
  332. auditItems.setBillId(tFee.getfId());
  333. auditItems.setActId(actId);
  334. auditItems.setIffinalItem("F");
  335. auditItems.setBillNo(tFee.getfBillno()); // 业务编号
  336. auditItems.setRefno1(String.valueOf(tFee.getfCorpid())); // 货权方
  337. auditItems.setRefno2(tFee.getfBilltype());// 财务类型
  338. auditItems.setRefno3(tFee.gettMblno());// 提单号
  339. auditItems.setSendUserId(loginUser.getUser().getUserId());
  340. auditItems.setSendName(loginUser.getUsername());
  341. auditItems.setSendTime(new Date());
  342. auditItems.setAuditUserId(loginUser.getUser().getUserId());
  343. auditItems.setAuditItem(new Date());
  344. auditItems.setAuditMsg("提交");
  345. auditItems.setAuditStatus("O");
  346. AjaxResult approvalFlow = auditItemsService.createApprovalFlow(auditItems);
  347. Long code = Long.valueOf(String.valueOf(approvalFlow.get("code"))).longValue();
  348. if (code.equals(500L)) {
  349. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  350. }
  351. return approvalFlow;
  352. }else {
  353. AjaxResult ajaxResult = tfeeFollow(tFee.getfId(), 6L);
  354. Long code = Long.valueOf(String.valueOf(ajaxResult.get("code"))).longValue();
  355. return ajaxResult;
  356. }
  357. }
  358. /**
  359. * 根据财务主表id 更新对应明细表状态
  360. *
  361. * @param fPid 财务主表id
  362. * @return 结果
  363. */
  364. @Transactional
  365. public AjaxResult tfeeFollow(Long fPid, long fettle) {
  366. if (StringUtils.isNull(fPid)) {
  367. return AjaxResult.error("财务更新状态未找到主表信息,请与管理员联系");
  368. }
  369. TFee tFee = new TFee();
  370. tFee.setfId(fPid);
  371. tFee.setfBillstatus(String.valueOf(fettle));
  372. int tFeeUpdateResult = tFeeMapper.updateTFee(tFee);
  373. if (tFeeUpdateResult <= 0) {
  374. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  375. return AjaxResult.error("更新财务明细状态失败,请联系管理员");
  376. }
  377. TFeeDo tFeeDo =new TFeeDo();
  378. tFeeDo.setfId(fPid);
  379. tFeeDo.setfStatus(String.valueOf(fettle));
  380. int itemUpdateResult = tFeeDoMapper.updateTFeeDo(tFeeDo);
  381. if (itemUpdateResult <= 0) {
  382. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  383. return AjaxResult.error("更新财务明细状态失败,请联系管理员");
  384. }
  385. return AjaxResult.success();
  386. }
  387. @Override
  388. @Transactional
  389. public AjaxResult revoke(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  390. // 更新 主表、从表
  391. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  392. tFee.setUpdateBy(loginUser.getUser().getUserName());
  393. tFee.setUpdateTime(new Date());
  394. tFeeMapper.updateTFee(tFee);
  395. // 删除从表
  396. tFeeDoMapper.deleteByFPid(tFee.getfId());
  397. // 财务从表
  398. if (StringUtils.isNotNull(tfeeDo)) {
  399. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  400. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  401. for (TFeeDo tFeeDo : tFeeDoList) {
  402. tFeeDo.setfPid(tFee.getfId());
  403. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  404. tFeeDo.setCreateTime(new Date());
  405. tFeeDoMapper.insertTFeeDo(tFeeDo);
  406. // 跟新费用明细
  407. int m = updateBillsFees(tFee.getfId(),tFeeDo,fBilltype);
  408. if (m == 0) {
  409. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  410. return AjaxResult.error("更新费用明细失败");
  411. }
  412. }
  413. }
  414. return AjaxResult.success();
  415. }
  416. @Override
  417. public AjaxResult queryRemove(Long fId) {
  418. TFee tFee=tFeeMapper.selectTFeeById(fId);
  419. TFeeDo tFeeDo = new TFeeDo();
  420. tFeeDo.setfPid(tFee.getfId());
  421. List<TFeeDo> tFeeDoList= tFeeDoMapper.selectTFeeDoList(tFeeDo);
  422. if( StringUtils.isNull(tFee)){
  423. return AjaxResult.success("0");
  424. } else if(StringUtils.isNotNull(tFee) && StringUtils.isEmpty(tFeeDoList) ){
  425. return AjaxResult.success("1");
  426. } else {
  427. return AjaxResult.success("2");
  428. }
  429. }
  430. /**
  431. * 更新费用明细
  432. * @param fid
  433. * @param tFeeDo
  434. * @param billsType
  435. * @return
  436. */
  437. @Transactional
  438. public int updateBillsFees(Long fid,TFeeDo tFeeDo,String billsType){
  439. // 查询从表数据
  440. TFee tFee=tFeeMapper.selectTFeeById(fid);
  441. if(billsType.equals("SF") || billsType.equals("FF")){
  442. billsType="DC";
  443. }
  444. Map<String, Object> map = new HashMap<>();
  445. map.put("tFee", tFee);
  446. map.put("billType", billsType);
  447. map.put("tFeeDo", tFeeDo);
  448. return tWarehousebillsfeesMapper.updateTWarehousebillsfee(map);
  449. }
  450. }