TFeeServiceImpl.java 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. package com.ruoyi.finance.service.impl;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.ruoyi.basicData.domain.TCorps;
  5. import com.ruoyi.basicData.domain.TFees;
  6. import com.ruoyi.basicData.mapper.TCorpsMapper;
  7. import com.ruoyi.basicData.mapper.TFeesMapper;
  8. import com.ruoyi.common.core.domain.AjaxResult;
  9. import com.ruoyi.common.core.domain.model.LoginUser;
  10. import com.ruoyi.common.utils.DateUtils;
  11. import com.ruoyi.common.utils.StringUtils;
  12. import com.ruoyi.finance.domain.TFee;
  13. import com.ruoyi.finance.domain.TFeeDo;
  14. import com.ruoyi.finance.domain.TWareHouseFees;
  15. import com.ruoyi.finance.mapper.TFeeDoMapper;
  16. import com.ruoyi.finance.mapper.TFeeMapper;
  17. import com.ruoyi.finance.service.ITFeeService;
  18. import com.ruoyi.warehouseBusiness.domain.*;
  19. import com.ruoyi.warehouseBusiness.mapper.BillnoDelMapper;
  20. import com.ruoyi.warehouseBusiness.mapper.TWarehouseBillsMapper;
  21. import com.ruoyi.warehouseBusiness.service.impl.BillnoSerialServiceImpl;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.stereotype.Service;
  24. import java.util.*;
  25. /**
  26. * 财务数据主Service业务层处理
  27. *
  28. * @author ruoyi
  29. * @date 2021-01-18
  30. */
  31. @Service
  32. public class TFeeServiceImpl implements ITFeeService {
  33. @Autowired
  34. private TFeeMapper tFeeMapper;
  35. @Autowired
  36. private TFeeDoMapper tFeeDoMapper;
  37. @Autowired
  38. private BillnoSerialServiceImpl billnoSerialServiceImpl;
  39. @Autowired
  40. private BillnoDelMapper billnoDelMapper;
  41. @Autowired
  42. private TCorpsMapper tCorpsMapper;
  43. @Autowired
  44. private TFeesMapper tFeesMapper;
  45. @Autowired
  46. private TWarehouseBillsMapper tWarehouseBillsMapper;
  47. /**
  48. * 查询财务数据主
  49. *
  50. * @param fId 财务数据主ID
  51. * @return 财务数据主
  52. */
  53. @Override
  54. public Map<String, Object> selectTFeeById(Long fId) {
  55. Map<String, Object> map = new HashMap<>();
  56. // 客户表
  57. List<Long> corpsId = new ArrayList<>();
  58. // 费用
  59. List<Long> feesId = new ArrayList<>();
  60. TFee tFee=tFeeMapper.selectTFeeById(fId);
  61. if (StringUtils.isNotNull(tFee.getfCorpid())) {
  62. corpsId.add(tFee.getfCorpid());
  63. }
  64. corpsId.add(tFee.getfCorpid());
  65. // 查询从表数据
  66. TFeeDo tFeeDo = new TFeeDo();
  67. tFeeDo.setfPid(fId);
  68. List<TFeeDo> tFeeDoList= tFeeDoMapper.selectTFeeDoList(tFeeDo);
  69. List<Map<String, Object>> feeDoList=new ArrayList<>();
  70. if (StringUtils.isNotEmpty(tFeeDoList)) {
  71. for (TFeeDo fees : tFeeDoList) {
  72. Map<String, Object> map1 = new HashMap<>();
  73. feesId.add(fees.getfFeeid());
  74. // 查询主表
  75. TWarehouseBills tWarehousebills = tWarehouseBillsMapper.selectTWarehousebillsById(fees.getfSrcpid());
  76. // 费用名称
  77. TFees tFees= tFeesMapper.selectTFeesById(fees.getfFeeid());
  78. map1.put("fId",fees.getfId());
  79. map1.put("fSrcid",fees.getfSrcid());
  80. map1.put("fSrcpid",fees.getfSrcpid());
  81. map1.put("fMblno",tWarehousebills.getfMblno());
  82. map1.put("fBscorpno",tWarehousebills.getfBscorpno());
  83. map1.put("fProductName",tWarehousebills.getfProductName());
  84. map1.put("fBsdate",tWarehousebills.getfBsdate());
  85. map1.put("fFeeid",fees.getfFeeid());
  86. map1.put("fFeeName",tFees.getfName());
  87. map1.put("fSrcdc",fees.getfSrcdc());
  88. map1.put("fAmt",fees.getfAmt());
  89. if(tWarehousebills.getfBilltype().equals("SJRK")){
  90. map1.put("fBilltype","入库");
  91. } else if(tWarehousebills.getfBilltype().equals("SJCK")){
  92. map1.put("fBilltype","出库");
  93. } else if(tWarehousebills.getfBilltype().equals("CKDB")){
  94. map1.put("fBilltype","调拨");
  95. } else if(tWarehousebills.getfBilltype().equals("HQZY")){
  96. map1.put("fBilltype","货权转移");
  97. }
  98. feeDoList.add(map1);
  99. }
  100. }
  101. List<TCorps> corpsList = new ArrayList<>();
  102. List<Long> corpsIdList = StringUtils.integerDeduplication(corpsId);
  103. for (Long corpId : corpsIdList) {
  104. TCorps corps = tCorpsMapper.selectTCorpsById(corpId);
  105. if (StringUtils.isNotNull(corps)) {
  106. corpsList.add(corps);
  107. }
  108. }
  109. List<TFees> feesList = new ArrayList<>();
  110. List<Long> longList = StringUtils.integerDeduplication(feesId);
  111. for (Long fees : longList) {
  112. TFees tFees = tFeesMapper.selectTFeesById(fees);
  113. if (StringUtils.isNotNull(tFees)) {
  114. feesList.add(tFees);
  115. }
  116. }
  117. map.put("tFee",tFee);
  118. map.put("corps",corpsList);
  119. map.put("feesList", feesList);
  120. map.put("feeDoList",feeDoList);
  121. return map;
  122. }
  123. /**
  124. * 查询财务数据主列表
  125. *
  126. * @param tFee 财务数据主
  127. * @return 财务数据主
  128. */
  129. @Override
  130. public List<TFee> selectTFeeList(TFee tFee) {
  131. return tFeeMapper.selectTFeeList(tFee);
  132. }
  133. /**
  134. * 新增财务数据主
  135. *
  136. * @param tFee 财务数据主
  137. * @return 结果
  138. */
  139. @Override
  140. public int insertTFee(TFee tFee) {
  141. tFee.setCreateTime(DateUtils.getNowDate());
  142. return tFeeMapper.insertTFee(tFee);
  143. }
  144. /**
  145. * 新增对账 、收费、
  146. * @param tfee
  147. * @param tfeeDo
  148. * @param loginUser
  149. * @param fBilltype
  150. * @return
  151. */
  152. @Override
  153. public AjaxResult insertTFeeTFeeDo(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  154. Long fPid = null;
  155. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  156. if (StringUtils.isNull(tFee.getfId())) {
  157. // 如果是新数据
  158. tFee.setCreateBy(loginUser.getUser().getUserName());
  159. tFee.setfBilltype(fBilltype);
  160. // 业务编码
  161. Date time = new Date();
  162. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  163. tFee.setfBillno(billNo);
  164. tFeeMapper.insertTFee(tFee);
  165. fPid = tFee.getfId();
  166. } else {
  167. fPid = tFee.getfId();
  168. tFee.setUpdateBy(loginUser.getUser().getUserName());
  169. tFee.setUpdateTime(new Date());
  170. tFeeMapper.updateTFee(tFee);
  171. // 删除从表
  172. tFeeDoMapper.deleteByFPid(fPid);
  173. }
  174. // 财务从表
  175. if (StringUtils.isNotNull(tfeeDo)) {
  176. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  177. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  178. for (TFeeDo tFeeDo : tFeeDoList) {
  179. tFeeDo.setfPid(fPid);
  180. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  181. tFeeDo.setCreateTime(new Date());
  182. tFeeDoMapper.insertTFeeDo(tFeeDo);
  183. }
  184. }
  185. return AjaxResult.success();
  186. }
  187. /**
  188. * 修改财务数据主
  189. *
  190. * @param tFee 财务数据主
  191. * @return 结果
  192. */
  193. @Override
  194. public int updateTFee(TFee tFee) {
  195. tFee.setUpdateTime(DateUtils.getNowDate());
  196. return tFeeMapper.updateTFee(tFee);
  197. }
  198. /**
  199. * 批量删除财务数据主
  200. *
  201. * @param fIds 需要删除的财务数据主ID
  202. * @return 结果
  203. */
  204. @Override
  205. public int deleteTFeeByIds(Long[] fIds) {
  206. // 取出业务编号、 放入 billno_del
  207. for (Long id : fIds) {
  208. // 1、查询主表信息
  209. TFee tFee = tFeeMapper.selectTFeeById(id);
  210. // 2、业务编号、客存编号 放入 billno_del
  211. BillnoDel billnoDel = new BillnoDel();
  212. billnoDel.setBillType(tFee.getfBilltype());
  213. billnoDel.setBillNo(tFee.getfBillno());
  214. billnoDelMapper.insertBillnoDel(billnoDel);
  215. }
  216. return tFeeMapper.deleteTFeeByIds(fIds);
  217. }
  218. /**
  219. * 删除财务数据主信息
  220. *
  221. * @param fId 财务数据主ID
  222. * @return 结果
  223. */
  224. @Override
  225. public int deleteTFeeById(Long fId) {
  226. return tFeeMapper.deleteTFeeById(fId);
  227. }
  228. @Override
  229. public List<Map<String, Object>> warehouseBillsFeesList(TWareHouseFees tWareHouseFees) {
  230. Map<String, Object> map = new HashMap<>();
  231. map.put("tWareHouseFees", tWareHouseFees);
  232. return tFeeMapper.warehouseBillsFeesList(map);
  233. }
  234. }