TFeeServiceImpl.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. if(tWarehousebills.getfBilltype().equals("SJRK")){
  105. map1.put("fBilltype","入库");
  106. } else if(tWarehousebills.getfBilltype().equals("SJCK")){
  107. map1.put("fBilltype","出库");
  108. } else if(tWarehousebills.getfBilltype().equals("CKDB")){
  109. map1.put("fBilltype","调拨");
  110. } else if(tWarehousebills.getfBilltype().equals("HQZY")){
  111. map1.put("fBilltype","货权转移");
  112. }
  113. feeDoList.add(map1);
  114. }
  115. }
  116. List<TCorps> corpsList = new ArrayList<>();
  117. List<Long> corpsIdList = StringUtils.integerDeduplication(corpsId);
  118. for (Long corpId : corpsIdList) {
  119. TCorps corps = tCorpsMapper.selectTCorpsById(corpId);
  120. if (StringUtils.isNotNull(corps)) {
  121. corpsList.add(corps);
  122. }
  123. }
  124. List<TFees> feesList = new ArrayList<>();
  125. List<Long> longList = StringUtils.integerDeduplication(feesId);
  126. for (Long fees : longList) {
  127. TFees tFees = tFeesMapper.selectTFeesById(fees);
  128. if (StringUtils.isNotNull(tFees)) {
  129. feesList.add(tFees);
  130. }
  131. }
  132. map.put("tFee",tFee);
  133. map.put("corps",corpsList);
  134. map.put("feesList", feesList);
  135. map.put("feeDoList",feeDoList);
  136. return map;
  137. }
  138. /**
  139. * 查询财务数据主列表
  140. *
  141. * @param tFee 财务数据主
  142. * @return 财务数据主
  143. */
  144. @Override
  145. public List<TFee> selectTFeeList(TFee tFee) {
  146. return tFeeMapper.selectTFeeList(tFee);
  147. }
  148. @Override
  149. public List<Map<String, Object>> selectTFeeList1(TFee tFee) {
  150. return tFeeMapper.selectTFeeList1(tFee);
  151. }
  152. /**
  153. * 新增财务数据主
  154. *
  155. * @param tFee 财务数据主
  156. * @return 结果
  157. */
  158. @Override
  159. public int insertTFee(TFee tFee) {
  160. tFee.setCreateTime(DateUtils.getNowDate());
  161. return tFeeMapper.insertTFee(tFee);
  162. }
  163. /**
  164. * 新增对账 、收费、
  165. * @param tfee
  166. * @param tfeeDo
  167. * @param loginUser
  168. * @param fBilltype
  169. * @return
  170. */
  171. @Override
  172. public AjaxResult insertTFeeTFeeDo(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  173. Long fPid = null;
  174. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  175. if (StringUtils.isNull(tFee.getfId())) {
  176. // 如果是新数据
  177. tFee.setCreateBy(loginUser.getUser().getUserName());
  178. tFee.setfBilltype(fBilltype);
  179. // 业务编码
  180. Date time = new Date();
  181. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  182. tFee.setfBillno(billNo);
  183. tFeeMapper.insertTFee(tFee);
  184. fPid = tFee.getfId();
  185. } else {
  186. fPid = tFee.getfId();
  187. tFee.setUpdateBy(loginUser.getUser().getUserName());
  188. tFee.setUpdateTime(new Date());
  189. tFeeMapper.updateTFee(tFee);
  190. // 删除从表
  191. tFeeDoMapper.deleteByFPid(fPid);
  192. }
  193. // 财务从表
  194. if (StringUtils.isNotNull(tfeeDo)) {
  195. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  196. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  197. for (TFeeDo tFeeDo : tFeeDoList) {
  198. tFeeDo.setfPid(fPid);
  199. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  200. tFeeDo.setCreateTime(new Date());
  201. tFeeDoMapper.insertTFeeDo(tFeeDo);
  202. }
  203. }
  204. return AjaxResult.success();
  205. }
  206. /**
  207. * 修改财务数据主
  208. *
  209. * @param tFee 财务数据主
  210. * @return 结果
  211. */
  212. @Override
  213. public int updateTFee(TFee tFee) {
  214. tFee.setUpdateTime(DateUtils.getNowDate());
  215. return tFeeMapper.updateTFee(tFee);
  216. }
  217. /**
  218. * 批量删除财务数据主
  219. *
  220. * @param fIds 需要删除的财务数据主ID
  221. * @return 结果
  222. */
  223. @Override
  224. public int deleteTFeeByIds(Long[] fIds) {
  225. // 取出业务编号、 放入 billno_del
  226. for (Long id : fIds) {
  227. // 1、查询主表信息
  228. TFee tFee = tFeeMapper.selectTFeeById(id);
  229. // 2、业务编号、客存编号 放入 billno_del
  230. BillnoDel billnoDel = new BillnoDel();
  231. billnoDel.setBillType(tFee.getfBilltype());
  232. billnoDel.setBillNo(tFee.getfBillno());
  233. billnoDelMapper.insertBillnoDel(billnoDel);
  234. }
  235. return tFeeMapper.deleteTFeeByIds(fIds);
  236. }
  237. /**
  238. * 删除财务数据主信息
  239. *
  240. * @param fId 财务数据主ID
  241. * @return 结果
  242. */
  243. @Override
  244. public int deleteTFeeById(Long fId) {
  245. return tFeeMapper.deleteTFeeById(fId);
  246. }
  247. @Override
  248. public List<Map<String, Object>> warehouseBillsFeesList(TWareHouseFees tWareHouseFees) {
  249. List<Map<String, Object>> maps =new ArrayList<Map<String, Object>>();
  250. Map<String, Object> map = new HashMap<>();
  251. map.put("tWareHouseFees", tWareHouseFees);
  252. List<Map<String, Object>> mapList = tFeeMapper.warehouseBillsFeesList(map);
  253. if (mapList != null && mapList.size() > 0) {
  254. String fAmtdr = null; // 金额
  255. String fAmt = null; // 结算
  256. for (Map<String, Object> m : mapList) {
  257. for (String k : m.keySet()) {
  258. if (k.equals("fAmtdr")) {
  259. fAmtdr = m.get(k).toString();
  260. }
  261. if (k.equals("fAmt")) {
  262. fAmt = m.get(k).toString();
  263. }
  264. }
  265. BigDecimal result = calculation1(fAmtdr, fAmt);
  266. m.put("fAmtdr",result);
  267. m.put("fAmt",result);
  268. maps.add(m);
  269. }
  270. }
  271. return maps;
  272. }
  273. public static BigDecimal calculation1(String fTotalgross, String fGrossweightblc) {
  274. BigDecimal num1 = new BigDecimal(fTotalgross);
  275. BigDecimal num2 = new BigDecimal(fGrossweightblc);
  276. BigDecimal result = num1.subtract(num2);
  277. return result.setScale(2, BigDecimal.ROUND_HALF_UP);
  278. }
  279. @Override
  280. @Transactional
  281. public AjaxResult confirm(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  282. // 更新 主表、从表
  283. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  284. tFee.setUpdateBy(loginUser.getUser().getUserName());
  285. tFee.setUpdateTime(new Date());
  286. tFeeMapper.updateTFee(tFee);
  287. // 删除从表
  288. tFeeDoMapper.deleteByFPid(tFee.getfId());
  289. // 财务从表
  290. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  291. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  292. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  293. for (TFeeDo tFeeDo : tFeeDoList) {
  294. tFeeDo.setfPid(tFee.getfId());
  295. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  296. tFeeDo.setCreateTime(new Date());
  297. tFeeDoMapper.insertTFeeDo(tFeeDo);
  298. // 跟新费用明细
  299. int m = updateBillsFees(tFee.getfId(),tFeeDo,fBilltype);
  300. if (m == 0) {
  301. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  302. return AjaxResult.error("更新费用明细失败");
  303. }
  304. }
  305. }
  306. // 这里加个判断取系统参数来确定是否需要启用审批流
  307. String key = "";
  308. boolean isApprove = false;
  309. long actId = 0L;
  310. if ("DZ".equals(fBilltype)) {
  311. actId = 210L;
  312. key = "warehouse.contrast.ApprovalFlow";
  313. } else if ("SF".equals(fBilltype)) {
  314. actId = 220L;
  315. key = "warehouse.charge.ApprovalFlow";
  316. } else if ("FF".equals(fBilltype)) {
  317. actId = 230L;
  318. key = "warehouse.payment.ApprovalFlow";
  319. }
  320. SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique(key);
  321. if (StringUtils.isNull(sysConfig)) {
  322. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  323. return AjaxResult.error("系统参数异常,未找到开启审批流参数");
  324. }
  325. if ("0".equals(sysConfig.getConfigValue())) {
  326. isApprove = true;
  327. }
  328. if (isApprove) {
  329. AuditItems auditItems = new AuditItems();
  330. auditItems.setLevelId(0L);
  331. auditItems.setBillId(tFee.getfId());
  332. auditItems.setActId(actId);
  333. auditItems.setIffinalItem("F");
  334. auditItems.setBillNo(tFee.getfBillno()); // 业务编号
  335. auditItems.setRefno1(tFee.getfBilltype()); // 财务类型
  336. auditItems.setSendUserId(loginUser.getUser().getUserId());
  337. auditItems.setSendName(loginUser.getUsername());
  338. auditItems.setSendTime(new Date());
  339. auditItems.setAuditUserId(loginUser.getUser().getUserId());
  340. auditItems.setAuditItem(new Date());
  341. auditItems.setAuditMsg("提交");
  342. auditItems.setAuditStatus("O");
  343. AjaxResult approvalFlow = auditItemsService.createApprovalFlow(auditItems);
  344. Long code = Long.valueOf(String.valueOf(approvalFlow.get("code"))).longValue();
  345. if (code.equals(500L)) {
  346. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  347. }
  348. return approvalFlow;
  349. }
  350. return null;
  351. }
  352. @Override
  353. @Transactional
  354. public AjaxResult revoke(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  355. // 更新 主表、从表
  356. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  357. tFee.setUpdateBy(loginUser.getUser().getUserName());
  358. tFee.setUpdateTime(new Date());
  359. tFeeMapper.updateTFee(tFee);
  360. // 删除从表
  361. tFeeDoMapper.deleteByFPid(tFee.getfId());
  362. // 财务从表
  363. if (StringUtils.isNotNull(tfeeDo)) {
  364. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  365. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  366. for (TFeeDo tFeeDo : tFeeDoList) {
  367. tFeeDo.setfPid(tFee.getfId());
  368. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  369. tFeeDo.setCreateTime(new Date());
  370. tFeeDoMapper.insertTFeeDo(tFeeDo);
  371. // 跟新费用明细
  372. int m = updateBillsFees(tFee.getfId(),tFeeDo,fBilltype);
  373. if (m == 0) {
  374. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  375. return AjaxResult.error("更新费用明细失败");
  376. }
  377. }
  378. }
  379. return AjaxResult.success();
  380. }
  381. /**
  382. * 更新费用明细
  383. * @param fid
  384. * @param tFeeDo
  385. * @param billsType
  386. * @return
  387. */
  388. @Transactional
  389. public int updateBillsFees(Long fid,TFeeDo tFeeDo,String billsType){
  390. // 查询从表数据
  391. TFee tFee=tFeeMapper.selectTFeeById(fid);
  392. if(billsType.equals("SF") || billsType.equals("FF")){
  393. billsType="DC";
  394. }
  395. Map<String, Object> map = new HashMap<>();
  396. map.put("tFee", tFee);
  397. map.put("billType", billsType);
  398. map.put("tFeeDo", tFeeDo);
  399. return tWarehousebillsfeesMapper.updateTWarehousebillsfee(map);
  400. }
  401. }