TFeeServiceImpl.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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,String billsType) {
  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 =new ArrayList<>();
  257. if(billsType.equals("DZ")){
  258. mapList = tFeeMapper.warehouseBillsFeesListAccamount(map);
  259. } else{
  260. if(tWareHouseFees.getfStatementNo()!=null && !tWareHouseFees.getfStatementNo().equals("")){
  261. mapList = tFeeMapper.warehouseBillsFeesListAccamount(map);
  262. }else {
  263. mapList = tFeeMapper.warehouseBillsFeesList(map);
  264. }
  265. }
  266. return mapList;
  267. }
  268. @Override
  269. public List<Map<String, Object>> warehouseBillsFeesList(TWareHouseFees tWareHouseFees) {
  270. return tFeeMapper.warehouseBillsFeesList1(tWareHouseFees);
  271. }
  272. public static BigDecimal calculation1(String fTotalgross, String fGrossweightblc) {
  273. BigDecimal num1 = new BigDecimal(fTotalgross);
  274. BigDecimal num2 = new BigDecimal(fGrossweightblc);
  275. BigDecimal result = num1.subtract(num2);
  276. return result.setScale(2, BigDecimal.ROUND_HALF_UP);
  277. }
  278. @Override
  279. @Transactional
  280. public AjaxResult confirm(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  281. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  282. if (StringUtils.isNull(tFee.getfId())) {
  283. // 如果是新数据
  284. tFee.setCreateBy(loginUser.getUser().getUserName());
  285. tFee.setfDeptid(loginUser.getUser().getDeptId());
  286. tFee.setfBilltype(fBilltype);
  287. // 业务编码
  288. Date time = new Date();
  289. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  290. tFee.setfBillno(billNo);
  291. tFeeMapper.insertTFee(tFee);
  292. } else {
  293. tFee.setUpdateBy(loginUser.getUser().getUserName());
  294. tFee.setUpdateTime(new Date());
  295. tFeeMapper.updateTFee(tFee);
  296. // 删除从表
  297. tFeeDoMapper.deleteByFPid(tFee.getfId());
  298. }
  299. // 财务从表
  300. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  301. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  302. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  303. for (TFeeDo tFeeDo : tFeeDoList) {
  304. tFeeDo.setfPid(tFee.getfId());
  305. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  306. tFeeDo.setCreateTime(new Date());
  307. tFeeDoMapper.insertTFeeDo(tFeeDo);
  308. }
  309. }
  310. // 这里加个判断取系统参数来确定是否需要启用审批流
  311. String key = "";
  312. boolean isApprove = false;
  313. long actId = 0L;
  314. if ("DZ".equals(fBilltype)) {
  315. actId = 210L;
  316. key = "warehouse.contrast.ApprovalFlow";
  317. } else if ("SF".equals(fBilltype)) {
  318. actId = 220L;
  319. key = "warehouse.charge.ApprovalFlow";
  320. } else if ("FF".equals(fBilltype)) {
  321. actId = 230L;
  322. key = "warehouse.payment.ApprovalFlow";
  323. }
  324. SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique(key);
  325. if (StringUtils.isNull(sysConfig)) {
  326. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  327. return AjaxResult.error("系统参数异常,未找到开启审批流参数");
  328. }
  329. if ("0".equals(sysConfig.getConfigValue())) {
  330. isApprove = true;
  331. }
  332. if (isApprove) {
  333. AuditItems auditItems = new AuditItems();
  334. auditItems.setLevelId(0L);
  335. auditItems.setBillId(tFee.getfId());
  336. auditItems.setActId(actId);
  337. auditItems.setIffinalItem("F");
  338. auditItems.setBillNo(tFee.getfBillno()); // 业务编号
  339. auditItems.setRefno1(String.valueOf(tFee.getfCorpid())); // 货权方
  340. auditItems.setRefno2(tFee.getfBilltype());// 财务类型
  341. auditItems.setRefno3(tFee.gettMblno());// 提单号
  342. auditItems.setSendUserId(loginUser.getUser().getUserId());
  343. auditItems.setSendName(loginUser.getUsername());
  344. auditItems.setSendTime(new Date());
  345. auditItems.setAuditUserId(loginUser.getUser().getUserId());
  346. auditItems.setAuditItem(new Date());
  347. auditItems.setAuditOpTime(new Date());
  348. auditItems.setAuditMsg("提交");
  349. auditItems.setAuditStatus("O");
  350. AjaxResult approvalFlow = auditItemsService.createApprovalFlow(auditItems);
  351. Long code = Long.valueOf(String.valueOf(approvalFlow.get("code"))).longValue();
  352. if (code.equals(500L)) {
  353. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  354. }
  355. return approvalFlow;
  356. }else {
  357. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  358. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  359. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  360. for (TFeeDo tFeeDo : tFeeDoList) {
  361. // 跟新费用明细
  362. int m = updateBillsFees(tFee.getfId(),tFeeDo,fBilltype);
  363. if (m == 0) {
  364. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  365. return AjaxResult.error("更新费用明细失败");
  366. }
  367. }
  368. }
  369. AjaxResult ajaxResult = tfeeFollow(tFee.getfId(), 6L);
  370. Long code = Long.valueOf(String.valueOf(ajaxResult.get("code"))).longValue();
  371. return ajaxResult;
  372. }
  373. }
  374. /**
  375. * 根据财务主表id 更新对应明细表状态
  376. *
  377. * @param fPid 财务主表id
  378. * @return 结果
  379. */
  380. @Transactional
  381. public AjaxResult tfeeFollow(Long fPid, long fettle) {
  382. if (StringUtils.isNull(fPid)) {
  383. return AjaxResult.error("财务更新状态未找到主表信息,请与管理员联系");
  384. }
  385. TFee tFee = new TFee();
  386. tFee.setfId(fPid);
  387. tFee.setfBillstatus(String.valueOf(fettle));
  388. int tFeeUpdateResult = tFeeMapper.updateTFee(tFee);
  389. if (tFeeUpdateResult <= 0) {
  390. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  391. return AjaxResult.error("更新财务明细状态失败,请联系管理员");
  392. }
  393. try{
  394. int itemUpdateResult = tFeeDoMapper.tfeeDoFollowUpdate(fPid,fettle);
  395. } catch (Exception exception){
  396. return AjaxResult.error("更新财务明细状态失败,请联系管理员");
  397. }
  398. return AjaxResult.success();
  399. }
  400. @Transactional
  401. public AjaxResult billsfeesFollow(Long fPid) {
  402. if (StringUtils.isNull(fPid)) {
  403. return AjaxResult.error("费用明细更新状态未找到主表信息,请与管理员联系");
  404. }
  405. TFee tFee=tFeeMapper.selectTFeeById(fPid);
  406. // 查询从表数据
  407. TFeeDo tFeeDo = new TFeeDo();
  408. tFeeDo.setfPid(fPid);
  409. List<TFeeDo> tFeeDoList= tFeeDoMapper.selectTFeeDoList(tFeeDo);
  410. for (TFeeDo tFeeDo1 : tFeeDoList) {
  411. // 跟新费用明细
  412. int m = updateBillsFees(fPid,tFeeDo1,tFee.getfBilltype());
  413. if (m == 0) {
  414. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  415. return AjaxResult.error("更新费用明细失败");
  416. }
  417. }
  418. return AjaxResult.success();
  419. }
  420. @Override
  421. @Transactional
  422. public AjaxResult revoke(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  423. // 更新 主表、从表
  424. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  425. tFee.setUpdateBy(loginUser.getUser().getUserName());
  426. tFee.setUpdateTime(new Date());
  427. tFeeMapper.updateTFee(tFee);
  428. // 删除从表
  429. tFeeDoMapper.deleteByFPid(tFee.getfId());
  430. // 财务从表
  431. if (StringUtils.isNotNull(tfeeDo)) {
  432. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  433. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  434. for (TFeeDo tFeeDo : tFeeDoList) {
  435. tFeeDo.setfPid(tFee.getfId());
  436. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  437. tFeeDo.setCreateTime(new Date());
  438. tFeeDoMapper.insertTFeeDo(tFeeDo);
  439. // 跟新费用明细
  440. int m = updateBillsFees(tFee.getfId(),tFeeDo,fBilltype);
  441. if (m == 0) {
  442. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  443. return AjaxResult.error("更新费用明细失败");
  444. }
  445. }
  446. }
  447. return AjaxResult.success();
  448. }
  449. @Override
  450. public AjaxResult queryRemove(Long fId) {
  451. TFee tFee=tFeeMapper.selectTFeeById(fId);
  452. TFeeDo tFeeDo = new TFeeDo();
  453. tFeeDo.setfPid(tFee.getfId());
  454. List<TFeeDo> tFeeDoList= tFeeDoMapper.selectTFeeDoList(tFeeDo);
  455. if( StringUtils.isNull(tFee)){
  456. return AjaxResult.success("0");
  457. } else if(StringUtils.isNotNull(tFee) && StringUtils.isEmpty(tFeeDoList) ){
  458. return AjaxResult.success("1");
  459. } else {
  460. return AjaxResult.success("2");
  461. }
  462. }
  463. /**
  464. * 更新费用明细
  465. * @param fid
  466. * @param tFeeDo
  467. * @param billsType
  468. * @return
  469. */
  470. @Transactional
  471. public int updateBillsFees(Long fid,TFeeDo tFeeDo,String billsType){
  472. // 查询从表数据
  473. TFee tFee=tFeeMapper.selectTFeeById(fid);
  474. if(billsType.equals("SF") || billsType.equals("FF")){
  475. billsType="DC";
  476. }
  477. Map<String, Object> map = new HashMap<>();
  478. map.put("tFee", tFee);
  479. map.put("billType", billsType);
  480. map.put("tFeeDo", tFeeDo);
  481. return tWarehousebillsfeesMapper.updateTWarehousebillsfee(map);
  482. }
  483. }