TFeeServiceImpl.java 25 KB

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