TFeeServiceImpl.java 23 KB

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