TFeeServiceImpl.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  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.TWarehouseBills;
  32. import com.ruoyi.warehouseBusiness.domain.TWarehousebillsfees;
  33. import com.ruoyi.warehouseBusiness.excel.ListMapToBeanUtils;
  34. import com.ruoyi.warehouseBusiness.excel.TWareHouseExcelItem;
  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.getfBusinessType()));
  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.getfBusinessType()));
  124. sysDictData.setStatus("0");
  125. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  126. } else if (tWarehousebillsfees.getfBilltype().equals("CKDB") | tWarehousebillsfees.getfBilltype().equals("HWTG") ){
  127. sysDictData.setDictType("st_trans_type");
  128. sysDictData.setDictValue(String.valueOf(tWarehousebillsfees.getfBusinessType()));
  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("HWTG")){
  162. map1.put("fBilltype","货物通关");
  163. } else if(tWarehousebills.getfBilltype().equals("HQZY")){
  164. map1.put("fBilltype","货权转移");
  165. }
  166. feeDoList.add(map1);
  167. }
  168. }
  169. List<TCorps> corpsList = new ArrayList<>();
  170. List<Long> corpsIdList = StringUtils.integerDeduplication(corpsId);
  171. for (Long corpId : corpsIdList) {
  172. TCorps corps = tCorpsMapper.selectTCorpsById(corpId);
  173. if (StringUtils.isNotNull(corps)) {
  174. corpsList.add(corps);
  175. }
  176. }
  177. List<TFees> feesList = new ArrayList<>();
  178. List<Long> longList = StringUtils.integerDeduplication(feesId);
  179. for (Long fees : longList) {
  180. TFees tFees = tFeesMapper.selectTFeesById(fees);
  181. if (StringUtils.isNotNull(tFees)) {
  182. feesList.add(tFees);
  183. }
  184. }
  185. map.put("tFee",tFee);
  186. map.put("corps",corpsList);
  187. map.put("feesList", feesList);
  188. map.put("feeDoList",feeDoList);
  189. return map;
  190. }
  191. /**
  192. * 查询财务数据主列表
  193. *
  194. * @param tFee 财务数据主
  195. * @return 财务数据主
  196. */
  197. @Override
  198. public List<TFee> selectTFeeList(TFee tFee) {
  199. return tFeeMapper.selectTFeeList(tFee);
  200. }
  201. @Override
  202. public List<Map<String, Object>> selectTFeeList1(TFee tFee) {
  203. return tFeeMapper.selectTFeeList1(tFee);
  204. }
  205. /**
  206. * 新增财务数据主
  207. *
  208. * @param tFee 财务数据主
  209. * @return 结果
  210. */
  211. @Override
  212. public int insertTFee(TFee tFee) {
  213. tFee.setCreateTime(DateUtils.getNowDate());
  214. return tFeeMapper.insertTFee(tFee);
  215. }
  216. /**
  217. * 新增对账 、收费、
  218. * @param tfee
  219. * @param tfeeDo
  220. * @param loginUser
  221. * @param fBilltype
  222. * @return
  223. */
  224. @Override
  225. @Transactional
  226. public AjaxResult insertTFeeTFeeDo(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  227. Long fPid = null;
  228. Map<String, Object> map = new HashMap<>();
  229. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  230. if (StringUtils.isNull(tFee.getfId())) {
  231. // 如果是新数据
  232. tFee.setCreateBy(loginUser.getUser().getUserName());
  233. tFee.setCreateTime(new Date());
  234. tFee.setfDeptid(loginUser.getUser().getDeptId());
  235. tFee.setfBilltype(fBilltype);
  236. // 业务编码
  237. Date time = new Date();
  238. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  239. tFee.setfBillno(billNo);
  240. tFeeMapper.insertTFee(tFee);
  241. fPid = tFee.getfId();
  242. } else {
  243. fPid = tFee.getfId();
  244. tFee.setUpdateBy(loginUser.getUser().getUserName());
  245. tFee.setUpdateTime(new Date());
  246. tFeeMapper.updateTFee(tFee);
  247. // 删除从表
  248. tFeeDoMapper.deleteByFPid(fPid);
  249. }
  250. // 财务从表
  251. if (StringUtils.isNotNull(tfeeDo)) {
  252. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  253. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  254. for (TFeeDo tFeeDo : tFeeDoList) {
  255. tFeeDo.setfPid(fPid);
  256. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  257. tFeeDo.setCreateTime(new Date());
  258. tFeeDoMapper.insertTFeeDo(tFeeDo);
  259. }
  260. }
  261. map.put("tFee", tFee);
  262. return AjaxResult.success("成功", map);
  263. }
  264. /**
  265. * 修改财务数据主
  266. *
  267. * @param tFee 财务数据主
  268. * @return 结果
  269. */
  270. @Override
  271. public int updateTFee(TFee tFee) {
  272. tFee.setUpdateTime(DateUtils.getNowDate());
  273. return tFeeMapper.updateTFee(tFee);
  274. }
  275. /**
  276. * 批量删除财务数据主
  277. *
  278. * @param fIds 需要删除的财务数据主ID
  279. * @return 结果
  280. */
  281. @Override
  282. public int deleteTFeeByIds(Long[] fIds) {
  283. // 取出业务编号、 放入 billno_del
  284. for (Long id : fIds) {
  285. // 1、查询主表信息
  286. TFee tFee = tFeeMapper.selectTFeeById(id);
  287. // 2、业务编号、客存编号 放入 billno_del
  288. BillnoDel billnoDel = new BillnoDel();
  289. billnoDel.setBillType(tFee.getfBilltype());
  290. billnoDel.setBillNo(tFee.getfBillno());
  291. billnoDelMapper.insertBillnoDel(billnoDel);
  292. }
  293. return tFeeMapper.deleteTFeeByIds(fIds);
  294. }
  295. /**
  296. * 删除财务数据主信息
  297. *
  298. * @param fId 财务数据主ID
  299. * @return 结果
  300. */
  301. @Override
  302. public int deleteTFeeById(Long fId) {
  303. return tFeeMapper.deleteTFeeById(fId);
  304. }
  305. @Override
  306. public List<Map<String, Object>> warehouseBillsFeesList(TWareHouseFees tWareHouseFees,String billsType) {
  307. List<Map<String, Object>> maps =new ArrayList<Map<String, Object>>();
  308. Map<String, Object> map = new HashMap<>();
  309. map.put("tWareHouseFees", tWareHouseFees);
  310. List<Map<String, Object>> mapList =new ArrayList<>();
  311. if(billsType.equals("DZ")){
  312. mapList = tFeeMapper.warehouseBillsFeesListAccamount(map);
  313. } else{
  314. mapList = tFeeMapper.warehouseBillsFeesList(map);
  315. /*if(tWareHouseFees.getfStatementNo()!=null && !tWareHouseFees.getfStatementNo().equals("")){
  316. mapList = tFeeMapper.warehouseBillsFeesListAccamount(map);
  317. }else {
  318. }*/
  319. }
  320. return mapList;
  321. }
  322. @Override
  323. public List<Map<String, Object>> warehouseBillsFeesList(TWareHouseFees tWareHouseFees) {
  324. return tFeeMapper.warehouseBillsFeesList1(tWareHouseFees);
  325. }
  326. @Override
  327. public List<Map<String, Object>> warehouseBillsFeesProfitList(TWareHouseFees tWareHouseFees) {
  328. return tFeeMapper.warehouseBillsFeesProfitList(tWareHouseFees);
  329. }
  330. public static BigDecimal calculation1(String fTotalgross, String fGrossweightblc) {
  331. BigDecimal num1 = new BigDecimal(fTotalgross);
  332. BigDecimal num2 = new BigDecimal(fGrossweightblc);
  333. BigDecimal result = num1.subtract(num2);
  334. return result.setScale(2, BigDecimal.ROUND_HALF_UP);
  335. }
  336. @Override
  337. @Transactional
  338. public AjaxResult confirm(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  339. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  340. tFee.setfBillstatus("4");
  341. if (StringUtils.isNull(tFee.getfId())) {
  342. // 如果是新数据
  343. tFee.setCreateBy(loginUser.getUser().getUserName());
  344. tFee.setfDeptid(loginUser.getUser().getDeptId());
  345. tFee.setfBilltype(fBilltype);
  346. // 业务编码
  347. Date time = new Date();
  348. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  349. tFee.setfBillno(billNo);
  350. tFeeMapper.insertTFee(tFee);
  351. } else {
  352. tFee.setUpdateBy(loginUser.getUser().getUserName());
  353. tFee.setUpdateTime(new Date());
  354. tFeeMapper.updateTFee(tFee);
  355. // 删除从表
  356. tFeeDoMapper.deleteByFPid(tFee.getfId());
  357. }
  358. // 财务从表
  359. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  360. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  361. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  362. for (TFeeDo tFeeDo : tFeeDoList) {
  363. tFeeDo.setfPid(tFee.getfId());
  364. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  365. tFeeDo.setCreateTime(new Date());
  366. tFeeDoMapper.insertTFeeDo(tFeeDo);
  367. }
  368. }
  369. // 这里加个判断取系统参数来确定是否需要启用审批流
  370. String key = "";
  371. boolean isApprove = false;
  372. long actId = 0L;
  373. if ("DZ".equals(fBilltype)) {
  374. actId = 210L;
  375. key = "warehouse.contrast.ApprovalFlow";
  376. } else if ("SF".equals(fBilltype)) {
  377. actId = 220L;
  378. key = "warehouse.charge.ApprovalFlow";
  379. } else if ("FF".equals(fBilltype)) {
  380. actId = 230L;
  381. key = "warehouse.payment.ApprovalFlow";
  382. }
  383. SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique(key);
  384. if (StringUtils.isNull(sysConfig)) {
  385. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  386. return AjaxResult.error("系统参数异常,未找到开启审批流参数");
  387. }
  388. if ("0".equals(sysConfig.getConfigValue())) {
  389. isApprove = true;
  390. }
  391. if (isApprove) {
  392. AuditItems auditItems = new AuditItems();
  393. auditItems.setLevelId(0L);
  394. auditItems.setBillId(tFee.getfId());
  395. auditItems.setActId(actId);
  396. auditItems.setIffinalItem("F");
  397. auditItems.setBillNo(tFee.getfBillno()); // 业务编号
  398. auditItems.setRefno1(String.valueOf(tFee.getfCorpid())); // 货权方
  399. auditItems.setRefno2(tFee.getfBilltype());// 财务类型
  400. auditItems.setRefno3(tFee.gettMblno());// 提单号
  401. auditItems.setSendUserId(loginUser.getUser().getUserId());
  402. auditItems.setSendName(loginUser.getUsername());
  403. auditItems.setSendTime(new Date());
  404. auditItems.setAuditUserId(loginUser.getUser().getUserId());
  405. auditItems.setAuditItem(new Date());
  406. auditItems.setAuditOpTime(new Date());
  407. auditItems.setAuditMsg("提交");
  408. auditItems.setAuditStatus("O");
  409. AjaxResult approvalFlow = auditItemsService.createApprovalFlow(auditItems);
  410. Long code = Long.valueOf(String.valueOf(approvalFlow.get("code"))).longValue();
  411. if (code.equals(500L)) {
  412. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  413. }
  414. return approvalFlow;
  415. }else {
  416. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  417. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  418. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  419. for (TFeeDo tFeeDo : tFeeDoList) {
  420. // 跟新费用明细
  421. int m = updateBillsFees(tFee.getfId(),tFeeDo,fBilltype);
  422. if (m == 0) {
  423. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  424. return AjaxResult.error("更新费用明细失败");
  425. }
  426. }
  427. }
  428. AjaxResult ajaxResult = tfeeFollow(tFee.getfId(), 6L);
  429. Long code = Long.valueOf(String.valueOf(ajaxResult.get("code"))).longValue();
  430. return ajaxResult;
  431. }
  432. }
  433. /**
  434. * 根据财务主表id 更新对应明细表状态
  435. *
  436. * @param fPid 财务主表id
  437. * @return 结果
  438. */
  439. @Transactional
  440. public AjaxResult tfeeFollow(Long fPid, long fettle) {
  441. if (StringUtils.isNull(fPid)) {
  442. return AjaxResult.error("财务更新状态未找到主表信息,请与管理员联系");
  443. }
  444. TFee tFee = new TFee();
  445. tFee.setfId(fPid);
  446. tFee.setfBillstatus(String.valueOf(fettle));
  447. int tFeeUpdateResult = tFeeMapper.updateTFee(tFee);
  448. if (tFeeUpdateResult <= 0) {
  449. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  450. return AjaxResult.error("更新财务明细状态失败,请联系管理员");
  451. }
  452. try{
  453. int itemUpdateResult = tFeeDoMapper.tfeeDoFollowUpdate(fPid,fettle);
  454. } catch (Exception exception){
  455. return AjaxResult.error("更新财务明细状态失败,请联系管理员");
  456. }
  457. return AjaxResult.success();
  458. }
  459. @Transactional
  460. public AjaxResult billsfeesFollow(Long fPid) {
  461. if (StringUtils.isNull(fPid)) {
  462. return AjaxResult.error("费用明细更新状态未找到主表信息,请与管理员联系");
  463. }
  464. TFee tFee=tFeeMapper.selectTFeeById(fPid);
  465. // 查询从表数据
  466. TFeeDo tFeeDo = new TFeeDo();
  467. tFeeDo.setfPid(fPid);
  468. List<TFeeDo> tFeeDoList= tFeeDoMapper.selectTFeeDoList(tFeeDo);
  469. for (TFeeDo tFeeDo1 : tFeeDoList) {
  470. // 跟新费用明细
  471. int m = updateBillsFees(fPid,tFeeDo1,tFee.getfBilltype());
  472. if (m == 0) {
  473. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  474. return AjaxResult.error("更新费用明细失败");
  475. }
  476. }
  477. return AjaxResult.success();
  478. }
  479. @Override
  480. @Transactional
  481. public AjaxResult revoke(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  482. // 更新 主表、从表
  483. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  484. tFee.setUpdateBy(loginUser.getUser().getUserName());
  485. tFee.setUpdateTime(new Date());
  486. tFeeMapper.updateTFee(tFee);
  487. // 删除从表
  488. tFeeDoMapper.deleteByFPid(tFee.getfId());
  489. // 财务从表
  490. if (StringUtils.isNotNull(tfeeDo)) {
  491. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  492. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  493. for (TFeeDo tFeeDo : tFeeDoList) {
  494. tFeeDo.setfPid(tFee.getfId());
  495. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  496. tFeeDo.setCreateTime(new Date());
  497. tFeeDoMapper.insertTFeeDo(tFeeDo);
  498. // 跟新费用明细
  499. int m = updateBillsFees(tFee.getfId(),tFeeDo,fBilltype);
  500. if (m == 0) {
  501. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  502. return AjaxResult.error("更新费用明细失败");
  503. }
  504. }
  505. }
  506. return AjaxResult.success();
  507. }
  508. @Override
  509. public AjaxResult queryRemove(Long fId) {
  510. TFee tFee=tFeeMapper.selectTFeeById(fId);
  511. TFeeDo tFeeDo = new TFeeDo();
  512. tFeeDo.setfPid(tFee.getfId());
  513. List<TFeeDo> tFeeDoList= tFeeDoMapper.selectTFeeDoList(tFeeDo);
  514. if( StringUtils.isNull(tFee)){
  515. return AjaxResult.success("0");
  516. } else if(StringUtils.isNotNull(tFee) && StringUtils.isEmpty(tFeeDoList) ){
  517. return AjaxResult.success("1");
  518. } else {
  519. return AjaxResult.success("2");
  520. }
  521. }
  522. @Override
  523. public List<TWareHouseExcelItem> selectTWarehousebillsItemsList(Long fId) {
  524. List<TWareHouseExcelItem> tWareHouseExcelItemList = tFeeMapper.selectTWarehousebillsItemsList(fId);
  525. List<TWareHouseExcelItem> tWareHouseExcelItemList1 = new ArrayList<>();
  526. for (TWareHouseExcelItem tWareHouseExcelItem : tWareHouseExcelItemList){
  527. if(StringUtils.isNotNull(tWareHouseExcelItem.getfBusinessType())){
  528. List<SysDictData> sysDictDataListIn = new ArrayList<>();
  529. SysDictData sysDictData =new SysDictData();
  530. if(tWareHouseExcelItem.getfBilltype().equals("入库")){
  531. sysDictData.setDictType("st_in_type");
  532. sysDictData.setDictValue(String.valueOf(tWareHouseExcelItem.getfBusinessType()));
  533. sysDictData.setStatus("0");
  534. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  535. } else if (tWareHouseExcelItem.getfBilltype().equals("出库")){
  536. sysDictData.setDictType("st_out_type");
  537. sysDictData.setDictValue(String.valueOf(tWareHouseExcelItem.getfBusinessType()));
  538. sysDictData.setStatus("0");
  539. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  540. } else if (tWareHouseExcelItem.getfBilltype().equals("调拨") | tWareHouseExcelItem.getfBilltype().equals("货物通关") ){
  541. sysDictData.setDictType("st_trans_type");
  542. sysDictData.setDictValue(String.valueOf(tWareHouseExcelItem.getfBusinessType()));
  543. sysDictData.setStatus("0");
  544. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  545. }
  546. if(null!=sysDictDataListIn && sysDictDataListIn.size()>0){
  547. tWareHouseExcelItem.setfBusinessType(sysDictDataListIn.get(0).getDictLabel());
  548. }
  549. }
  550. tWareHouseExcelItemList1.add(tWareHouseExcelItem);
  551. }
  552. return tWareHouseExcelItemList1;
  553. }
  554. @Override
  555. public String findCtrlcorpid(Long fId) {
  556. TFee tFee=tFeeMapper.selectTFeeById(fId);
  557. String exportName = tFee.getfCtrlcorpid()+"-"+tFee.getfBillno();
  558. return exportName;
  559. }
  560. @Override
  561. public List<Receivable> receivableExport(TWareHouseFees tWareHouseFees) throws Exception {
  562. List<Map<String, Object>> list = tFeeMapper.warehouseBillsFeesList1(tWareHouseFees);
  563. List<Receivable> list1 = ListMapToBeanUtils.castMapToBean(list,Receivable.class);
  564. return list1;
  565. }
  566. @Override
  567. public List<Payable> payableExport(TWareHouseFees tWareHouseFees) throws Exception {
  568. List<Map<String, Object>> list = tFeeMapper.warehouseBillsFeesList1(tWareHouseFees);
  569. List<Payable> list1 = ListMapToBeanUtils.castMapToBean(list,Payable.class);
  570. return list1;
  571. }
  572. @Override
  573. public List<Profit> profitExport(TWareHouseFees tWareHouseFees) throws Exception {
  574. List<Map<String, Object>> list = tFeeMapper.warehouseBillsFeesProfitList(tWareHouseFees);
  575. List<Profit> list1 = ListMapToBeanUtils.castMapToBean(list,Profit.class);
  576. return list1;
  577. }
  578. @Override
  579. public List<Contrast> contrastExport(TFee tFee) throws Exception {
  580. List<Map<String, Object>> list = tFeeMapper.selectTFeeList1(tFee);
  581. List<Contrast> list1 = ListMapToBeanUtils.castMapToBean(list,Contrast.class);
  582. return list1;
  583. }
  584. @Override
  585. public List<Payment> paymentExport(TFee tFee) throws Exception {
  586. List<Map<String, Object>> list = tFeeMapper.selectFeeList(tFee);
  587. List<Payment> list1 = ListMapToBeanUtils.castMapToBean(list,Payment.class);
  588. return list1;
  589. }
  590. @Override
  591. public List<Charge> chargeExport(TFee tFee) throws Exception {
  592. List<Map<String, Object>> list = tFeeMapper.selectFeeList(tFee);
  593. List<Charge> list1 = ListMapToBeanUtils.castMapToBean(list,Charge.class);
  594. return list1;
  595. }
  596. /**
  597. * 更新费用明细
  598. * @param fid
  599. * @param tFeeDo
  600. * @param billsType
  601. * @return
  602. */
  603. @Transactional
  604. public int updateBillsFees(Long fid,TFeeDo tFeeDo,String billsType){
  605. // 查询从表数据
  606. TFee tFee=tFeeMapper.selectTFeeById(fid);
  607. if(billsType.equals("SF") || billsType.equals("FF")){
  608. billsType="DC";
  609. }
  610. Map<String, Object> map = new HashMap<>();
  611. map.put("tFee", tFee);
  612. map.put("billType", billsType);
  613. map.put("tFeeDo", tFeeDo);
  614. return tWarehousebillsfeesMapper.updateTWarehousebillsfee(map);
  615. }
  616. }