TFeeServiceImpl.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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. Map<String, Object> map = new HashMap<>();
  176. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  177. if (StringUtils.isNull(tFee.getfId())) {
  178. // 如果是新数据
  179. tFee.setCreateBy(loginUser.getUser().getUserName());
  180. tFee.setfDeptid(loginUser.getUser().getDeptId());
  181. tFee.setfBilltype(fBilltype);
  182. // 业务编码
  183. Date time = new Date();
  184. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  185. tFee.setfBillno(billNo);
  186. tFeeMapper.insertTFee(tFee);
  187. fPid = tFee.getfId();
  188. } else {
  189. fPid = tFee.getfId();
  190. tFee.setUpdateBy(loginUser.getUser().getUserName());
  191. tFee.setUpdateTime(new Date());
  192. tFeeMapper.updateTFee(tFee);
  193. // 删除从表
  194. tFeeDoMapper.deleteByFPid(fPid);
  195. }
  196. // 财务从表
  197. if (StringUtils.isNotNull(tfeeDo)) {
  198. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  199. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  200. for (TFeeDo tFeeDo : tFeeDoList) {
  201. tFeeDo.setfPid(fPid);
  202. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  203. tFeeDo.setCreateTime(new Date());
  204. tFeeDoMapper.insertTFeeDo(tFeeDo);
  205. }
  206. }
  207. map.put("tFee", tFee);
  208. return AjaxResult.success("成功", map);
  209. }
  210. /**
  211. * 修改财务数据主
  212. *
  213. * @param tFee 财务数据主
  214. * @return 结果
  215. */
  216. @Override
  217. public int updateTFee(TFee tFee) {
  218. tFee.setUpdateTime(DateUtils.getNowDate());
  219. return tFeeMapper.updateTFee(tFee);
  220. }
  221. /**
  222. * 批量删除财务数据主
  223. *
  224. * @param fIds 需要删除的财务数据主ID
  225. * @return 结果
  226. */
  227. @Override
  228. public int deleteTFeeByIds(Long[] fIds) {
  229. // 取出业务编号、 放入 billno_del
  230. for (Long id : fIds) {
  231. // 1、查询主表信息
  232. TFee tFee = tFeeMapper.selectTFeeById(id);
  233. // 2、业务编号、客存编号 放入 billno_del
  234. BillnoDel billnoDel = new BillnoDel();
  235. billnoDel.setBillType(tFee.getfBilltype());
  236. billnoDel.setBillNo(tFee.getfBillno());
  237. billnoDelMapper.insertBillnoDel(billnoDel);
  238. }
  239. return tFeeMapper.deleteTFeeByIds(fIds);
  240. }
  241. /**
  242. * 删除财务数据主信息
  243. *
  244. * @param fId 财务数据主ID
  245. * @return 结果
  246. */
  247. @Override
  248. public int deleteTFeeById(Long fId) {
  249. return tFeeMapper.deleteTFeeById(fId);
  250. }
  251. @Override
  252. public List<Map<String, Object>> warehouseBillsFeesList(TWareHouseFees tWareHouseFees) {
  253. List<Map<String, Object>> maps =new ArrayList<Map<String, Object>>();
  254. Map<String, Object> map = new HashMap<>();
  255. map.put("tWareHouseFees", tWareHouseFees);
  256. List<Map<String, Object>> mapList = tFeeMapper.warehouseBillsFeesList(map);
  257. if (mapList != null && mapList.size() > 0) {
  258. String fAmtdr = null; // 金额
  259. String fAmt = null; // 结算
  260. for (Map<String, Object> m : mapList) {
  261. for (String k : m.keySet()) {
  262. if (k.equals("fAmtdr")) {
  263. fAmtdr = m.get(k).toString();
  264. }
  265. if (k.equals("fAmt")) {
  266. fAmt = m.get(k).toString();
  267. }
  268. }
  269. BigDecimal result = calculation1(fAmtdr, fAmt);
  270. m.put("fAmtdr",result);
  271. m.put("fAmt",result);
  272. maps.add(m);/*if(result.compareTo(BigDecimal.ZERO) > 0) {
  273. maps.add(m);
  274. }*/
  275. }
  276. }
  277. return maps;
  278. }
  279. public static BigDecimal calculation1(String fTotalgross, String fGrossweightblc) {
  280. BigDecimal num1 = new BigDecimal(fTotalgross);
  281. BigDecimal num2 = new BigDecimal(fGrossweightblc);
  282. BigDecimal result = num1.subtract(num2);
  283. return result.setScale(2, BigDecimal.ROUND_HALF_UP);
  284. }
  285. @Override
  286. @Transactional
  287. public AjaxResult confirm(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  288. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  289. if (StringUtils.isNull(tFee.getfId())) {
  290. // 如果是新数据
  291. tFee.setCreateBy(loginUser.getUser().getUserName());
  292. tFee.setfDeptid(loginUser.getUser().getDeptId());
  293. tFee.setfBilltype(fBilltype);
  294. // 业务编码
  295. Date time = new Date();
  296. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  297. tFee.setfBillno(billNo);
  298. tFeeMapper.insertTFee(tFee);
  299. } else {
  300. tFee.setUpdateBy(loginUser.getUser().getUserName());
  301. tFee.setUpdateTime(new Date());
  302. tFeeMapper.updateTFee(tFee);
  303. // 删除从表
  304. tFeeDoMapper.deleteByFPid(tFee.getfId());
  305. }
  306. // 财务从表
  307. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  308. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  309. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  310. for (TFeeDo tFeeDo : tFeeDoList) {
  311. tFeeDo.setfPid(tFee.getfId());
  312. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  313. tFeeDo.setCreateTime(new Date());
  314. tFeeDoMapper.insertTFeeDo(tFeeDo);
  315. }
  316. }
  317. // 这里加个判断取系统参数来确定是否需要启用审批流
  318. String key = "";
  319. boolean isApprove = false;
  320. long actId = 0L;
  321. if ("DZ".equals(fBilltype)) {
  322. actId = 210L;
  323. key = "warehouse.contrast.ApprovalFlow";
  324. } else if ("SF".equals(fBilltype)) {
  325. actId = 220L;
  326. key = "warehouse.charge.ApprovalFlow";
  327. } else if ("FF".equals(fBilltype)) {
  328. actId = 230L;
  329. key = "warehouse.payment.ApprovalFlow";
  330. }
  331. SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique(key);
  332. if (StringUtils.isNull(sysConfig)) {
  333. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  334. return AjaxResult.error("系统参数异常,未找到开启审批流参数");
  335. }
  336. if ("0".equals(sysConfig.getConfigValue())) {
  337. isApprove = true;
  338. }
  339. if (isApprove) {
  340. AuditItems auditItems = new AuditItems();
  341. auditItems.setLevelId(0L);
  342. auditItems.setBillId(tFee.getfId());
  343. auditItems.setActId(actId);
  344. auditItems.setIffinalItem("F");
  345. auditItems.setBillNo(tFee.getfBillno()); // 业务编号
  346. auditItems.setRefno1(String.valueOf(tFee.getfCorpid())); // 货权方
  347. auditItems.setRefno2(tFee.getfBilltype());// 财务类型
  348. auditItems.setRefno3(tFee.gettMblno());// 提单号
  349. auditItems.setSendUserId(loginUser.getUser().getUserId());
  350. auditItems.setSendName(loginUser.getUsername());
  351. auditItems.setSendTime(new Date());
  352. auditItems.setAuditUserId(loginUser.getUser().getUserId());
  353. auditItems.setAuditItem(new Date());
  354. auditItems.setAuditMsg("提交");
  355. auditItems.setAuditStatus("O");
  356. AjaxResult approvalFlow = auditItemsService.createApprovalFlow(auditItems);
  357. Long code = Long.valueOf(String.valueOf(approvalFlow.get("code"))).longValue();
  358. if (code.equals(500L)) {
  359. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  360. }
  361. return approvalFlow;
  362. }else {
  363. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  364. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  365. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  366. for (TFeeDo tFeeDo : tFeeDoList) {
  367. // 跟新费用明细
  368. int m = updateBillsFees(tFee.getfId(),tFeeDo,fBilltype);
  369. if (m == 0) {
  370. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  371. return AjaxResult.error("更新费用明细失败");
  372. }
  373. }
  374. }
  375. AjaxResult ajaxResult = tfeeFollow(tFee.getfId(), 6L);
  376. Long code = Long.valueOf(String.valueOf(ajaxResult.get("code"))).longValue();
  377. return ajaxResult;
  378. }
  379. }
  380. /**
  381. * 根据财务主表id 更新对应明细表状态
  382. *
  383. * @param fPid 财务主表id
  384. * @return 结果
  385. */
  386. @Transactional
  387. public AjaxResult tfeeFollow(Long fPid, long fettle) {
  388. if (StringUtils.isNull(fPid)) {
  389. return AjaxResult.error("财务更新状态未找到主表信息,请与管理员联系");
  390. }
  391. TFee tFee = new TFee();
  392. tFee.setfId(fPid);
  393. tFee.setfBillstatus(String.valueOf(fettle));
  394. int tFeeUpdateResult = tFeeMapper.updateTFee(tFee);
  395. if (tFeeUpdateResult <= 0) {
  396. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  397. return AjaxResult.error("更新财务明细状态失败,请联系管理员");
  398. }
  399. int itemUpdateResult = tFeeDoMapper.tfeeDoFollowUpdate(fPid,fettle);
  400. if (itemUpdateResult <= 0) {
  401. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  402. return AjaxResult.error("更新财务明细状态失败,请联系管理员");
  403. }
  404. return AjaxResult.success();
  405. }
  406. @Transactional
  407. public AjaxResult billsfeesFollow(Long fPid) {
  408. if (StringUtils.isNull(fPid)) {
  409. return AjaxResult.error("费用明细更新状态未找到主表信息,请与管理员联系");
  410. }
  411. TFee tFee=tFeeMapper.selectTFeeById(fPid);
  412. // 查询从表数据
  413. TFeeDo tFeeDo = new TFeeDo();
  414. tFeeDo.setfPid(fPid);
  415. List<TFeeDo> tFeeDoList= tFeeDoMapper.selectTFeeDoList(tFeeDo);
  416. for (TFeeDo tFeeDo1 : tFeeDoList) {
  417. // 跟新费用明细
  418. int m = updateBillsFees(fPid,tFeeDo1,tFee.getfBilltype());
  419. if (m == 0) {
  420. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  421. return AjaxResult.error("更新费用明细失败");
  422. }
  423. }
  424. return AjaxResult.success();
  425. }
  426. @Override
  427. @Transactional
  428. public AjaxResult revoke(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  429. // 更新 主表、从表
  430. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  431. tFee.setUpdateBy(loginUser.getUser().getUserName());
  432. tFee.setUpdateTime(new Date());
  433. tFeeMapper.updateTFee(tFee);
  434. // 删除从表
  435. tFeeDoMapper.deleteByFPid(tFee.getfId());
  436. // 财务从表
  437. if (StringUtils.isNotNull(tfeeDo)) {
  438. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  439. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  440. for (TFeeDo tFeeDo : tFeeDoList) {
  441. tFeeDo.setfPid(tFee.getfId());
  442. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  443. tFeeDo.setCreateTime(new Date());
  444. tFeeDoMapper.insertTFeeDo(tFeeDo);
  445. // 跟新费用明细
  446. int m = updateBillsFees(tFee.getfId(),tFeeDo,fBilltype);
  447. if (m == 0) {
  448. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  449. return AjaxResult.error("更新费用明细失败");
  450. }
  451. }
  452. }
  453. return AjaxResult.success();
  454. }
  455. @Override
  456. public AjaxResult queryRemove(Long fId) {
  457. TFee tFee=tFeeMapper.selectTFeeById(fId);
  458. TFeeDo tFeeDo = new TFeeDo();
  459. tFeeDo.setfPid(tFee.getfId());
  460. List<TFeeDo> tFeeDoList= tFeeDoMapper.selectTFeeDoList(tFeeDo);
  461. if( StringUtils.isNull(tFee)){
  462. return AjaxResult.success("0");
  463. } else if(StringUtils.isNotNull(tFee) && StringUtils.isEmpty(tFeeDoList) ){
  464. return AjaxResult.success("1");
  465. } else {
  466. return AjaxResult.success("2");
  467. }
  468. }
  469. /**
  470. * 更新费用明细
  471. * @param fid
  472. * @param tFeeDo
  473. * @param billsType
  474. * @return
  475. */
  476. @Transactional
  477. public int updateBillsFees(Long fid,TFeeDo tFeeDo,String billsType){
  478. // 查询从表数据
  479. TFee tFee=tFeeMapper.selectTFeeById(fid);
  480. if(billsType.equals("SF") || billsType.equals("FF")){
  481. billsType="DC";
  482. }
  483. Map<String, Object> map = new HashMap<>();
  484. map.put("tFee", tFee);
  485. map.put("billType", billsType);
  486. map.put("tFeeDo", tFeeDo);
  487. return tWarehousebillsfeesMapper.updateTWarehousebillsfee(map);
  488. }
  489. }