TFeeServiceImpl.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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.mapper.TWarehousebillsfeesMapper;
  22. import com.ruoyi.warehouseBusiness.service.impl.BillnoSerialServiceImpl;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.stereotype.Service;
  25. import java.math.BigDecimal;
  26. import java.util.*;
  27. /**
  28. * 财务数据主Service业务层处理
  29. *
  30. * @author ruoyi
  31. * @date 2021-01-18
  32. */
  33. @Service
  34. public class TFeeServiceImpl implements ITFeeService {
  35. @Autowired
  36. private TFeeMapper tFeeMapper;
  37. @Autowired
  38. private TFeeDoMapper tFeeDoMapper;
  39. @Autowired
  40. private BillnoSerialServiceImpl billnoSerialServiceImpl;
  41. @Autowired
  42. private BillnoDelMapper billnoDelMapper;
  43. @Autowired
  44. private TCorpsMapper tCorpsMapper;
  45. @Autowired
  46. private TFeesMapper tFeesMapper;
  47. @Autowired
  48. private TWarehouseBillsMapper tWarehouseBillsMapper;
  49. @Autowired
  50. private TWarehousebillsfeesMapper tWarehousebillsfeesMapper;
  51. /**
  52. * 查询财务数据主
  53. *
  54. * @param fId 财务数据主ID
  55. * @return 财务数据主
  56. */
  57. @Override
  58. public Map<String, Object> selectTFeeById(Long fId) {
  59. Map<String, Object> map = new HashMap<>();
  60. // 客户表
  61. List<Long> corpsId = new ArrayList<>();
  62. // 费用
  63. List<Long> feesId = new ArrayList<>();
  64. TFee tFee=tFeeMapper.selectTFeeById(fId);
  65. if (StringUtils.isNotNull(tFee.getfCorpid())) {
  66. corpsId.add(tFee.getfCorpid());
  67. }
  68. corpsId.add(tFee.getfCorpid());
  69. // 查询从表数据
  70. TFeeDo tFeeDo = new TFeeDo();
  71. tFeeDo.setfPid(fId);
  72. List<TFeeDo> tFeeDoList= tFeeDoMapper.selectTFeeDoList(tFeeDo);
  73. List<Map<String, Object>> feeDoList=new ArrayList<>();
  74. if (StringUtils.isNotEmpty(tFeeDoList)) {
  75. for (TFeeDo fees : tFeeDoList) {
  76. Map<String, Object> map1 = new HashMap<>();
  77. feesId.add(fees.getfFeeid());
  78. // 查询主表
  79. TWarehouseBills tWarehousebills = tWarehouseBillsMapper.selectTWarehousebillsById(fees.getfSrcpid());
  80. // 费用名称
  81. TFees tFees= tFeesMapper.selectTFeesById(fees.getfFeeid());
  82. map1.put("fId",fees.getfId());
  83. map1.put("fSrcid",fees.getfSrcid());
  84. map1.put("fSrcpid",fees.getfSrcpid());
  85. map1.put("fMblno",tWarehousebills.getfMblno());
  86. map1.put("fBscorpno",tWarehousebills.getfBscorpno());
  87. map1.put("fProductName",tWarehousebills.getfProductName());
  88. map1.put("fBsdate",tWarehousebills.getfBsdate());
  89. map1.put("fFeeid",fees.getfFeeid());
  90. map1.put("fFeeName",tFees.getfName());
  91. map1.put("fSrcdc",fees.getfSrcdc());
  92. map1.put("fAmt",fees.getfAmt());
  93. if(tWarehousebills.getfBilltype().equals("SJRK")){
  94. map1.put("fBilltype","入库");
  95. } else if(tWarehousebills.getfBilltype().equals("SJCK")){
  96. map1.put("fBilltype","出库");
  97. } else if(tWarehousebills.getfBilltype().equals("CKDB")){
  98. map1.put("fBilltype","调拨");
  99. } else if(tWarehousebills.getfBilltype().equals("HQZY")){
  100. map1.put("fBilltype","货权转移");
  101. }
  102. feeDoList.add(map1);
  103. }
  104. }
  105. List<TCorps> corpsList = new ArrayList<>();
  106. List<Long> corpsIdList = StringUtils.integerDeduplication(corpsId);
  107. for (Long corpId : corpsIdList) {
  108. TCorps corps = tCorpsMapper.selectTCorpsById(corpId);
  109. if (StringUtils.isNotNull(corps)) {
  110. corpsList.add(corps);
  111. }
  112. }
  113. List<TFees> feesList = new ArrayList<>();
  114. List<Long> longList = StringUtils.integerDeduplication(feesId);
  115. for (Long fees : longList) {
  116. TFees tFees = tFeesMapper.selectTFeesById(fees);
  117. if (StringUtils.isNotNull(tFees)) {
  118. feesList.add(tFees);
  119. }
  120. }
  121. map.put("tFee",tFee);
  122. map.put("corps",corpsList);
  123. map.put("feesList", feesList);
  124. map.put("feeDoList",feeDoList);
  125. return map;
  126. }
  127. /**
  128. * 查询财务数据主列表
  129. *
  130. * @param tFee 财务数据主
  131. * @return 财务数据主
  132. */
  133. @Override
  134. public List<TFee> selectTFeeList(TFee tFee) {
  135. return tFeeMapper.selectTFeeList(tFee);
  136. }
  137. @Override
  138. public List<Map<String, Object>> selectTFeeList1(TFee tFee) {
  139. return tFeeMapper.selectTFeeList1(tFee);
  140. }
  141. /**
  142. * 新增财务数据主
  143. *
  144. * @param tFee 财务数据主
  145. * @return 结果
  146. */
  147. @Override
  148. public int insertTFee(TFee tFee) {
  149. tFee.setCreateTime(DateUtils.getNowDate());
  150. return tFeeMapper.insertTFee(tFee);
  151. }
  152. /**
  153. * 新增对账 、收费、
  154. * @param tfee
  155. * @param tfeeDo
  156. * @param loginUser
  157. * @param fBilltype
  158. * @return
  159. */
  160. @Override
  161. public AjaxResult insertTFeeTFeeDo(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  162. Long fPid = null;
  163. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  164. if (StringUtils.isNull(tFee.getfId())) {
  165. // 如果是新数据
  166. tFee.setCreateBy(loginUser.getUser().getUserName());
  167. tFee.setfBilltype(fBilltype);
  168. // 业务编码
  169. Date time = new Date();
  170. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  171. tFee.setfBillno(billNo);
  172. tFeeMapper.insertTFee(tFee);
  173. fPid = tFee.getfId();
  174. } else {
  175. fPid = tFee.getfId();
  176. tFee.setUpdateBy(loginUser.getUser().getUserName());
  177. tFee.setUpdateTime(new Date());
  178. tFeeMapper.updateTFee(tFee);
  179. // 删除从表
  180. tFeeDoMapper.deleteByFPid(fPid);
  181. }
  182. // 财务从表
  183. if (StringUtils.isNotNull(tfeeDo)) {
  184. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  185. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  186. for (TFeeDo tFeeDo : tFeeDoList) {
  187. tFeeDo.setfPid(fPid);
  188. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  189. tFeeDo.setCreateTime(new Date());
  190. tFeeDoMapper.insertTFeeDo(tFeeDo);
  191. }
  192. }
  193. return AjaxResult.success();
  194. }
  195. /**
  196. * 修改财务数据主
  197. *
  198. * @param tFee 财务数据主
  199. * @return 结果
  200. */
  201. @Override
  202. public int updateTFee(TFee tFee) {
  203. tFee.setUpdateTime(DateUtils.getNowDate());
  204. return tFeeMapper.updateTFee(tFee);
  205. }
  206. /**
  207. * 批量删除财务数据主
  208. *
  209. * @param fIds 需要删除的财务数据主ID
  210. * @return 结果
  211. */
  212. @Override
  213. public int deleteTFeeByIds(Long[] fIds) {
  214. // 取出业务编号、 放入 billno_del
  215. for (Long id : fIds) {
  216. // 1、查询主表信息
  217. TFee tFee = tFeeMapper.selectTFeeById(id);
  218. // 2、业务编号、客存编号 放入 billno_del
  219. BillnoDel billnoDel = new BillnoDel();
  220. billnoDel.setBillType(tFee.getfBilltype());
  221. billnoDel.setBillNo(tFee.getfBillno());
  222. billnoDelMapper.insertBillnoDel(billnoDel);
  223. }
  224. return tFeeMapper.deleteTFeeByIds(fIds);
  225. }
  226. /**
  227. * 删除财务数据主信息
  228. *
  229. * @param fId 财务数据主ID
  230. * @return 结果
  231. */
  232. @Override
  233. public int deleteTFeeById(Long fId) {
  234. return tFeeMapper.deleteTFeeById(fId);
  235. }
  236. @Override
  237. public List<Map<String, Object>> warehouseBillsFeesList(TWareHouseFees tWareHouseFees) {
  238. List<Map<String, Object>> maps =new ArrayList<Map<String, Object>>();
  239. Map<String, Object> map = new HashMap<>();
  240. map.put("tWareHouseFees", tWareHouseFees);
  241. List<Map<String, Object>> mapList = tFeeMapper.warehouseBillsFeesList(map);
  242. if (mapList != null && mapList.size() > 0) {
  243. String fAmtdr = null; // 金额
  244. String fAmt = null; // 结算
  245. for (Map<String, Object> m : mapList) {
  246. for (String k : m.keySet()) {
  247. if (k.equals("fAmtdr")) {
  248. fAmtdr = m.get(k).toString();
  249. }
  250. if (k.equals("fAmt")) {
  251. fAmt = m.get(k).toString();
  252. }
  253. }
  254. BigDecimal result = calculation1(fAmtdr, fAmt);
  255. m.put("fAmtdr",result);
  256. m.put("fAmt",result);
  257. maps.add(m);
  258. }
  259. }
  260. return maps;
  261. }
  262. public static BigDecimal calculation1(String fTotalgross, String fGrossweightblc) {
  263. BigDecimal num1 = new BigDecimal(fTotalgross);
  264. BigDecimal num2 = new BigDecimal(fGrossweightblc);
  265. BigDecimal result = num1.subtract(num2);
  266. return result.setScale(2, BigDecimal.ROUND_HALF_UP);
  267. }
  268. @Override
  269. public AjaxResult confirm(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  270. // 更新 主表、从表
  271. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  272. tFee.setUpdateBy(loginUser.getUser().getUserName());
  273. tFee.setUpdateTime(new Date());
  274. tFeeMapper.updateTFee(tFee);
  275. // 删除从表
  276. tFeeDoMapper.deleteByFPid(tFee.getfId());
  277. // 财务从表
  278. if (StringUtils.isNotNull(tfeeDo)) {
  279. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  280. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  281. for (TFeeDo tFeeDo : tFeeDoList) {
  282. tFeeDo.setfPid(tFee.getfId());
  283. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  284. tFeeDo.setCreateTime(new Date());
  285. tFeeDoMapper.insertTFeeDo(tFeeDo);
  286. }
  287. }
  288. // 更新费用明细
  289. updateBillsFees(tFee.getfId(),fBilltype);
  290. // 审批流程
  291. return null;
  292. }
  293. public void updateBillsFees(Long fid,String billsType){
  294. // 查询从表数据
  295. TFee tFee=tFeeMapper.selectTFeeById(fid);
  296. TFeeDo tFeeDo = new TFeeDo();
  297. tFeeDo.setfPid(fid);
  298. List<TFeeDo> tFeeDoList= tFeeDoMapper.selectTFeeDoList(tFeeDo);
  299. // 更新费用明细
  300. for (TFeeDo tFeeDo1 : tFeeDoList ){
  301. // 查询仓库费用明细表数据
  302. TWarehousebillsfees tWarehousebillsfees=new TWarehousebillsfees();
  303. tWarehousebillsfees.setfId(tFeeDo1.getfSrcid());
  304. if(billsType.equals("DZ")){
  305. tWarehousebillsfees.setfStatementNo(tFee.getfBillno());
  306. tWarehousebillsfees.setfAccamountDate(tFee.getfAccbilldate());
  307. } else {
  308. tWarehousebillsfees.setfStlamountNo(tFee.getfBillno());
  309. // tWarehousebillsfees.setfStlamount();
  310. tWarehousebillsfees.setfStlamountDate(tFee.getfAccbilldate());
  311. }
  312. }
  313. }
  314. }