TFeeServiceImpl.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  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.entity.SysDictData;
  12. import com.ruoyi.common.core.domain.model.LoginUser;
  13. import com.ruoyi.common.utils.DateUtils;
  14. import com.ruoyi.common.utils.StringUtils;
  15. import com.ruoyi.finance.domain.TFee;
  16. import com.ruoyi.finance.domain.TFeeDo;
  17. import com.ruoyi.finance.domain.TWareHouseFees;
  18. import com.ruoyi.finance.excel.Contrast;
  19. import com.ruoyi.finance.mapper.TFeeDoMapper;
  20. import com.ruoyi.finance.mapper.TFeeMapper;
  21. import com.ruoyi.finance.service.ITFeeService;
  22. import com.ruoyi.reportManagement.excel.Payable;
  23. import com.ruoyi.reportManagement.excel.Profit;
  24. import com.ruoyi.reportManagement.excel.Receivable;
  25. import com.ruoyi.system.domain.SysConfig;
  26. import com.ruoyi.system.mapper.SysConfigMapper;
  27. import com.ruoyi.system.service.ISysDictDataService;
  28. import com.ruoyi.warehouseBusiness.domain.BillnoDel;
  29. import com.ruoyi.warehouseBusiness.domain.TWareHouseExcelItem;
  30. import com.ruoyi.warehouseBusiness.domain.TWarehouseBills;
  31. import com.ruoyi.warehouseBusiness.domain.TWarehousebillsfees;
  32. import com.ruoyi.warehouseBusiness.excel.ListMapToBeanUtils;
  33. import com.ruoyi.warehouseBusiness.mapper.BillnoDelMapper;
  34. import com.ruoyi.warehouseBusiness.mapper.TWarehouseBillsMapper;
  35. import com.ruoyi.warehouseBusiness.mapper.TWarehousebillsfeesMapper;
  36. import com.ruoyi.warehouseBusiness.service.impl.BillnoSerialServiceImpl;
  37. import org.springframework.beans.factory.annotation.Autowired;
  38. import org.springframework.stereotype.Service;
  39. import org.springframework.transaction.annotation.Transactional;
  40. import org.springframework.transaction.interceptor.TransactionAspectSupport;
  41. import java.math.BigDecimal;
  42. import java.util.*;
  43. /**
  44. * 财务数据主Service业务层处理
  45. *
  46. * @author ruoyi
  47. * @date 2021-01-18
  48. */
  49. @Service
  50. public class TFeeServiceImpl implements ITFeeService {
  51. @Autowired
  52. private TFeeMapper tFeeMapper;
  53. @Autowired
  54. private TFeeDoMapper tFeeDoMapper;
  55. @Autowired
  56. private BillnoSerialServiceImpl billnoSerialServiceImpl;
  57. @Autowired
  58. private BillnoDelMapper billnoDelMapper;
  59. @Autowired
  60. private TCorpsMapper tCorpsMapper;
  61. @Autowired
  62. private TFeesMapper tFeesMapper;
  63. @Autowired
  64. private TWarehouseBillsMapper tWarehouseBillsMapper;
  65. @Autowired
  66. private TWarehousebillsfeesMapper tWarehousebillsfeesMapper;
  67. @Autowired
  68. private SysConfigMapper sysConfigMapper;
  69. @Autowired
  70. private AuditItemsServiceImpl auditItemsService;
  71. @Autowired
  72. private ISysDictDataService iSysDictDataService;
  73. /**
  74. * 查询财务数据主
  75. *
  76. * @param fId 财务数据主ID
  77. * @return 财务数据主
  78. */
  79. @Override
  80. public Map<String, Object> selectTFeeById(Long fId) {
  81. Map<String, Object> map = new HashMap<>();
  82. // 客户表
  83. List<Long> corpsId = new ArrayList<>();
  84. // 费用
  85. List<Long> feesId = new ArrayList<>();
  86. TFee tFee=tFeeMapper.selectTFeeById(fId);
  87. if (StringUtils.isNotNull(tFee.getfCorpid())) {
  88. corpsId.add(tFee.getfCorpid());
  89. }
  90. corpsId.add(tFee.getfCorpid());
  91. // 查询从表数据
  92. TFeeDo tFeeDo = new TFeeDo();
  93. tFeeDo.setfPid(fId);
  94. List<TFeeDo> tFeeDoList= tFeeDoMapper.selectTFeeDoList(tFeeDo);
  95. List<Map<String, Object>> feeDoList=new ArrayList<>();
  96. if (StringUtils.isNotEmpty(tFeeDoList)) {
  97. for (TFeeDo fees : tFeeDoList) {
  98. Map<String, Object> map1 = new HashMap<>();
  99. feesId.add(fees.getfFeeid());
  100. // 查询主表
  101. TWarehouseBills tWarehousebills = tWarehouseBillsMapper.selectTWarehousebillsById(fees.getfSrcpid());
  102. // 费用名称
  103. TFees tFees= tFeesMapper.selectTFeesById(fees.getfFeeid());
  104. // 费用表数据
  105. TWarehousebillsfees tWarehousebillsfees = tWarehousebillsfeesMapper.selectTWarehousebillsfeesById(fees.getfSrcid());
  106. // 字典宝
  107. SysDictData sysDictData =new SysDictData();
  108. sysDictData.setDictType("data_unitfees");
  109. sysDictData.setDictValue(String.valueOf(tWarehousebillsfees.getfFeeunitid()));
  110. sysDictData.setStatus("0");
  111. List<SysDictData> sysDictDataList = iSysDictDataService.selectDictDataList(sysDictData);
  112. List<SysDictData> sysDictDataListIn = new ArrayList<>();
  113. SysDictData sysDictDataIn =new SysDictData();
  114. if(tWarehousebillsfees.getfBilltype().equals("SJRK")){
  115. sysDictData.setDictType("st_in_type");
  116. sysDictData.setDictValue(String.valueOf(tWarehousebillsfees.getfFeeunitid()));
  117. sysDictData.setStatus("0");
  118. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  119. } else if (tWarehousebillsfees.getfBilltype().equals("SJCK")){
  120. sysDictData.setDictType("st_out_type");
  121. sysDictData.setDictValue(String.valueOf(tWarehousebillsfees.getfFeeunitid()));
  122. sysDictData.setStatus("0");
  123. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  124. } else if (tWarehousebillsfees.getfBilltype().equals("HQZY")){
  125. sysDictData.setDictType("st_trans_type");
  126. sysDictData.setDictValue(String.valueOf(tWarehousebillsfees.getfFeeunitid()));
  127. sysDictData.setStatus("0");
  128. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  129. }
  130. map1.put("fId",fees.getfId());
  131. map1.put("fSrcid",fees.getfSrcid());
  132. map1.put("fSrcpid",fees.getfSrcpid());
  133. map1.put("fMblno",tWarehousebillsfees.getfMblno());
  134. map1.put("fBscorpno",tWarehousebills.getfBscorpno());
  135. map1.put("fProductName",tWarehousebillsfees.getfProductName());
  136. map1.put("fBsdate",tWarehousebillsfees.getfBsdate());
  137. map1.put("fFeeid",fees.getfFeeid());
  138. map1.put("fFeeName",tFees.getfName());
  139. map1.put("fSrcdc",fees.getfSrcdc());
  140. map1.put("fAmt",fees.getfAmt());
  141. map1.put("fAmtdr",fees.getfAmtdr());
  142. map1.put("fRemarks",fees.getfRemarks());
  143. map1.put("srcBillNo",tWarehousebillsfees.getSrcId());
  144. map1.put("fMarks",tWarehousebillsfees.getfMarks());
  145. map1.put("fChargedate",tWarehousebillsfees.getfChargedate());
  146. map1.put("fBillingDeadline",tWarehousebillsfees.getfBillingDeadline());
  147. map1.put("fBillingDays",tWarehousebillsfees.getfBillingDays());
  148. map1.put("fInventoryDays",tWarehousebillsfees.getfInventoryDays());
  149. map1.put("fFeeunitid",sysDictDataList.get(0).getDictLabel());
  150. map1.put("fQty",tWarehousebillsfees.getfQty());
  151. map1.put("fUnitprice",tWarehousebillsfees.getfUnitprice());
  152. map1.put("fBusinessType",sysDictDataListIn.get(0).getDictLabel());
  153. if(tWarehousebills.getfBilltype().equals("SJRK")){
  154. map1.put("fBilltype","入库");
  155. } else if(tWarehousebills.getfBilltype().equals("SJCK")){
  156. map1.put("fBilltype","出库");
  157. } else if(tWarehousebills.getfBilltype().equals("CKDB")){
  158. map1.put("fBilltype","调拨");
  159. } else if(tWarehousebills.getfBilltype().equals("HQZY")){
  160. map1.put("fBilltype","货权转移");
  161. }
  162. feeDoList.add(map1);
  163. }
  164. }
  165. List<TCorps> corpsList = new ArrayList<>();
  166. List<Long> corpsIdList = StringUtils.integerDeduplication(corpsId);
  167. for (Long corpId : corpsIdList) {
  168. TCorps corps = tCorpsMapper.selectTCorpsById(corpId);
  169. if (StringUtils.isNotNull(corps)) {
  170. corpsList.add(corps);
  171. }
  172. }
  173. List<TFees> feesList = new ArrayList<>();
  174. List<Long> longList = StringUtils.integerDeduplication(feesId);
  175. for (Long fees : longList) {
  176. TFees tFees = tFeesMapper.selectTFeesById(fees);
  177. if (StringUtils.isNotNull(tFees)) {
  178. feesList.add(tFees);
  179. }
  180. }
  181. map.put("tFee",tFee);
  182. map.put("corps",corpsList);
  183. map.put("feesList", feesList);
  184. map.put("feeDoList",feeDoList);
  185. return map;
  186. }
  187. /**
  188. * 查询财务数据主列表
  189. *
  190. * @param tFee 财务数据主
  191. * @return 财务数据主
  192. */
  193. @Override
  194. public List<TFee> selectTFeeList(TFee tFee) {
  195. return tFeeMapper.selectTFeeList(tFee);
  196. }
  197. @Override
  198. public List<Map<String, Object>> selectTFeeList1(TFee tFee) {
  199. return tFeeMapper.selectTFeeList1(tFee);
  200. }
  201. /**
  202. * 新增财务数据主
  203. *
  204. * @param tFee 财务数据主
  205. * @return 结果
  206. */
  207. @Override
  208. public int insertTFee(TFee tFee) {
  209. tFee.setCreateTime(DateUtils.getNowDate());
  210. return tFeeMapper.insertTFee(tFee);
  211. }
  212. /**
  213. * 新增对账 、收费、
  214. * @param tfee
  215. * @param tfeeDo
  216. * @param loginUser
  217. * @param fBilltype
  218. * @return
  219. */
  220. @Override
  221. @Transactional
  222. public AjaxResult insertTFeeTFeeDo(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  223. Long fPid = null;
  224. Map<String, Object> map = new HashMap<>();
  225. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  226. if (StringUtils.isNull(tFee.getfId())) {
  227. // 如果是新数据
  228. tFee.setCreateBy(loginUser.getUser().getUserName());
  229. tFee.setCreateTime(new Date());
  230. tFee.setfDeptid(loginUser.getUser().getDeptId());
  231. tFee.setfBilltype(fBilltype);
  232. // 业务编码
  233. Date time = new Date();
  234. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  235. tFee.setfBillno(billNo);
  236. tFeeMapper.insertTFee(tFee);
  237. fPid = tFee.getfId();
  238. } else {
  239. fPid = tFee.getfId();
  240. tFee.setUpdateBy(loginUser.getUser().getUserName());
  241. tFee.setUpdateTime(new Date());
  242. tFeeMapper.updateTFee(tFee);
  243. // 删除从表
  244. tFeeDoMapper.deleteByFPid(fPid);
  245. }
  246. // 财务从表
  247. if (StringUtils.isNotNull(tfeeDo)) {
  248. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  249. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  250. for (TFeeDo tFeeDo : tFeeDoList) {
  251. tFeeDo.setfPid(fPid);
  252. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  253. tFeeDo.setCreateTime(new Date());
  254. tFeeDoMapper.insertTFeeDo(tFeeDo);
  255. }
  256. }
  257. map.put("tFee", tFee);
  258. return AjaxResult.success("成功", map);
  259. }
  260. /**
  261. * 修改财务数据主
  262. *
  263. * @param tFee 财务数据主
  264. * @return 结果
  265. */
  266. @Override
  267. public int updateTFee(TFee tFee) {
  268. tFee.setUpdateTime(DateUtils.getNowDate());
  269. return tFeeMapper.updateTFee(tFee);
  270. }
  271. /**
  272. * 批量删除财务数据主
  273. *
  274. * @param fIds 需要删除的财务数据主ID
  275. * @return 结果
  276. */
  277. @Override
  278. public int deleteTFeeByIds(Long[] fIds) {
  279. // 取出业务编号、 放入 billno_del
  280. for (Long id : fIds) {
  281. // 1、查询主表信息
  282. TFee tFee = tFeeMapper.selectTFeeById(id);
  283. // 2、业务编号、客存编号 放入 billno_del
  284. BillnoDel billnoDel = new BillnoDel();
  285. billnoDel.setBillType(tFee.getfBilltype());
  286. billnoDel.setBillNo(tFee.getfBillno());
  287. billnoDelMapper.insertBillnoDel(billnoDel);
  288. }
  289. return tFeeMapper.deleteTFeeByIds(fIds);
  290. }
  291. /**
  292. * 删除财务数据主信息
  293. *
  294. * @param fId 财务数据主ID
  295. * @return 结果
  296. */
  297. @Override
  298. public int deleteTFeeById(Long fId) {
  299. return tFeeMapper.deleteTFeeById(fId);
  300. }
  301. @Override
  302. public List<Map<String, Object>> warehouseBillsFeesList(TWareHouseFees tWareHouseFees,String billsType) {
  303. List<Map<String, Object>> maps =new ArrayList<Map<String, Object>>();
  304. Map<String, Object> map = new HashMap<>();
  305. map.put("tWareHouseFees", tWareHouseFees);
  306. List<Map<String, Object>> mapList =new ArrayList<>();
  307. if(billsType.equals("DZ")){
  308. mapList = tFeeMapper.warehouseBillsFeesListAccamount(map);
  309. } else{
  310. mapList = tFeeMapper.warehouseBillsFeesList(map);
  311. /*if(tWareHouseFees.getfStatementNo()!=null && !tWareHouseFees.getfStatementNo().equals("")){
  312. mapList = tFeeMapper.warehouseBillsFeesListAccamount(map);
  313. }else {
  314. }*/
  315. }
  316. return mapList;
  317. }
  318. @Override
  319. public List<Map<String, Object>> warehouseBillsFeesList(TWareHouseFees tWareHouseFees) {
  320. return tFeeMapper.warehouseBillsFeesList1(tWareHouseFees);
  321. }
  322. @Override
  323. public List<Map<String, Object>> warehouseBillsFeesProfitList(TWareHouseFees tWareHouseFees) {
  324. return tFeeMapper.warehouseBillsFeesProfitList(tWareHouseFees);
  325. }
  326. public static BigDecimal calculation1(String fTotalgross, String fGrossweightblc) {
  327. BigDecimal num1 = new BigDecimal(fTotalgross);
  328. BigDecimal num2 = new BigDecimal(fGrossweightblc);
  329. BigDecimal result = num1.subtract(num2);
  330. return result.setScale(2, BigDecimal.ROUND_HALF_UP);
  331. }
  332. @Override
  333. @Transactional
  334. public AjaxResult confirm(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  335. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  336. tFee.setfBillstatus("4");
  337. if (StringUtils.isNull(tFee.getfId())) {
  338. // 如果是新数据
  339. tFee.setCreateBy(loginUser.getUser().getUserName());
  340. tFee.setfDeptid(loginUser.getUser().getDeptId());
  341. tFee.setfBilltype(fBilltype);
  342. // 业务编码
  343. Date time = new Date();
  344. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  345. tFee.setfBillno(billNo);
  346. tFeeMapper.insertTFee(tFee);
  347. } else {
  348. tFee.setUpdateBy(loginUser.getUser().getUserName());
  349. tFee.setUpdateTime(new Date());
  350. tFeeMapper.updateTFee(tFee);
  351. // 删除从表
  352. tFeeDoMapper.deleteByFPid(tFee.getfId());
  353. }
  354. // 财务从表
  355. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  356. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  357. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  358. for (TFeeDo tFeeDo : tFeeDoList) {
  359. tFeeDo.setfPid(tFee.getfId());
  360. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  361. tFeeDo.setCreateTime(new Date());
  362. tFeeDoMapper.insertTFeeDo(tFeeDo);
  363. }
  364. }
  365. // 这里加个判断取系统参数来确定是否需要启用审批流
  366. String key = "";
  367. boolean isApprove = false;
  368. long actId = 0L;
  369. if ("DZ".equals(fBilltype)) {
  370. actId = 210L;
  371. key = "warehouse.contrast.ApprovalFlow";
  372. } else if ("SF".equals(fBilltype)) {
  373. actId = 220L;
  374. key = "warehouse.charge.ApprovalFlow";
  375. } else if ("FF".equals(fBilltype)) {
  376. actId = 230L;
  377. key = "warehouse.payment.ApprovalFlow";
  378. }
  379. SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique(key);
  380. if (StringUtils.isNull(sysConfig)) {
  381. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  382. return AjaxResult.error("系统参数异常,未找到开启审批流参数");
  383. }
  384. if ("0".equals(sysConfig.getConfigValue())) {
  385. isApprove = true;
  386. }
  387. if (isApprove) {
  388. AuditItems auditItems = new AuditItems();
  389. auditItems.setLevelId(0L);
  390. auditItems.setBillId(tFee.getfId());
  391. auditItems.setActId(actId);
  392. auditItems.setIffinalItem("F");
  393. auditItems.setBillNo(tFee.getfBillno()); // 业务编号
  394. auditItems.setRefno1(String.valueOf(tFee.getfCorpid())); // 货权方
  395. auditItems.setRefno2(tFee.getfBilltype());// 财务类型
  396. auditItems.setRefno3(tFee.gettMblno());// 提单号
  397. auditItems.setSendUserId(loginUser.getUser().getUserId());
  398. auditItems.setSendName(loginUser.getUsername());
  399. auditItems.setSendTime(new Date());
  400. auditItems.setAuditUserId(loginUser.getUser().getUserId());
  401. auditItems.setAuditItem(new Date());
  402. auditItems.setAuditOpTime(new Date());
  403. auditItems.setAuditMsg("提交");
  404. auditItems.setAuditStatus("O");
  405. AjaxResult approvalFlow = auditItemsService.createApprovalFlow(auditItems);
  406. Long code = Long.valueOf(String.valueOf(approvalFlow.get("code"))).longValue();
  407. if (code.equals(500L)) {
  408. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  409. }
  410. return approvalFlow;
  411. }else {
  412. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  413. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  414. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  415. for (TFeeDo tFeeDo : tFeeDoList) {
  416. // 跟新费用明细
  417. int m = updateBillsFees(tFee.getfId(),tFeeDo,fBilltype);
  418. if (m == 0) {
  419. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  420. return AjaxResult.error("更新费用明细失败");
  421. }
  422. }
  423. }
  424. AjaxResult ajaxResult = tfeeFollow(tFee.getfId(), 6L);
  425. Long code = Long.valueOf(String.valueOf(ajaxResult.get("code"))).longValue();
  426. return ajaxResult;
  427. }
  428. }
  429. /**
  430. * 根据财务主表id 更新对应明细表状态
  431. *
  432. * @param fPid 财务主表id
  433. * @return 结果
  434. */
  435. @Transactional
  436. public AjaxResult tfeeFollow(Long fPid, long fettle) {
  437. if (StringUtils.isNull(fPid)) {
  438. return AjaxResult.error("财务更新状态未找到主表信息,请与管理员联系");
  439. }
  440. TFee tFee = new TFee();
  441. tFee.setfId(fPid);
  442. tFee.setfBillstatus(String.valueOf(fettle));
  443. int tFeeUpdateResult = tFeeMapper.updateTFee(tFee);
  444. if (tFeeUpdateResult <= 0) {
  445. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  446. return AjaxResult.error("更新财务明细状态失败,请联系管理员");
  447. }
  448. try{
  449. int itemUpdateResult = tFeeDoMapper.tfeeDoFollowUpdate(fPid,fettle);
  450. } catch (Exception exception){
  451. return AjaxResult.error("更新财务明细状态失败,请联系管理员");
  452. }
  453. return AjaxResult.success();
  454. }
  455. @Transactional
  456. public AjaxResult billsfeesFollow(Long fPid) {
  457. if (StringUtils.isNull(fPid)) {
  458. return AjaxResult.error("费用明细更新状态未找到主表信息,请与管理员联系");
  459. }
  460. TFee tFee=tFeeMapper.selectTFeeById(fPid);
  461. // 查询从表数据
  462. TFeeDo tFeeDo = new TFeeDo();
  463. tFeeDo.setfPid(fPid);
  464. List<TFeeDo> tFeeDoList= tFeeDoMapper.selectTFeeDoList(tFeeDo);
  465. for (TFeeDo tFeeDo1 : tFeeDoList) {
  466. // 跟新费用明细
  467. int m = updateBillsFees(fPid,tFeeDo1,tFee.getfBilltype());
  468. if (m == 0) {
  469. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  470. return AjaxResult.error("更新费用明细失败");
  471. }
  472. }
  473. return AjaxResult.success();
  474. }
  475. @Override
  476. @Transactional
  477. public AjaxResult revoke(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  478. // 更新 主表、从表
  479. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  480. tFee.setUpdateBy(loginUser.getUser().getUserName());
  481. tFee.setUpdateTime(new Date());
  482. tFeeMapper.updateTFee(tFee);
  483. // 删除从表
  484. tFeeDoMapper.deleteByFPid(tFee.getfId());
  485. // 财务从表
  486. if (StringUtils.isNotNull(tfeeDo)) {
  487. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  488. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  489. for (TFeeDo tFeeDo : tFeeDoList) {
  490. tFeeDo.setfPid(tFee.getfId());
  491. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  492. tFeeDo.setCreateTime(new Date());
  493. tFeeDoMapper.insertTFeeDo(tFeeDo);
  494. // 跟新费用明细
  495. int m = updateBillsFees(tFee.getfId(),tFeeDo,fBilltype);
  496. if (m == 0) {
  497. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  498. return AjaxResult.error("更新费用明细失败");
  499. }
  500. }
  501. }
  502. return AjaxResult.success();
  503. }
  504. @Override
  505. public AjaxResult queryRemove(Long fId) {
  506. TFee tFee=tFeeMapper.selectTFeeById(fId);
  507. TFeeDo tFeeDo = new TFeeDo();
  508. tFeeDo.setfPid(tFee.getfId());
  509. List<TFeeDo> tFeeDoList= tFeeDoMapper.selectTFeeDoList(tFeeDo);
  510. if( StringUtils.isNull(tFee)){
  511. return AjaxResult.success("0");
  512. } else if(StringUtils.isNotNull(tFee) && StringUtils.isEmpty(tFeeDoList) ){
  513. return AjaxResult.success("1");
  514. } else {
  515. return AjaxResult.success("2");
  516. }
  517. }
  518. @Override
  519. public List<TWareHouseExcelItem> selectTWarehousebillsItemsList(Long fId) {
  520. return tFeeMapper.selectTWarehousebillsItemsList(fId);
  521. }
  522. @Override
  523. public String findCtrlcorpid(Long fId) {
  524. TFee tFee=tFeeMapper.selectTFeeById(fId);
  525. String exportName = tFee.getfCtrlcorpid()+"-"+tFee.getfBillno();
  526. return exportName;
  527. }
  528. @Override
  529. public List<Receivable> receivableExport(TWareHouseFees tWareHouseFees) throws Exception {
  530. List<Map<String, Object>> list = tFeeMapper.warehouseBillsFeesList1(tWareHouseFees);
  531. List<Receivable> list1 = ListMapToBeanUtils.castMapToBean(list,Receivable.class);
  532. return list1;
  533. }
  534. @Override
  535. public List<Payable> payableExport(TWareHouseFees tWareHouseFees) throws Exception {
  536. List<Map<String, Object>> list = tFeeMapper.warehouseBillsFeesList1(tWareHouseFees);
  537. List<Payable> list1 = ListMapToBeanUtils.castMapToBean(list,Payable.class);
  538. return list1;
  539. }
  540. @Override
  541. public List<Profit> profitExport(TWareHouseFees tWareHouseFees) throws Exception {
  542. List<Map<String, Object>> list = tFeeMapper.warehouseBillsFeesProfitList(tWareHouseFees);
  543. List<Profit> list1 = ListMapToBeanUtils.castMapToBean(list,Profit.class);
  544. return list1;
  545. }
  546. @Override
  547. public List<Contrast> contrastExport(TFee tFee) throws Exception {
  548. List<Map<String, Object>> list = tFeeMapper.selectTFeeList1(tFee);
  549. List<Contrast> list1 = ListMapToBeanUtils.castMapToBean(list,Contrast.class);
  550. return list1;
  551. }
  552. /**
  553. * 更新费用明细
  554. * @param fid
  555. * @param tFeeDo
  556. * @param billsType
  557. * @return
  558. */
  559. @Transactional
  560. public int updateBillsFees(Long fid,TFeeDo tFeeDo,String billsType){
  561. // 查询从表数据
  562. TFee tFee=tFeeMapper.selectTFeeById(fid);
  563. if(billsType.equals("SF") || billsType.equals("FF")){
  564. billsType="DC";
  565. }
  566. Map<String, Object> map = new HashMap<>();
  567. map.put("tFee", tFee);
  568. map.put("billType", billsType);
  569. map.put("tFeeDo", tFeeDo);
  570. return tWarehousebillsfeesMapper.updateTWarehousebillsfee(map);
  571. }
  572. }