TFeeServiceImpl.java 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326
  1. package com.ruoyi.finance.service.impl;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
  5. import com.ruoyi.approvalFlow.domain.AuditItems;
  6. import com.ruoyi.approvalFlow.mapper.AuditItemsDoMapper;
  7. import com.ruoyi.approvalFlow.mapper.AuditItemsMapper;
  8. import com.ruoyi.approvalFlow.service.impl.AuditItemsAbout;
  9. import com.ruoyi.approvalFlow.service.impl.AuditItemsServiceImpl;
  10. import com.ruoyi.basicData.domain.TCorps;
  11. import com.ruoyi.basicData.domain.TFees;
  12. import com.ruoyi.basicData.mapper.TCorpsMapper;
  13. import com.ruoyi.basicData.mapper.TFeesMapper;
  14. import com.ruoyi.common.config.RuoYiConfig;
  15. import com.ruoyi.common.core.domain.AjaxResult;
  16. import com.ruoyi.common.core.domain.entity.SysDictData;
  17. import com.ruoyi.common.core.domain.model.LoginUser;
  18. import com.ruoyi.common.exception.WarehouseException;
  19. import com.ruoyi.common.utils.DateUtils;
  20. import com.ruoyi.common.utils.DictUtils;
  21. import com.ruoyi.common.utils.StringUtils;
  22. import com.ruoyi.common.utils.poi.ExcelUtils;
  23. import com.ruoyi.finance.domain.TFee;
  24. import com.ruoyi.finance.domain.TFeeDo;
  25. import com.ruoyi.finance.domain.TWareHouseFees;
  26. import com.ruoyi.finance.domain.dto.FeeDTO;
  27. import com.ruoyi.finance.domain.excel.GeneralLedgerDetailExcel;
  28. import com.ruoyi.finance.domain.excel.GeneralLedgerExcel;
  29. import com.ruoyi.finance.domain.excel.ProfitGeneralLedgerExcel;
  30. import com.ruoyi.finance.domain.vo.FeeVO;
  31. import com.ruoyi.finance.excel.Charge;
  32. import com.ruoyi.finance.excel.Contrast;
  33. import com.ruoyi.finance.excel.Detailed;
  34. import com.ruoyi.finance.excel.Payment;
  35. import com.ruoyi.finance.mapper.TFeeDoMapper;
  36. import com.ruoyi.finance.mapper.TFeeMapper;
  37. import com.ruoyi.finance.service.ITFeeService;
  38. import com.ruoyi.finance.shipping.*;
  39. import com.ruoyi.reportManagement.dto.TWarehousebill;
  40. import com.ruoyi.reportManagement.excel.Profit;
  41. import com.ruoyi.reportManagement.excel.Receivable;
  42. import com.ruoyi.shipping.domain.TAccount;
  43. import com.ruoyi.shipping.domain.TFeeInvoice;
  44. import com.ruoyi.shipping.domain.TVessel;
  45. import com.ruoyi.shipping.domain.TVoyage;
  46. import com.ruoyi.shipping.excel.Account;
  47. import com.ruoyi.shipping.excel.ExportFinancial;
  48. import com.ruoyi.shipping.mapper.TFeeInvoiceMapper;
  49. import com.ruoyi.shipping.mapper.TVesselMapper;
  50. import com.ruoyi.shipping.mapper.TVoyageMapper;
  51. import com.ruoyi.system.domain.SysConfig;
  52. import com.ruoyi.system.mapper.SysConfigMapper;
  53. import com.ruoyi.system.mapper.SysDictDataMapper;
  54. import com.ruoyi.system.service.ISysDictDataService;
  55. import com.ruoyi.warehouseBusiness.domain.BillnoDel;
  56. import com.ruoyi.warehouseBusiness.domain.TWarehouseBills;
  57. import com.ruoyi.warehouseBusiness.domain.TWarehousebillsfees;
  58. import com.ruoyi.warehouseBusiness.domain.enums.FeesTypeEnum;
  59. import com.ruoyi.warehouseBusiness.domain.enums.WarehouseTypeEnum;
  60. import com.ruoyi.warehouseBusiness.excel.ListMapToBeanUtils;
  61. import com.ruoyi.warehouseBusiness.excel.TWareHouseExcelItem;
  62. import com.ruoyi.warehouseBusiness.mapper.BillnoDelMapper;
  63. import com.ruoyi.warehouseBusiness.mapper.TWarehouseBillsMapper;
  64. import com.ruoyi.warehouseBusiness.mapper.TWarehousebillsfeesMapper;
  65. import com.ruoyi.warehouseBusiness.service.impl.BillnoSerialServiceImpl;
  66. import org.apache.commons.compress.utils.Lists;
  67. import org.apache.poi.hssf.usermodel.*;
  68. import org.apache.poi.ss.util.CellRangeAddress;
  69. import org.springframework.beans.BeanUtils;
  70. import org.springframework.beans.factory.annotation.Autowired;
  71. import org.springframework.stereotype.Service;
  72. import org.springframework.transaction.annotation.Transactional;
  73. import org.springframework.transaction.interceptor.TransactionAspectSupport;
  74. import java.io.File;
  75. import java.io.FileOutputStream;
  76. import java.io.OutputStream;
  77. import java.math.BigDecimal;
  78. import java.text.SimpleDateFormat;
  79. import java.util.*;
  80. import java.util.stream.Collectors;
  81. import static java.util.stream.Collectors.toList;
  82. /**
  83. * 财务数据主Service业务层处理
  84. *
  85. * @author ruoyi
  86. * @date 2021-01-18
  87. */
  88. @Service
  89. public class TFeeServiceImpl implements ITFeeService {
  90. @Autowired
  91. private TFeeMapper tFeeMapper;
  92. @Autowired
  93. private TFeeDoMapper tFeeDoMapper;
  94. @Autowired
  95. private BillnoSerialServiceImpl billnoSerialServiceImpl;
  96. @Autowired
  97. private BillnoDelMapper billnoDelMapper;
  98. @Autowired
  99. private TCorpsMapper tCorpsMapper;
  100. @Autowired
  101. private TFeesMapper tFeesMapper;
  102. @Autowired
  103. private TWarehouseBillsMapper tWarehouseBillsMapper;
  104. @Autowired
  105. private TWarehousebillsfeesMapper tWarehousebillsfeesMapper;
  106. @Autowired
  107. private SysConfigMapper sysConfigMapper;
  108. @Autowired
  109. private AuditItemsServiceImpl auditItemsService;
  110. @Autowired
  111. private ISysDictDataService iSysDictDataService;
  112. @Autowired
  113. private SysDictDataMapper sysDictDataMapper;
  114. @Autowired
  115. private TFeeInvoiceMapper tFeeInvoiceMapper;
  116. @Autowired
  117. private TVesselMapper tVesselMapper;
  118. @Autowired
  119. private TVoyageMapper tVoyageMapper;
  120. private final String ST_IN_TYPE = "st_in_type";
  121. private final String ST_OUT_TYPE = "st_out_type";
  122. private final String ST_TRANS_TYPE = "st_trans_type";
  123. /**
  124. * 查询财务数据主
  125. *
  126. * @param fId 财务数据主ID
  127. * @return 财务数据主
  128. */
  129. @Override
  130. public Map<String, Object> selectTFeeById(Long fId) {
  131. Map<String, Object> map = new HashMap<>();
  132. // 客户表
  133. List<Long> corpsId = new ArrayList<>();
  134. // 费用
  135. List<Long> feesId = new ArrayList<>();
  136. //费用名称
  137. String feeName = null;
  138. TFee tFee = tFeeMapper.selectTFeeById(fId);
  139. if (StringUtils.isNotNull(tFee.getfCorpid())) {
  140. corpsId.add(tFee.getfCorpid());
  141. }
  142. corpsId.add(tFee.getfCorpid());
  143. // 查询从表数据
  144. TFeeDo tFeeDo = new TFeeDo();
  145. tFeeDo.setfPid(fId);
  146. List<TFeeDo> tFeeDoList = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  147. List<Map<String, Object>> feeDoList = new ArrayList<>();
  148. if (StringUtils.isNotEmpty(tFeeDoList)) {
  149. for (TFeeDo fees : tFeeDoList) {
  150. Map<String, Object> map1 = new HashMap<>();
  151. feesId.add(fees.getfFeeid());
  152. // 查询主表
  153. TWarehouseBills tWarehousebills = tWarehouseBillsMapper.selectTWarehousebillsById(fees.getfSrcpid());
  154. if (Objects.isNull(tWarehousebills)) {
  155. throw new WarehouseException("未找到仓储信息");
  156. }
  157. // 费用名称
  158. TFees tFees = tFeesMapper.selectTFeesById(fees.getfFeeid());
  159. if (tFees != null) {
  160. feeName = tFees.getfName();
  161. }
  162. // 费用表数据
  163. TWarehousebillsfees tWarehousebillsfees = tWarehousebillsfeesMapper.selectTWarehousebillsfeesById(fees.getfSrcid());
  164. if (tWarehousebillsfees == null) {
  165. return AjaxResult.error("费用数据为空,请确认");
  166. }
  167. // 字典宝
  168. SysDictData sysDictData = new SysDictData();
  169. sysDictData.setDictType("data_unitfees");
  170. sysDictData.setDictValue(String.valueOf(tWarehousebillsfees.getfFeeunitid()));
  171. sysDictData.setStatus("0");
  172. List<SysDictData> sysDictDataList = iSysDictDataService.selectDictDataList(sysDictData);
  173. List<SysDictData> sysDictDataListIn = new ArrayList<>();
  174. if (StringUtils.isNotEmpty(tWarehousebillsfees.getfBilltype()) && tWarehousebillsfees.getfBilltype().equals("SJRK")) {
  175. sysDictData.setDictType(ST_IN_TYPE);
  176. sysDictData.setDictValue(String.valueOf(tWarehousebillsfees.getfBusinessType()));
  177. sysDictData.setStatus("0");
  178. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  179. } else if (StringUtils.isNotEmpty(tWarehousebillsfees.getfBilltype()) && tWarehousebillsfees.getfBilltype().equals("SJCK")) {
  180. sysDictData.setDictType(ST_OUT_TYPE);
  181. sysDictData.setDictValue(String.valueOf(tWarehousebillsfees.getfBusinessType()));
  182. sysDictData.setStatus("0");
  183. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  184. } else if (StringUtils.isNotEmpty(tWarehousebillsfees.getfBilltype()) && tWarehousebillsfees.getfBilltype().equals("CKDB") | tWarehousebillsfees.getfBilltype().equals("HWTG")) {
  185. sysDictData.setDictType(ST_TRANS_TYPE);
  186. sysDictData.setDictValue(String.valueOf(tWarehousebillsfees.getfBusinessType()));
  187. sysDictData.setStatus("0");
  188. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  189. }
  190. // 之前遗留汉字特别处理
  191. FeesTypeEnum feesTypeEnum;
  192. if (fees.getfSrcdc().equals("收")) {
  193. feesTypeEnum = FeesTypeEnum.D;
  194. } else if (fees.getfSrcdc().equals("付")) {
  195. feesTypeEnum = FeesTypeEnum.C;
  196. } else {
  197. feesTypeEnum = FeesTypeEnum.fromType(fees.getfSrcdc());
  198. }
  199. map1.put("fSrcdcName", feesTypeEnum.getName());
  200. map1.put("fId", fees.getfId());
  201. map1.put("fSrcid", fees.getfSrcid());
  202. map1.put("fSrcpid", fees.getfSrcpid());
  203. map1.put("fMblno", tWarehousebillsfees.getfMblno());
  204. map1.put("fBscorpno", tWarehousebills.getfBscorpno());
  205. map1.put("fProductName", tWarehousebillsfees.getfProductName());
  206. map1.put("fBsdate", tWarehousebillsfees.getfBsdate());
  207. map1.put("fFeeid", fees.getfFeeid());
  208. map1.put("fFeeName", feeName);
  209. map1.put("fSrcdc", fees.getfSrcdc());
  210. map1.put("fAmt", fees.getfAmt());
  211. map1.put("fAmtdr", fees.getfAmtdr());
  212. map1.put("fRemarks", fees.getfRemarks());
  213. map1.put("srcBillNo", tWarehousebillsfees.getSrcId());
  214. map1.put("fMarks", tWarehousebillsfees.getfMarks());
  215. map1.put("fChargedate", tWarehousebillsfees.getfChargedate());
  216. map1.put("fBillingDeadline", tWarehousebillsfees.getfBillingDeadline());
  217. map1.put("fBillingDays", tWarehousebillsfees.getfBillingDays());
  218. map1.put("fInventoryDays", tWarehousebillsfees.getfInventoryDays());
  219. map1.put("fFeeunitid", sysDictDataList.get(0).getDictLabel());
  220. map1.put("fQty", tWarehousebillsfees.getfQty());
  221. map1.put("fUnitprice", tWarehousebillsfees.getfUnitprice());
  222. map1.put("fBillno",fees.getfSrcBillno());// 业务编号(单据编号)
  223. map1.put("invoiceNo",fees.getfInvoiceNo());// 发票号
  224. map1.put("fTaxrate",tWarehousebillsfees.getfTaxrateStr());// 税率--传递字符串数据
  225. if (StringUtils.isNotEmpty(tWarehousebillsfees.getfBilltype()) && tWarehousebillsfees.getfBilltype().equals("KHDD")) {
  226. map1.put("fBusinessType", "船运订单");
  227. } else if (CollectionUtils.isNotEmpty(sysDictDataListIn)) {
  228. map1.put("fBusinessType", sysDictDataListIn.get(0).getDictLabel());
  229. }
  230. if (StringUtils.isNotEmpty(tWarehousebills.getfBilltype()) && tWarehousebills.getfBilltype().equals("SJRK")) {
  231. map1.put("fBilltype", "入库");
  232. } else if (StringUtils.isNotEmpty(tWarehousebills.getfBilltype()) && tWarehousebills.getfBilltype().equals("SJCK")) {
  233. map1.put("fBilltype", "出库");
  234. } else if (StringUtils.isNotEmpty(tWarehousebills.getfBilltype()) && tWarehousebills.getfBilltype().equals("CKDB")) {
  235. map1.put("fBilltype", "调拨");
  236. } else if (StringUtils.isNotEmpty(tWarehousebills.getfBilltype()) && tWarehousebills.getfBilltype().equals("HWTG")) {
  237. map1.put("fBilltype", "货物通关");
  238. } else if (StringUtils.isNotEmpty(tWarehousebills.getfBilltype()) && tWarehousebills.getfBilltype().equals("HQZY")) {
  239. map1.put("fBilltype", "货权转移");
  240. } else if (StringUtils.isNotEmpty(tWarehousebills.getfBilltype()) && tWarehousebills.getfBilltype().equals("KHDD")) {
  241. map1.put("fBilltype", "船运订单");
  242. }
  243. feeDoList.add(map1);
  244. }
  245. }
  246. List<TCorps> corpsList = new ArrayList<>();
  247. List<Long> corpsIdList = StringUtils.integerDeduplication(corpsId);
  248. for (Long corpId : corpsIdList) {
  249. TCorps corps = tCorpsMapper.selectTCorpsById(corpId);
  250. if (StringUtils.isNotNull(corps)) {
  251. corpsList.add(corps);
  252. }
  253. }
  254. List<TFees> feesList = new ArrayList<>();
  255. List<Long> longList = StringUtils.integerDeduplication(feesId);
  256. for (Long fees : longList) {
  257. TFees tFees = tFeesMapper.selectTFeesById(fees);
  258. if (StringUtils.isNotNull(tFees)) {
  259. feesList.add(tFees);
  260. }
  261. }
  262. map.put("tFee", tFee);
  263. map.put("corps", corpsList);
  264. map.put("feesList", feesList);
  265. map.put("feeDoList", feeDoList);
  266. return map;
  267. }
  268. @Override
  269. public Map<String, Object> selectTFeeByIdNew(Long fId) {
  270. Map<String, Object> map = new HashMap<>();
  271. TFee tFee = tFeeMapper.selectTFeeByIdNew(fId);
  272. List<TFeeDo> feeDoList = tFeeDoMapper.selectTFeeDoByfPid(fId);
  273. TFeeInvoice tFeeInvoice = new TFeeInvoice();
  274. tFeeInvoice.setfPid(fId);
  275. List<TFeeInvoice> tFeeInvoiceList = tFeeInvoiceMapper.selectTFeeInvoiceList(tFeeInvoice);
  276. map.put("tFee", tFee);
  277. map.put("feeDoList", feeDoList);
  278. map.put("tFeeInvoiceList", tFeeInvoiceList);
  279. return map;
  280. }
  281. /**
  282. * 查询财务数据主列表
  283. *
  284. * @param tFee 财务数据主
  285. * @return 财务数据主
  286. */
  287. @Override
  288. public List<TFee> selectTFeeList(TFee tFee) {
  289. List<TFee> list = tFeeMapper.selectTFeeList(tFee);
  290. for (TFee tf : list) {
  291. List<TFeeDo> fd = tFeeDoMapper.selectTFeeDoByfPid(tf.getfId());
  292. StringBuilder strb = new StringBuilder();
  293. for (TFeeDo tFeeDo : fd) {
  294. if (StringUtils.isNotNull(tFeeDo.getfSrcBillno())) {
  295. strb.append(tFeeDo.getfSrcBillno()).append(",");
  296. }
  297. }
  298. tf.setfSrcBillno(StringUtils.objToStr(StringUtils.removeTheLastComma(strb)));
  299. }
  300. return list;
  301. }
  302. @Override
  303. public List<Map<String, Object>> selectTFeeList1(TFee tFee) {
  304. List<Map<String,Object>> list = tFeeMapper.selectTFeeList1(tFee);
  305. for (Map<String,Object> map : list) {
  306. List<TFeeDo> tfd = tFeeDoMapper.selectTFeeDoByfPid(Long.valueOf(map.get("fId").toString()));
  307. if (tfd.size()!=0) {
  308. StringBuilder stringBuilder = new StringBuilder();
  309. for (TFeeDo tFeeDo : tfd) {
  310. if (StringUtils.isNotNull(tFeeDo.getfSrcBillno())) {
  311. stringBuilder.append(tFeeDo.getfSrcBillno()).append(",");
  312. }
  313. }
  314. map.put("fSrcBillno",StringUtils.removeTheLastComma(stringBuilder));
  315. }
  316. }
  317. return list;
  318. }
  319. @Override
  320. public List<Map<String, Object>> webVersionTFee(TFee tFee) {
  321. return tFeeMapper.webVersionTFee(tFee);
  322. }
  323. @Override
  324. public List<Map<String, Object>> webVersionDetail(TAccount tAccount) {
  325. return tWarehousebillsfeesMapper.webVersionDetail(tAccount);
  326. }
  327. @Override
  328. public List<Map<String, Object>> webVersionInvoice(TFee tFee) {
  329. return tFeeMapper.webVersionInvoice(tFee);
  330. }
  331. @Override
  332. public List<Map<String, Object>> webVersionInvoiceDetail(TFee tFee) {
  333. List<Map<String, Object>> list = tFeeMapper.webVersionInvoice(tFee);
  334. if (CollectionUtils.isNotEmpty(list)) {
  335. for (Map<String, Object> map : list) {
  336. Long fId = Long.valueOf(map.get("fId").toString());
  337. List<TFeeDo> tFeeDos = tFeeDoMapper.selectTFeeDoByfPid(fId);
  338. map.put("tFeeDoList", tFeeDos);
  339. TFeeInvoice tFeeInvoice = new TFeeInvoice();
  340. tFeeInvoice.setfPid(fId);
  341. List<TFeeInvoice> tFeeInvoiceList = tFeeInvoiceMapper.selectTFeeInvoiceList(tFeeInvoice);
  342. map.put("tFeeInvoiceList", tFeeInvoiceList);
  343. }
  344. }
  345. return list;
  346. }
  347. @Override
  348. public List<Map<String, Object>> webVersionList(TAccount tAccount) {
  349. return tWarehousebillsfeesMapper.webVersionReconciliation(tAccount);
  350. }
  351. /**
  352. * 新增财务数据主
  353. *
  354. * @param tFee 财务数据主
  355. * @return 结果
  356. */
  357. @Override
  358. public int insertTFee(TFee tFee) {
  359. tFee.setCreateTime(DateUtils.getNowDate());
  360. return tFeeMapper.insertTFee(tFee);
  361. }
  362. /**
  363. * 新增对账 、收费、
  364. *
  365. * @param tfee
  366. * @param tfeeDo
  367. * @param loginUser
  368. * @param fBilltype
  369. * @return
  370. */
  371. @Override
  372. @Transactional
  373. public AjaxResult insertTFeeTFeeDo(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  374. Long fPid = null;
  375. Map<String, Object> map = new HashMap<>();
  376. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  377. if (StringUtils.isNull(tFee.getfId())) {
  378. // 如果是新数据
  379. tFee.setCreateBy(loginUser.getUser().getUserName());
  380. tFee.setCreateTime(new Date());
  381. tFee.setfDeptid(loginUser.getUser().getDeptId());
  382. tFee.setfBilltype(fBilltype);
  383. // 业务编码
  384. Date time = new Date();
  385. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  386. tFee.setfBillno(billNo);
  387. tFee.setSrcBillNo(billNo);
  388. tFee.setfBillstatus("2");
  389. tFeeMapper.insertTFee(tFee);
  390. fPid = tFee.getfId();
  391. } else {
  392. fPid = tFee.getfId();
  393. tFee.setUpdateBy(loginUser.getUser().getUserName());
  394. tFee.setUpdateTime(new Date());
  395. tFeeMapper.updateTFee(tFee);
  396. tFee = tFeeMapper.selectTFeeById(fPid);
  397. tFee.setSrcBillNo(tFee.getfBillno());
  398. // 删除从表
  399. tFeeDoMapper.deleteByFPid(fPid);
  400. }
  401. // 财务从表
  402. if (StringUtils.isNotNull(tfeeDo)) {
  403. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  404. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  405. for (TFeeDo tFeeDo : tFeeDoList) {
  406. tFeeDo.setfPid(fPid);
  407. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  408. tFeeDo.setCreateTime(new Date());
  409. tFeeDo.setfSrcBillno(tFeeDo.getfBillno());
  410. tFeeDo.setfStatus("2");
  411. tFeeDoMapper.insertTFeeDo(tFeeDo);
  412. }
  413. }
  414. List<FinancialTFeeDoExcel> list = tFeeDoMapper.selectFinancialTFeeDo(fPid);
  415. map.put("tFee", tFee);
  416. map.put("tFeeDo", list);
  417. return AjaxResult.success("成功", map);
  418. }
  419. @Override
  420. public AjaxResult insertWebVersion(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  421. Long fPid = null;
  422. Map<String, Object> map = new HashMap<>();
  423. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  424. if (StringUtils.isNull(tFee.getfId())) {
  425. // 如果是新数据
  426. tFee.setCreateBy(loginUser.getUser().getUserName());
  427. tFee.setCreateTime(new Date());
  428. tFee.setfDeptid(loginUser.getUser().getDeptId());
  429. tFee.setfBilltype(fBilltype);
  430. // 业务编码
  431. Date time = new Date();
  432. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  433. tFee.setfBillno(billNo);
  434. tFee.setfBillstatus("2");
  435. tFee.setfAccbilldate(new Date());
  436. tFeeMapper.insertTFee(tFee);
  437. fPid = tFee.getfId();
  438. } else {
  439. fPid = tFee.getfId();
  440. tFee.setUpdateBy(loginUser.getUser().getUserName());
  441. tFee.setUpdateTime(new Date());
  442. tFeeMapper.updateTFee(tFee);
  443. // 删除从表
  444. tFeeDoMapper.deleteByFPid(fPid);
  445. }
  446. // 财务从表
  447. if (StringUtils.isNotNull(tfeeDo)) {
  448. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  449. List<TAccount> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TAccount.class);
  450. for (TAccount tAccount : tFeeDoList) {
  451. TFeeDo tFeeDo = new TFeeDo();
  452. tFeeDo.setfSrcid(tAccount.getfSrcid());
  453. tFeeDo.setfSrcpid(tAccount.getfSrcpid());
  454. tFeeDo.setfPid(fPid);
  455. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  456. tFeeDo.setCreateTime(new Date());
  457. tFeeDo.setfStatus("2");
  458. tFeeDo.setfSrcdc("D");
  459. tFeeDo.setfAmtdr(tAccount.getfAmtdr());
  460. tFeeDo.setfAmt(tAccount.getfAmt());
  461. tFeeDo.setfFeeid(tAccount.getfFeeid());
  462. tFeeDoMapper.insertTFeeDo(tFeeDo);
  463. }
  464. }
  465. map.put("tFee", tFee);
  466. return AjaxResult.success("成功", map);
  467. }
  468. /**
  469. * 新增对账 、收费、
  470. *
  471. * @param tfee
  472. * @param tfeeDo
  473. * @param loginUser
  474. * @param fBilltype
  475. * @return
  476. */
  477. @Override
  478. @Transactional
  479. public AjaxResult insertKHTFeeTFeeDo(String tfee, String tfeeDo, String tFeeInvoice, LoginUser loginUser, String fBilltype) {
  480. Long fPid = null;
  481. Map<String, Object> map = new HashMap<>();
  482. String billStatus = "2";
  483. if (fBilltype.equals("INV")) {
  484. billStatus = "6";
  485. }
  486. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  487. if (StringUtils.isNull(tFee.getfId())) {
  488. // 如果是新数据
  489. tFee.setCreateBy(loginUser.getUser().getUserName());
  490. tFee.setCreateTime(new Date());
  491. tFee.setfDeptid(loginUser.getUser().getDeptId());
  492. tFee.setfBilltype(fBilltype);
  493. // 业务编码
  494. Date time = new Date();
  495. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  496. tFee.setfBillno(billNo);
  497. tFee.setfBillstatus(billStatus);
  498. tFeeMapper.insertTFee(tFee);
  499. fPid = tFee.getfId();
  500. } else {
  501. fPid = tFee.getfId();
  502. boolean change = this.change(fPid);
  503. if (!change && !"INV".equals(fBilltype)) {
  504. return AjaxResult.error("当前数据不支持修改");
  505. }
  506. tFee.setUpdateBy(loginUser.getUser().getUserName());
  507. tFee.setUpdateTime(new Date());
  508. tFeeMapper.updateTFee(tFee);
  509. // 删除从表
  510. tFeeDoMapper.deleteByFPid(fPid);
  511. tFeeInvoiceMapper.deleteByFPid(fPid);
  512. }
  513. // 财务从表
  514. if (StringUtils.isNotNull(tfeeDo)) {
  515. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  516. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  517. for (TFeeDo tFeeDo : tFeeDoList) {
  518. tFeeDo.setfPid(fPid);
  519. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  520. tFeeDo.setCreateTime(new Date());
  521. tFeeDo.setfStatus(billStatus);
  522. tFeeDoMapper.insertTFeeDo(tFeeDo);
  523. }
  524. }
  525. if (!"".equals(tFeeInvoice) && tFeeInvoice != null && !"null".equals(tFeeInvoice)) {
  526. JSONArray jsonDrArray = JSONArray.parseArray(tFeeInvoice);
  527. List<TFeeInvoice> tFeeInvoiceList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeInvoice.class);
  528. for (TFeeInvoice feeInvoice : tFeeInvoiceList) {
  529. feeInvoice.setfPid(fPid);
  530. feeInvoice.setCreateBy(loginUser.getUser().getUserName());
  531. feeInvoice.setCreateTime(new Date());
  532. feeInvoice.setfBillstatus(billStatus);
  533. tFeeInvoiceMapper.insertTFeeInvoice(feeInvoice);
  534. }
  535. }
  536. map.put("tFee", tFee);
  537. return AjaxResult.success("成功", map);
  538. }
  539. /**
  540. * 修改财务数据主
  541. *
  542. * @param tFee 财务数据主
  543. * @return 结果
  544. */
  545. @Override
  546. public int updateTFee(TFee tFee) {
  547. tFee.setUpdateTime(DateUtils.getNowDate());
  548. return tFeeMapper.updateTFee(tFee);
  549. }
  550. /**
  551. * 批量删除财务数据主
  552. *
  553. * @param fIds 需要删除的财务数据主ID
  554. * @return 结果
  555. */
  556. @Override
  557. @Transactional
  558. public AjaxResult deleteWebVersionByIds(Long[] fIds) {
  559. // 取出业务编号、 放入 billno_del
  560. for (Long id : fIds) {
  561. // 1、查询主表信息
  562. TFee tFee = tFeeMapper.selectTFeeById(id);
  563. boolean change = this.change(id);
  564. if (change == false) {
  565. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  566. return AjaxResult.error("数据正在审批或审批通过,不允许删除");
  567. }
  568. // 2、业务编号、客存编号 放入 billno_del
  569. BillnoDel billnoDel = new BillnoDel();
  570. billnoDel.setBillType(tFee.getfBilltype());
  571. billnoDel.setBillNo(tFee.getfBillno());
  572. billnoDelMapper.insertBillnoDel(billnoDel);
  573. if (tFee.getfAccountId() != null) {
  574. TFee fee = tFeeMapper.selectTFeeById(tFee.getfAccountId());
  575. fee.setfMake(0);
  576. int updateTFee = tFeeMapper.updateTFee(fee);
  577. }
  578. }
  579. int i = tFeeMapper.deleteTFeeByIds(fIds);
  580. if (i <= 0) {
  581. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  582. return AjaxResult.error("删除发票申请失败,请找管理员");
  583. }
  584. return AjaxResult.success();
  585. }
  586. @Override
  587. public int deleteTFeeByIds(Long[] fIds) {
  588. // 取出业务编号、 放入 billno_del
  589. for (Long id : fIds) {
  590. // 1、查询主表信息
  591. TFee tFee = tFeeMapper.selectTFeeById(id);
  592. // 2、业务编号、客存编号 放入 billno_del
  593. BillnoDel billnoDel = new BillnoDel();
  594. billnoDel.setBillType(tFee.getfBilltype());
  595. billnoDel.setBillNo(tFee.getfBillno());
  596. billnoDelMapper.insertBillnoDel(billnoDel);
  597. if (tFee.getfAccountId() != null) {
  598. TFee fee = tFeeMapper.selectTFeeById(tFee.getfAccountId());
  599. fee.setfMake(0);
  600. tFeeMapper.updateTFee(fee);
  601. }
  602. }
  603. return tFeeMapper.deleteTFeeByIds(fIds);
  604. }
  605. /**
  606. * 删除财务数据主信息
  607. *
  608. * @param fId 财务数据主ID
  609. * @return 结果
  610. */
  611. @Override
  612. public int deleteTFeeById(Long fId) {
  613. return tFeeMapper.deleteTFeeById(fId);
  614. }
  615. @Override
  616. public List<Map<String, Object>> warehouseBillsFeesList(TWareHouseFees tWareHouseFees, String billsType) {
  617. Map<String, Object> map = new HashMap<>();
  618. map.put("tWareHouseFees", tWareHouseFees);
  619. List<Map<String, Object>> mapList;
  620. if (billsType.equals("DZ") || billsType.equals("KHDZ")) {
  621. mapList = tFeeMapper.warehouseBillsFeesListAccamount(map);
  622. updateBillTypeName(mapList, tWareHouseFees.getfBilltype());
  623. return mapList;
  624. } else if (billsType.equals("invoiceFP")) {
  625. mapList = tFeeMapper.warehouseInvoiceFPFeesList(map);
  626. return mapList;
  627. } else if (billsType.equals("ApplyFP")) {
  628. mapList = tFeeMapper.warehouseApplyFPFeesList(map);
  629. return mapList;
  630. } else if (FeesTypeEnum.INVOICE.getType().equals(billsType)) {
  631. // 查询发票
  632. mapList = tFeeMapper.queryApplyInvoiceFeesList(map);
  633. return mapList;
  634. } else {
  635. mapList = tFeeMapper.warehouseBillsFeesList(map);
  636. updateBillTypeName(mapList, tWareHouseFees.getfBilltype());
  637. return mapList;
  638. }
  639. }
  640. /**
  641. * 根据传入业务类型判断传入对应值
  642. *
  643. * @param mapList
  644. * @param type
  645. */
  646. private void updateBillTypeName(List<Map<String, Object>> mapList, String type) {
  647. if (CollectionUtils.isNotEmpty(mapList)) {
  648. List<String> typeList = Lists.newArrayList();
  649. typeList.add(ST_IN_TYPE);
  650. typeList.add(ST_OUT_TYPE);
  651. typeList.add(ST_TRANS_TYPE);
  652. List<SysDictData> sysDictDataList = sysDictDataMapper.selectByTypes(typeList);
  653. // 遍历map
  654. for (Map<String, Object> map : mapList) {
  655. // 如果类型为入库
  656. if (StringUtils.isEmpty(type) && Objects.nonNull(map.get("fBusinessType"))) {
  657. String fBusinessType = map.get("fBusinessType").toString();
  658. String dictLabel = sysDictDataList.stream().filter(li -> Objects.equals(li.getDictValue(), fBusinessType))
  659. .map(SysDictData::getDictLabel).findFirst().orElseThrow(() -> new WarehouseException("缺少字典表信息"));
  660. map.put("fBusinessType", dictLabel);
  661. } else if (StringUtils.isNotEmpty(type) && type.equals(WarehouseTypeEnum.SJRK.getType()) && Objects.nonNull(map.get("fBusinessType"))) {
  662. String dictLabel = DictUtils.getDictLabel(ST_IN_TYPE, map.get("fBusinessType").toString());
  663. if (StringUtils.isNotEmpty(dictLabel)) {
  664. map.put("fBusinessType", dictLabel);
  665. }
  666. } else if (StringUtils.isNotEmpty(type) && type.equals(WarehouseTypeEnum.SJCK.getType()) && Objects.nonNull(map.get("fBusinessType"))) {
  667. String dictLabel = DictUtils.getDictLabel(ST_OUT_TYPE, map.get("fBusinessType").toString());
  668. if (StringUtils.isNotEmpty(dictLabel)) {
  669. map.put("fBusinessType", dictLabel);
  670. }
  671. } else if (StringUtils.isNotEmpty(type) && type.equals(WarehouseTypeEnum.HQZY.getType()) && Objects.nonNull(map.get("fBusinessType"))) {
  672. String dictLabel = DictUtils.getDictLabel(ST_TRANS_TYPE, map.get("fBusinessType").toString());
  673. if (StringUtils.isNotEmpty(dictLabel)) {
  674. map.put("fBusinessType", dictLabel);
  675. }
  676. }
  677. }
  678. }
  679. }
  680. @Override
  681. public List<FeeVO> warehouseBillsFeesList(TWareHouseFees tWareHouseFees) {
  682. if (tWareHouseFees.getSwitchSection() == 1) {
  683. tWareHouseFees.setTimeExamine(tWareHouseFees.getTimeExamine());
  684. } else {
  685. tWareHouseFees.setfBstimeExamine(tWareHouseFees.getTimeExamine());
  686. }
  687. return tFeeMapper.selectFinancialLedgerList(tWareHouseFees);
  688. }
  689. @Override
  690. public List<Map<String, Object>> warehouseBillsFeesProfitList(TWareHouseFees tWareHouseFees) {
  691. if (tWareHouseFees.getGroupBy() == 0) {
  692. return tFeeMapper.warehouseBillsFeesProfitList(tWareHouseFees);
  693. }
  694. if (tWareHouseFees.getSwitchSection() == 1) {
  695. tWareHouseFees.setTimeExamine(tWareHouseFees.getTimeExamine());
  696. } else {
  697. tWareHouseFees.setfBstimeExamine(tWareHouseFees.getTimeExamine());
  698. }
  699. return tFeeMapper.warehouseBillsFeesCustomProfitList(tWareHouseFees);
  700. }
  701. public static BigDecimal calculation1(String fTotalgross, String fGrossweightblc) {
  702. BigDecimal num1 = new BigDecimal(fTotalgross);
  703. BigDecimal num2 = new BigDecimal(fGrossweightblc);
  704. BigDecimal result = num1.subtract(num2);
  705. return result.setScale(2, BigDecimal.ROUND_HALF_UP);
  706. }
  707. @Override
  708. @Transactional
  709. public AjaxResult confirm(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  710. String key = "";
  711. boolean isApprove = false;
  712. Map<String, Object> messageMap = new HashMap<>();
  713. long actId = 0L;
  714. if (!fBilltype.equals(FeesTypeEnum.INVOICE.getType())) {
  715. if ("DZ".equals(fBilltype)) {
  716. actId = 210L;
  717. key = "warehouse.contrast.ApprovalFlow";
  718. } else if ("SF".equals(fBilltype)) {
  719. actId = 220L;
  720. key = "warehouse.charge.ApprovalFlow";
  721. } else if ("FF".equals(fBilltype)) {
  722. actId = 230L;
  723. key = "warehouse.payment.ApprovalFlow";
  724. } else if ("KHDZ".equals(fBilltype)) {
  725. actId = 430L;
  726. key = "warehouse.kaiHeContrast.ApprovalFlow";
  727. } else if ("KHSF".equals(fBilltype)) {
  728. actId = 440L;
  729. key = "warehouse.kaiHeCharge.ApprovalFlow";
  730. } else if ("KHFF".equals(fBilltype)) {
  731. actId = 450L;
  732. key = "warehouse.kaiHePayment.ApprovalFlow";
  733. }
  734. SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique(key);
  735. if (StringUtils.isNull(sysConfig)) {
  736. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  737. return AjaxResult.error("系统参数异常,未找到开启审批流参数");
  738. }
  739. if ("0".equals(sysConfig.getConfigValue())) {
  740. isApprove = true;
  741. }
  742. }
  743. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  744. String billstatus = "";
  745. if (isApprove) {
  746. billstatus = "4";
  747. } else {
  748. billstatus = "6";
  749. }
  750. if (StringUtils.isNull(tFee.getfId())) {
  751. // 如果是新数据
  752. tFee.setCreateBy(loginUser.getUser().getUserName());
  753. tFee.setfDeptid(loginUser.getUser().getDeptId());
  754. tFee.setfBilltype(fBilltype);
  755. tFee.setfBillstatus(billstatus);
  756. // 业务编码
  757. Date time = new Date();
  758. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  759. tFee.setfBillno(billNo);
  760. tFeeMapper.insertTFee(tFee);
  761. } else {
  762. tFee.setUpdateBy(loginUser.getUser().getUserName());
  763. tFee.setUpdateTime(new Date());
  764. tFee.setfBillstatus(billstatus);
  765. tFeeMapper.updateTFee(tFee);
  766. }
  767. // 删除从表
  768. tFeeDoMapper.deleteByFPid(tFee.getfId());
  769. messageMap.put("tFee", tFee);
  770. // 声明业务编号 list
  771. List<String> fSrcBillnos = new ArrayList<>();
  772. // 财务从表
  773. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  774. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  775. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  776. for (TFeeDo tFeeDo : tFeeDoList) {
  777. Map<String, Object> map = this.judgeMoney(tFeeDo.getfSrcid(), tFeeDo.getfAmt(), fBilltype, tFeeDo.getfFeeid());
  778. if (!(Boolean) map.get("flag")) {
  779. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  780. return AjaxResult.error(map.get("message").toString());
  781. }
  782. tFeeDo.setfPid(tFee.getfId());
  783. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  784. tFeeDo.setCreateTime(new Date());
  785. tFeeDo.setfStatus(billstatus);
  786. tFeeDo.setfSrcBillno(tFeeDo.getfBillno());
  787. if (StringUtils.isNotNull(tFeeDo.getfBillno())) {
  788. // 装载业务编号
  789. fSrcBillnos.add(tFeeDo.getfBillno());
  790. }
  791. tFeeDoMapper.insertTFeeDo(tFeeDo);
  792. }
  793. }
  794. // 点击对账、收费、付费提交审核时去掉费用
  795. if (actId >= 210L && actId <= 230L) {
  796. AjaxResult ajaxResult = this.billsfeesFollow(tFee.getfId());
  797. String code = ajaxResult.get("code").toString();
  798. if ("500".equals(code)) {
  799. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  800. return ajaxResult;
  801. }
  802. }
  803. //凯和收费提交审核时去掉钱
  804. if (actId >= 430 && actId <= 450){
  805. //判断明细客户是否为同一个
  806. List<TFeeDo> list = tFeeDoMapper.selectTFeeDoByfPid(tFee.getfId());
  807. if (CollectionUtils.isNotEmpty(list)){
  808. List<Long> collect = list.stream().filter(e -> e.getfSrcid() != null).map(TFeeDo::getfSrcid).collect(toList());
  809. if (CollectionUtils.isNotEmpty(collect)){
  810. List<Long> corpid = tWarehousebillsfeesMapper.getCorpid(collect);
  811. if (CollectionUtils.isNotEmpty(corpid)){
  812. List<Long> longs = corpid.stream().distinct().collect(toList());
  813. if (CollectionUtils.isNotEmpty(longs) && longs.size() >1){
  814. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  815. return AjaxResult.error("费用明细的客户非同一个客户");
  816. }
  817. }
  818. }
  819. }
  820. AjaxResult ajaxResult = this.billsfeesFollow(tFee.getfId());
  821. String code = ajaxResult.get("code").toString();
  822. if ("500".equals(code)) {
  823. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  824. return ajaxResult;
  825. }
  826. }
  827. // 这里加个判断取系统参数来确定是否需要启用审批流
  828. BigDecimal amount = BigDecimal.ZERO;//财务对账金额
  829. //获取账单明细
  830. List<TFeeDo> list = tFeeDoMapper.selectTFeeDoByfPid(tFee.getfId());
  831. if (CollectionUtils.isNotEmpty(list)){
  832. amount = list.stream().filter(e -> e.getfAmt() != null).map(TFeeDo::getfAmt).reduce(BigDecimal.ZERO, BigDecimal::add);
  833. }
  834. if (isApprove) {
  835. AuditItems auditItems = new AuditItems();
  836. auditItems.setLevelId(0L);
  837. auditItems.setBillId(tFee.getfId());
  838. auditItems.setActId(actId);
  839. auditItems.setIffinalItem("F");
  840. auditItems.setBillNo(tFee.getfBillno()); // 业务编号
  841. auditItems.setRefno1(String.valueOf(tFee.getfCorpid())); // 货权方
  842. auditItems.setRefno2(fBilltype);// 财务类型
  843. auditItems.setRefno3(tFee.gettMblno());// 提单号
  844. auditItems.setSendUserId(loginUser.getUser().getUserId()); // 请核人 ID
  845. auditItems.setSendName(loginUser.getUsername()); // 请核人名称
  846. auditItems.setSendTime(new Date()); // 请核时间
  847. auditItems.setAuditUserId(loginUser.getUser().getUserId());// 审核人 ID
  848. auditItems.setAuditItem(new Date());// 审核通过时间
  849. auditItems.setAuditOpTime(new Date());// 审核时间
  850. auditItems.setFidStatus("f_billstatus");// 存储对应审批字段
  851. auditItems.setTimes(1L);// 第几次提交审批
  852. auditItems.setAuditMsg("提交");
  853. auditItems.setAuditStatus("O");// 提交状态
  854. auditItems.setfSrcBillnos(fSrcBillnos);// 装载业务编号数据(来源单据编号)
  855. auditItems.setAmount(amount);//对账金额
  856. AjaxResult approvalFlow = auditItemsService.createApprovalFlow(auditItems);// 生成审批流
  857. Long code = Long.valueOf(String.valueOf(approvalFlow.get("code"))).longValue();
  858. if (code.equals(500L)) {
  859. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  860. return AjaxResult.error("发票申请提交审核失败,请找管理员");
  861. }
  862. } else {
  863. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  864. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  865. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  866. for (TFeeDo tFeeDo : tFeeDoList) {
  867. // 跟新费用明细
  868. int m = updateBillsFees(tFee.getfId(), tFeeDo, fBilltype);
  869. if (m == 0) {
  870. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  871. return AjaxResult.error("更新费用明细失败");
  872. }
  873. }
  874. }
  875. AjaxResult ajaxResult = tfeeFollow(tFee.getfId(), 6L);
  876. Long code = Long.valueOf(String.valueOf(ajaxResult.get("code"))).longValue();
  877. if (code.equals(500L)) {
  878. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  879. return AjaxResult.error("发票申请提交审核失败,请找管理员");
  880. }
  881. //凯和系统 修改订单的实收实付费用
  882. if ("KHSF".equals(fBilltype) || "KHFF".equals(fBilltype)){
  883. this.updateMessage(tFee.getfId());
  884. }
  885. }
  886. return AjaxResult.success("成功", messageMap);
  887. }
  888. @Override
  889. @Transactional
  890. public AjaxResult webVersionConfirm(Long[] fIds, String billsType, LoginUser loginUser) {
  891. String key = "";
  892. boolean isApprove = false;
  893. long actId = 0L;
  894. if ("DZ".equals(billsType)) {
  895. actId = 210L;
  896. key = "warehouse.contrast.ApprovalFlow";
  897. } else if ("SF".equals(billsType)) {
  898. actId = 220L;
  899. key = "warehouse.charge.ApprovalFlow";
  900. } else if ("FF".equals(billsType)) {
  901. actId = 230L;
  902. key = "warehouse.payment.ApprovalFlow";
  903. } else if ("KHDZ".equals(billsType)) {
  904. actId = 430L;
  905. key = "warehouse.kaiHeContrast.ApprovalFlow";
  906. } else if ("KHSF".equals(billsType)) {
  907. actId = 440L;
  908. key = "warehouse.kaiHeCharge.ApprovalFlow";
  909. } else if ("KHFF".equals(billsType)) {
  910. actId = 450L;
  911. key = "warehouse.kaiHePayment.ApprovalFlow";
  912. }
  913. SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique(key);
  914. if (StringUtils.isNull(sysConfig)) {
  915. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  916. return AjaxResult.error("系统参数异常,未找到开启审批流参数");
  917. }
  918. if ("0".equals(sysConfig.getConfigValue())) {
  919. isApprove = true;
  920. }
  921. String billStatus = null;
  922. if (isApprove) {
  923. billStatus = "4";
  924. } else {
  925. billStatus = "6";
  926. }
  927. for (Long fId : fIds) {
  928. TFee tFee = tFeeMapper.selectTFeeById(fId);
  929. if (tFee == null) {
  930. return AjaxResult.error("对账数据有误请确认");
  931. }
  932. boolean change = this.change(tFee.getfId());
  933. if (change == false) {
  934. return AjaxResult.error("数据正在审批或审批通过,不允许提交审核");
  935. }
  936. //更新主表数据状态
  937. TFee fee = new TFee();
  938. fee.setfId(fId);
  939. fee.setfBillstatus(billStatus);
  940. int i = tFeeMapper.updateTFee(fee);
  941. //更新从表数据状态
  942. int update = tFeeDoMapper.tfeeDoFollowUpdate(fId, Long.valueOf(billStatus));
  943. if (isApprove) {
  944. AuditItems auditItems = new AuditItems();
  945. auditItems.setLevelId(0L);
  946. auditItems.setBillId(tFee.getfId());
  947. auditItems.setActId(actId);
  948. auditItems.setIffinalItem("F");
  949. auditItems.setBillNo(tFee.getfBillno()); // 业务编号
  950. auditItems.setRefno1(String.valueOf(tFee.getfCorpid())); // 货权方
  951. auditItems.setRefno2(billsType);// 财务类型
  952. auditItems.setRefno3(tFee.gettMblno());// 提单号
  953. auditItems.setSendUserId(loginUser.getUser().getUserId());
  954. auditItems.setSendName(loginUser.getUsername());
  955. auditItems.setSendTime(new Date());
  956. auditItems.setAuditUserId(loginUser.getUser().getUserId());
  957. auditItems.setAuditItem(new Date());
  958. auditItems.setAuditOpTime(new Date());
  959. auditItems.setFidStatus("f_billstatus");
  960. auditItems.setTimes(1L);
  961. auditItems.setAuditMsg("提交");
  962. auditItems.setAuditStatus("O");
  963. AjaxResult approvalFlow = auditItemsService.createApprovalFlow(auditItems);
  964. Long code = Long.valueOf(String.valueOf(approvalFlow.get("code"))).longValue();
  965. if (code.equals(500L)) {
  966. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  967. }
  968. return approvalFlow;
  969. } else {
  970. TFeeDo tFeeDo = new TFeeDo();
  971. tFeeDo.setfPid(fId);
  972. List<TFeeDo> tFeeDoList = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  973. for (TFeeDo feeDo : tFeeDoList) {
  974. // 跟新费用明细
  975. int m = updateBillsFees(fId, feeDo, billsType);
  976. if (m == 0) {
  977. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  978. return AjaxResult.error("更新费用明细失败");
  979. }
  980. }
  981. }
  982. AjaxResult ajaxResult = tfeeFollow(tFee.getfId(), 6L);
  983. Long code = Long.valueOf(String.valueOf(ajaxResult.get("code"))).longValue();
  984. return ajaxResult;
  985. }
  986. return AjaxResult.success();
  987. }
  988. @Override
  989. @Transactional
  990. public AjaxResult confirmKaiHe(String tfee, String tfeeDo, String tFeeInvoice, LoginUser loginUser, String fBilltype) {
  991. Long fPid = null;
  992. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  993. Map<String, Object> messageMap = new HashMap<>();
  994. String key = "";
  995. boolean isApprove = false;
  996. long actId = 0L;
  997. String billStatus = "";
  998. if ("DZ".equals(fBilltype)) {
  999. actId = 210L;
  1000. key = "warehouse.contrast.ApprovalFlow";
  1001. } else if ("SF".equals(fBilltype)) {
  1002. actId = 220L;
  1003. key = "warehouse.charge.ApprovalFlow";
  1004. } else if ("FF".equals(fBilltype)) {
  1005. actId = 230L;
  1006. key = "warehouse.payment.ApprovalFlow";
  1007. } else if ("KHDZ".equals(fBilltype)) {
  1008. actId = 430L;
  1009. key = "warehouse.kaiHeContrast.ApprovalFlow";
  1010. } else if ("KHSF".equals(fBilltype)) {
  1011. actId = 440L;
  1012. key = "warehouse.kaiHeCharge.ApprovalFlow";
  1013. } else if ("KHFF".equals(fBilltype)) {
  1014. actId = 450L;
  1015. key = "warehouse.kaiHePayment.ApprovalFlow";
  1016. } else if ("ApplyFP".equals(fBilltype)) {
  1017. actId = 470L;
  1018. key = "warehouse.kaiHeApplyFP.ApprovalFlow";
  1019. }
  1020. SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique(key);
  1021. if (StringUtils.isNull(sysConfig)) {
  1022. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1023. return AjaxResult.error("系统参数异常,未找到开启审批流参数");
  1024. }
  1025. if ("0".equals(sysConfig.getConfigValue())) {
  1026. isApprove = true;
  1027. }
  1028. if (isApprove) {
  1029. billStatus = "4";
  1030. } else {
  1031. billStatus = "6";
  1032. }
  1033. if (StringUtils.isNull(tFee.getfId())) {
  1034. // 如果是新数据
  1035. tFee.setCreateBy(loginUser.getUser().getUserName());
  1036. tFee.setfDeptid(loginUser.getUser().getDeptId());
  1037. tFee.setfBilltype(fBilltype);
  1038. // 业务编码
  1039. Date time = new Date();
  1040. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  1041. tFee.setfBillno(billNo);
  1042. tFee.setfBillstatus(billStatus);
  1043. tFeeMapper.insertTFee(tFee);
  1044. fPid = tFee.getfId();
  1045. } else {
  1046. fPid = tFee.getfId();
  1047. boolean change = this.change(fPid);
  1048. if (!change) {
  1049. return AjaxResult.error("当前数据不支持修改");
  1050. }
  1051. tFee.setUpdateBy(loginUser.getUser().getUserName());
  1052. tFee.setUpdateTime(new Date());
  1053. tFee.setfBillstatus(billStatus);
  1054. tFeeMapper.updateTFee(tFee);
  1055. // 删除从表
  1056. tFeeDoMapper.deleteByFPid(tFee.getfId());
  1057. //删除开票从表
  1058. tFeeInvoiceMapper.deleteByFPid(tFee.getfId());
  1059. }
  1060. messageMap.put("tFee", tFee);
  1061. // 财务从表
  1062. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  1063. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  1064. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  1065. for (TFeeDo tFeeDo : tFeeDoList) {
  1066. Map<String, Object> map = this.judgeMoney(tFeeDo.getfSrcid(), tFeeDo.getfAmt(), fBilltype, tFeeDo.getfFeeid());
  1067. boolean b = (Boolean) map.get("flag");
  1068. if (b == false) {
  1069. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1070. return AjaxResult.error(map.get("message").toString());
  1071. }
  1072. tFeeDo.setfPid(tFee.getfId());
  1073. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  1074. tFeeDo.setCreateTime(new Date());
  1075. tFeeDo.setfStatus(billStatus);
  1076. tFeeDoMapper.insertTFeeDo(tFeeDo);
  1077. }
  1078. }
  1079. if (!"".equals(tFeeInvoice) && tFeeInvoice != null && !"null".equals(tFeeInvoice)) {
  1080. JSONArray jsonDrArray = JSONArray.parseArray(tFeeInvoice);
  1081. List<TFeeInvoice> tFeeInvoiceList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeInvoice.class);
  1082. for (TFeeInvoice feeInvoice : tFeeInvoiceList) {
  1083. feeInvoice.setfPid(fPid);
  1084. feeInvoice.setCreateBy(loginUser.getUser().getUserName());
  1085. feeInvoice.setCreateTime(new Date());
  1086. feeInvoice.setfBillstatus(billStatus);
  1087. tFeeInvoiceMapper.insertTFeeInvoice(feeInvoice);
  1088. }
  1089. }
  1090. // 这里加个判断取系统参数来确定是否需要启用审批流
  1091. if (isApprove) {
  1092. AuditItems auditItems = new AuditItems();
  1093. auditItems.setLevelId(0L);
  1094. auditItems.setBillId(tFee.getfId());
  1095. auditItems.setActId(actId);
  1096. auditItems.setIffinalItem("F");
  1097. auditItems.setBillNo(tFee.getfBillno()); // 业务编号
  1098. auditItems.setRefno1(String.valueOf(tFee.getfCorpid())); // 货权方
  1099. auditItems.setRefno2(fBilltype);// 财务类型
  1100. auditItems.setRefno3(tFee.gettMblno());// 提单号
  1101. auditItems.setSendUserId(loginUser.getUser().getUserId());
  1102. auditItems.setSendName(loginUser.getUsername());
  1103. auditItems.setSendTime(new Date());
  1104. auditItems.setAuditUserId(loginUser.getUser().getUserId());
  1105. auditItems.setAuditItem(new Date());
  1106. auditItems.setAuditOpTime(new Date());
  1107. auditItems.setFidStatus("f_billstatus");
  1108. auditItems.setTimes(1L);
  1109. auditItems.setAuditMsg("提交");
  1110. auditItems.setAuditStatus("O");
  1111. AjaxResult approvalFlow = auditItemsService.createApprovalFlow(auditItems);
  1112. Long code = Long.valueOf(String.valueOf(approvalFlow.get("code"))).longValue();
  1113. if (code.equals(500L)) {
  1114. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1115. return AjaxResult.error("发票申请提交审核失败,请找管理员");
  1116. }
  1117. } else {
  1118. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  1119. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  1120. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  1121. for (TFeeDo tFeeDo : tFeeDoList) {
  1122. // 跟新费用明细
  1123. int m = updateBillsFees(tFee.getfId(), tFeeDo, fBilltype);
  1124. if (m == 0) {
  1125. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1126. return AjaxResult.error("更新费用明细失败");
  1127. }
  1128. }
  1129. }
  1130. AjaxResult ajaxResult = tfeeFollow(tFee.getfId(), 6L);
  1131. Long code = Long.valueOf(String.valueOf(ajaxResult.get("code"))).longValue();
  1132. if (code.equals(500L)) {
  1133. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1134. return AjaxResult.error("发票申请提交审核失败,请找管理员");
  1135. }
  1136. }
  1137. return AjaxResult.success("成功", messageMap);
  1138. }
  1139. /**
  1140. * 根据财务主表id 更新对应明细表状态
  1141. *
  1142. * @param fPid 财务主表id
  1143. * @return 结果
  1144. */
  1145. @Transactional
  1146. public AjaxResult tfeeFollow(Long fPid, long fettle) {
  1147. if (StringUtils.isNull(fPid)) {
  1148. return AjaxResult.error("财务更新状态未找到主表信息,请与管理员联系");
  1149. }
  1150. TFee tFee = new TFee();
  1151. tFee.setfId(fPid);
  1152. tFee.setfBillstatus(String.valueOf(fettle));
  1153. int tFeeUpdateResult = tFeeMapper.updateTFee(tFee);
  1154. if (tFeeUpdateResult <= 0) {
  1155. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1156. return AjaxResult.error("更新财务明细状态失败,请联系管理员");
  1157. }
  1158. try {
  1159. int itemUpdateResult = tFeeDoMapper.tfeeDoFollowUpdate(fPid, fettle);
  1160. } catch (Exception exception) {
  1161. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1162. return AjaxResult.error("更新财务明细状态失败,请联系管理员");
  1163. }
  1164. TFeeInvoice invoice = new TFeeInvoice();
  1165. invoice.setfPid(fPid);
  1166. List<TFeeInvoice> tFeeInvoiceList = tFeeInvoiceMapper.selectTFeeInvoiceList(invoice);
  1167. if (CollectionUtils.isNotEmpty(tFeeInvoiceList)) {
  1168. try {
  1169. int itemUpdateResult = tFeeInvoiceMapper.tFeeInvoiceUpdate(fPid, fettle);
  1170. } catch (Exception exception) {
  1171. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1172. return AjaxResult.error("更新开票明细状态失败,请联系管理员");
  1173. }
  1174. }
  1175. return AjaxResult.success();
  1176. }
  1177. @Transactional
  1178. public synchronized AjaxResult billsfeesFollow(Long fPid) {
  1179. if (StringUtils.isNull(fPid)) {
  1180. return AjaxResult.error("费用明细更新状态未找到主表信息,请与管理员联系");
  1181. }
  1182. TFee tFee = tFeeMapper.selectTFeeById(fPid);
  1183. // 查询从表数据
  1184. TFeeDo tFeeDo = new TFeeDo();
  1185. tFeeDo.setfPid(fPid);
  1186. List<TFeeDo> tFeeDoList = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  1187. for (TFeeDo tFeeDo1 : tFeeDoList) {
  1188. // 跟新费用明细
  1189. Map<String, Object> map = this.judgeMoney(tFeeDo1.getfSrcid(), tFeeDo1.getfAmt(), tFee.getfBilltype(), tFeeDo1.getfFeeid());
  1190. if (!(Boolean) map.get("flag")) {
  1191. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1192. return AjaxResult.error(map.get("message").toString());
  1193. }
  1194. int m = updateBillsFees(fPid, tFeeDo1, tFee.getfBilltype());
  1195. if (m == 0) {
  1196. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1197. return AjaxResult.error("更新费用明细失败");
  1198. }
  1199. }
  1200. return AjaxResult.success();
  1201. }
  1202. /**
  1203. * 账单管理撤销对账、收费、付费
  1204. * @param fPid
  1205. * @param fBillType
  1206. * @return
  1207. */
  1208. @Transactional
  1209. public AjaxResult updateDSFMoney(Long fPid,String fBillType){
  1210. if (StringUtils.isNull(fPid)) {
  1211. return AjaxResult.error("费用明细更新状态未找到主表信息,请与管理员联系");
  1212. }
  1213. // 获取从表数据
  1214. TFeeDo tFeeDo = new TFeeDo();
  1215. tFeeDo.setfPid(fPid);
  1216. List<TFeeDo> tFeeDos = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  1217. for (TFeeDo tFeeDo1 : tFeeDos) {
  1218. int m = updateBillsFees(fPid, tFeeDo1, fBillType);
  1219. if (m == 0) {
  1220. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1221. return AjaxResult.error("更新费用明细失败");
  1222. }
  1223. }
  1224. return AjaxResult.success();
  1225. }
  1226. /**
  1227. * 凯和撤销收费 付费 对账
  1228. * @param fPid
  1229. * @param fBillType
  1230. * @return
  1231. */
  1232. @Transactional
  1233. public AjaxResult updateMoney(Long fPid,String fBillType) {
  1234. if (StringUtils.isNull(fPid)) {
  1235. return AjaxResult.error("费用明细更新状态未找到主表信息,请与管理员联系");
  1236. }
  1237. TFee tFee = tFeeMapper.selectTFeeById(fPid);
  1238. // 查询从表数据
  1239. TFeeDo tFeeDo = new TFeeDo();
  1240. tFeeDo.setfPid(fPid);
  1241. List<TFeeDo> tFeeDoList = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  1242. for (TFeeDo tFeeDo1 : tFeeDoList) {
  1243. /* // 跟新费用明细
  1244. Map<String, Object> map = this.judgeMoney(tFeeDo1.getfSrcid(), tFeeDo1.getfAmt(), tFee.getfBilltype(), tFeeDo1.getfFeeid());
  1245. if (!(Boolean) map.get("flag")) {
  1246. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1247. return AjaxResult.error(map.get("message").toString());
  1248. }*/
  1249. int m = updateBillsFees(fPid, tFeeDo1, fBillType);
  1250. if (m == 0) {
  1251. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1252. return AjaxResult.error("更新费用明细失败");
  1253. }
  1254. }
  1255. return AjaxResult.success();
  1256. }
  1257. @Override
  1258. @Transactional
  1259. public AjaxResult revoke(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  1260. // 更新 主表、从表
  1261. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  1262. if ("DZApplyFP".equals(fBilltype)) {
  1263. TFee fee = tFeeMapper.selectTFeeById(tFee.getfId());
  1264. if (fee.getfMake() == 1) {
  1265. return AjaxResult.error("该申请发票已开销项发票,不能撤销");
  1266. }
  1267. }
  1268. tFee.setUpdateBy(loginUser.getUser().getUserName());
  1269. tFee.setUpdateTime(new Date());
  1270. tFeeMapper.updateTFee(tFee);
  1271. // 删除从表
  1272. // tFeeDoMapper.deleteByFPid(tFee.getfId());
  1273. // 财务从表
  1274. if (StringUtils.isNotNull(tfeeDo)) {
  1275. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  1276. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  1277. for (TFeeDo tFeeDo : tFeeDoList) {
  1278. if (StringUtils.isNull(tFeeDo.getfId())) { // 需写入数据
  1279. tFeeDo.setfPid(tFee.getfId());
  1280. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  1281. tFeeDo.setCreateTime(new Date());
  1282. tFeeDoMapper.insertTFeeDo(tFeeDo);
  1283. // 跟新费用明细
  1284. int m = updateBillsFees(tFee.getfId(), tFeeDo, fBilltype);
  1285. if (m == 0) {
  1286. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1287. return AjaxResult.error("更新费用明细失败");
  1288. }
  1289. } else { // 需更改数据
  1290. TFeeDo tfdo = tFeeDoMapper.selectTFeeDoById(tFeeDo.getfId());
  1291. tfdo.setUpdateBy(loginUser.getUser().getUserName());
  1292. tfdo.setUpdateTime(new Date());
  1293. tFeeDoMapper.updateTFeeDo(tfdo);
  1294. }
  1295. }
  1296. }
  1297. //修改主订单费用信息
  1298. if (fBilltype.equals("DCRevoke")) {
  1299. this.updateMessage(tFee.getfId());
  1300. }
  1301. // 撤销对账时更改费用明细数据
  1302. /*if (fBilltype.equals("DZRevoke")) {
  1303. this.updateDSFMoney(tFee.getfId(),fBilltype);
  1304. }*/
  1305. // 根据业务财务数据 id 删除对应的审批流数据
  1306. AuditItemsAbout.deleteAuditItemsData(tFee.getfId());
  1307. return AjaxResult.success();
  1308. }
  1309. public void updateMessage(Long fid) {
  1310. List<TFeeDo> list = tFeeDoMapper.selectTFeeDoByfPid(fid);
  1311. if (CollectionUtils.isNotEmpty(list)){
  1312. List<Long> collect = list.stream().map(TFeeDo::getfSrcpid).collect(toList());
  1313. collect.stream().forEach(item ->{
  1314. TWarehouseBills warehouseBills = tWarehouseBillsMapper.selectTWarehousebillsById(item);
  1315. //获取订舱单位
  1316. TCorps tCorps = tCorpsMapper.selectTCorpsById(warehouseBills.getfCorpid());
  1317. //实收费用
  1318. List<TWarehousebillsfees> warehousebillsfees = tWarehousebillsfeesMapper.selectFeesByPId(item, "D");
  1319. //实付费用
  1320. List<TWarehousebillsfees> tWarehousebillsfees = tWarehousebillsfeesMapper.selectFeesByPId(item, "C");
  1321. TWarehouseBills tWarehouseBills = new TWarehouseBills();
  1322. tWarehouseBills.setfId(item);
  1323. tWarehouseBills.setfRecycle(warehousebillsfees.stream().filter(ei->ei.getfStlamount()!=null && ei.getfBillstatus().longValue() == 6L).map(TWarehousebillsfees::getfStlamount).reduce(BigDecimal.ZERO,BigDecimal::add));
  1324. tWarehouseBills.setfPay(tWarehousebillsfees.stream().filter(ei->ei.getfStlamount()!=null && ei.getfBillstatus().longValue() == 6L).map(TWarehousebillsfees::getfStlamount).reduce(BigDecimal.ZERO,BigDecimal::add));
  1325. //如果订舱单位是凯和 应收尾0 也是放货状态
  1326. //1: 未放货 应收>0 应收>实收
  1327. //2:放货 应收>0 应收=实收
  1328. if ((tCorps == null || tCorps.getfCname().equals("青岛凯和志诚物流有限公司")) && !warehouseBills.getfCaregoStatus().equals("3") ){
  1329. tWarehouseBills.setfCaregoStatus("2");
  1330. }else if (warehouseBills.getfReceivable().compareTo(BigDecimal.ZERO) > 0 && warehouseBills.getfReceivable().compareTo(tWarehouseBills.getfRecycle()) > 0){
  1331. tWarehouseBills.setfCaregoStatus("1");
  1332. }else if (warehouseBills.getfReceivable().compareTo(BigDecimal.ZERO) > 0 && warehouseBills.getfReceivable().compareTo(tWarehouseBills.getfRecycle()) <= 0){
  1333. tWarehouseBills.setfCaregoStatus("2");
  1334. }
  1335. tWarehouseBillsMapper.updateTWarehousebills(tWarehouseBills);
  1336. });
  1337. }
  1338. }
  1339. @Override
  1340. public AjaxResult queryRemove(Long fId) {
  1341. TFee tFee = tFeeMapper.selectTFeeById(fId);
  1342. TFeeDo tFeeDo = new TFeeDo();
  1343. tFeeDo.setfPid(tFee.getfId());
  1344. List<TFeeDo> tFeeDoList = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  1345. if (StringUtils.isNull(tFee)) {
  1346. return AjaxResult.success("0");
  1347. } else if (StringUtils.isNotNull(tFee) && StringUtils.isEmpty(tFeeDoList)) {
  1348. return AjaxResult.success("1");
  1349. } else if (tFee.getfBilltype().equals("INV") && tFee.getfAccountId() != null) {
  1350. return AjaxResult.success("3");
  1351. } else {
  1352. return AjaxResult.success("2");
  1353. }
  1354. }
  1355. @Override
  1356. @Transactional
  1357. public AjaxResult remove(Long fId) {
  1358. TFee tFee = tFeeMapper.selectTFeeById(fId);
  1359. if ("4".equals(tFee.getfBillstatus())) {
  1360. return AjaxResult.error("数据已提交审批,暂不能删除");
  1361. } else if ("5".equals(tFee.getfBillstatus())) {
  1362. return AjaxResult.error("数据正在审批,暂不能删除");
  1363. } else if ("6".equals(tFee.getfBillstatus())) {
  1364. return AjaxResult.error("数据审批完成,不能删除");
  1365. } else {
  1366. try {
  1367. tFeeMapper.deleteTFeeById(fId);
  1368. tFeeDoMapper.deleteByFPid(fId);
  1369. tFeeInvoiceMapper.deleteByFPid(fId);
  1370. } catch (Exception e) {
  1371. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1372. return AjaxResult.error("删除失败,请找管理员");
  1373. }
  1374. return AjaxResult.success();
  1375. }
  1376. }
  1377. @Override
  1378. public List<TWareHouseExcelItem> selectTWarehousebillsItemsList(Long fId) {
  1379. List<TWareHouseExcelItem> tWareHouseExcelItemList = tFeeMapper.selectTWarehousebillsItemsList(fId);
  1380. List<TWareHouseExcelItem> tWareHouseExcelItemList1 = new ArrayList<>();
  1381. for (TWareHouseExcelItem tWareHouseExcelItem : tWareHouseExcelItemList) {
  1382. if (StringUtils.isNotNull(tWareHouseExcelItem.getfBusinessType())) {
  1383. List<SysDictData> sysDictDataListIn = new ArrayList<>();
  1384. SysDictData sysDictData = new SysDictData();
  1385. if (tWareHouseExcelItem.getfBilltype().equals("入库")) {
  1386. sysDictData.setDictType(ST_IN_TYPE);
  1387. sysDictData.setDictValue(String.valueOf(tWareHouseExcelItem.getfBusinessType()));
  1388. sysDictData.setStatus("0");
  1389. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  1390. } else if (tWareHouseExcelItem.getfBilltype().equals("出库")) {
  1391. sysDictData.setDictType(ST_OUT_TYPE);
  1392. sysDictData.setDictValue(String.valueOf(tWareHouseExcelItem.getfBusinessType()));
  1393. sysDictData.setStatus("0");
  1394. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  1395. } else if (tWareHouseExcelItem.getfBilltype().equals("调拨") | tWareHouseExcelItem.getfBilltype().equals("货物通关")) {
  1396. sysDictData.setDictType(ST_TRANS_TYPE);
  1397. sysDictData.setDictValue(String.valueOf(tWareHouseExcelItem.getfBusinessType()));
  1398. sysDictData.setStatus("0");
  1399. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  1400. }
  1401. if (null != sysDictDataListIn && sysDictDataListIn.size() > 0) {
  1402. tWareHouseExcelItem.setfBusinessType(sysDictDataListIn.get(0).getDictLabel());
  1403. }
  1404. }
  1405. tWareHouseExcelItemList1.add(tWareHouseExcelItem);
  1406. }
  1407. return tWareHouseExcelItemList1;
  1408. }
  1409. @Override
  1410. public String findCtrlcorpid(Long fId) {
  1411. TFee tFee = tFeeMapper.selectTFeeById(fId);
  1412. //String exportName = tFee.getfCtrlcorpid() + "-" + tFee.getfBillno();
  1413. String exportName = tFee.getfCorpidName() + "-" + tFee.getfBillno();
  1414. return exportName;
  1415. }
  1416. @Override
  1417. public List<Receivable> receivableExport(TWareHouseFees tWareHouseFees) throws Exception {
  1418. List<Map<String, Object>> list = tFeeMapper.warehouseBillsFeesList1(tWareHouseFees);
  1419. List<Receivable> list1 = ListMapToBeanUtils.castMapToBean(list, Receivable.class);
  1420. return list1;
  1421. }
  1422. @Override
  1423. public List<GeneralLedgerExcel> payableExport(TWareHouseFees tWareHouseFees) throws Exception {
  1424. List<GeneralLedgerExcel> ledgerExcelList = new ArrayList<>();
  1425. List<FeeVO> feeVOList = tFeeMapper.selectFinancialLedgerList(tWareHouseFees);
  1426. feeVOList.forEach(vo -> {
  1427. GeneralLedgerExcel ledgerExcel = new GeneralLedgerExcel();
  1428. ledgerExcel.setFAmount(vo.getFAmount());
  1429. ledgerExcel.setReviewDate(vo.getReviewDate());
  1430. ledgerExcel.setFFeesName(vo.getFFeesName());
  1431. ledgerExcel.setNnfinished(vo.getNnfinished());
  1432. ledgerExcel.setFStlamount(vo.getFStlamount());
  1433. ledgerExcelList.add(ledgerExcel);
  1434. });
  1435. return ledgerExcelList;
  1436. }
  1437. @Override
  1438. public List<Profit> profitExport(TWareHouseFees tWareHouseFees) throws Exception {
  1439. List<Map<String, Object>> list = tFeeMapper.warehouseBillsFeesProfitList(tWareHouseFees);
  1440. return ListMapToBeanUtils.castMapToBean(list, Profit.class);
  1441. }
  1442. @Override
  1443. public List<ProfitGeneralLedgerExcel> profitCustomExport(TWareHouseFees tWareHouseFees) throws Exception {
  1444. List<Map<String, Object>> list = tFeeMapper.warehouseBillsFeesCustomProfitList(tWareHouseFees);
  1445. return ListMapToBeanUtils.castMapToBean(list, ProfitGeneralLedgerExcel.class);
  1446. }
  1447. @Override
  1448. public List<Contrast> contrastExport(TFee tFee) throws Exception {
  1449. List<Map<String, Object>> list = tFeeMapper.selectTFeeList1(tFee);
  1450. for (Map<String,Object> map : list) {
  1451. List<TFeeDo> tfd = tFeeDoMapper.selectTFeeDoByfPid(Long.valueOf(map.get("fId").toString()));
  1452. if (tfd.size()!=0) {
  1453. StringBuilder stringBuilder = new StringBuilder();
  1454. for (TFeeDo tFeeDo : tfd) {
  1455. if (StringUtils.isNotNull(tFeeDo.getfSrcBillno())) {
  1456. stringBuilder.append(tFeeDo.getfSrcBillno()).append(",");
  1457. }
  1458. }
  1459. map.put("fSrcBillno",StringUtils.removeTheLastComma(stringBuilder));
  1460. }
  1461. }
  1462. return ListMapToBeanUtils.castMapToBean(list, Contrast.class);
  1463. }
  1464. @Override
  1465. public List<Payment> paymentExport(TFee tFee) throws Exception {
  1466. List<Map<String, Object>> list = tFeeMapper.selectFeeList(tFee);
  1467. return ListMapToBeanUtils.castMapToBean(list, Payment.class);
  1468. }
  1469. @Override
  1470. public List<Charge> chargeExport(TFee tFee) throws Exception {
  1471. List<Map<String, Object>> list = tFeeMapper.selectFeeList(tFee);
  1472. return ListMapToBeanUtils.castMapToBean(list, Charge.class);
  1473. }
  1474. @Override
  1475. public List<Account> accountExport(TFee tFee) throws Exception {
  1476. List<Map<String, Object>> list = tFeeMapper.webVersionTFee(tFee);
  1477. return ListMapToBeanUtils.castMapToBean(list, Account.class);
  1478. }
  1479. @Override
  1480. public List<Detailed> selectDetailedList(Long fId) {
  1481. List<Detailed> detailedList = tFeeMapper.selectDetailedList(fId);
  1482. List<Detailed> detailedList1 = new ArrayList<>();
  1483. for (Detailed tWareHouseExcelItem : detailedList) {
  1484. if (StringUtils.isNotNull(tWareHouseExcelItem.getfBusinessType())) {
  1485. List<SysDictData> sysDictDataListIn = new ArrayList<>();
  1486. SysDictData sysDictData = new SysDictData();
  1487. if (tWareHouseExcelItem.getfBilltype().equals("入库")) {
  1488. sysDictData.setDictType(ST_IN_TYPE);
  1489. sysDictData.setDictValue(String.valueOf(tWareHouseExcelItem.getfBusinessType()));
  1490. sysDictData.setStatus("0");
  1491. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  1492. } else if (tWareHouseExcelItem.getfBilltype().equals("出库")) {
  1493. sysDictData.setDictType(ST_OUT_TYPE);
  1494. sysDictData.setDictValue(String.valueOf(tWareHouseExcelItem.getfBusinessType()));
  1495. sysDictData.setStatus("0");
  1496. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  1497. } else if (tWareHouseExcelItem.getfBilltype().equals("调拨") | tWareHouseExcelItem.getfBilltype().equals("货物通关")) {
  1498. sysDictData.setDictType(ST_TRANS_TYPE);
  1499. sysDictData.setDictValue(String.valueOf(tWareHouseExcelItem.getfBusinessType()));
  1500. sysDictData.setStatus("0");
  1501. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  1502. }
  1503. if (CollectionUtils.isNotEmpty(sysDictDataListIn)) {
  1504. tWareHouseExcelItem.setfBusinessType(sysDictDataListIn.get(0).getDictLabel());
  1505. }
  1506. }
  1507. detailedList1.add(tWareHouseExcelItem);
  1508. }
  1509. return detailedList1;
  1510. }
  1511. @Override
  1512. public List<Map<String, Object>> selectdetailedList(TWarehousebill tWarehousebill) {
  1513. return tFeeMapper.selectDetailedList1(tWarehousebill);
  1514. }
  1515. /**
  1516. * 更新费用明细
  1517. *
  1518. * @param fid
  1519. * @param tFeeDo
  1520. * @param billsType
  1521. * @return
  1522. */
  1523. @Transactional
  1524. public int updateBillsFees(Long fid, TFeeDo tFeeDo, String billsType) {
  1525. // 查询从表数据
  1526. TFee tFee = tFeeMapper.selectTFeeById(fid);
  1527. if (billsType.equals("SF") || billsType.equals("FF")
  1528. || billsType.equals("KHSF") || billsType.equals("KHFF")) {
  1529. billsType = "DC";
  1530. }
  1531. Map<String, Object> map = new HashMap<>();
  1532. map.put("tFee", tFee);
  1533. map.put("billType", billsType);
  1534. map.put("tFeeDo", tFeeDo);
  1535. return tWarehousebillsfeesMapper.updateTWarehousebillsfee(map);
  1536. }
  1537. public boolean change(Long fId) {
  1538. boolean flag = false;
  1539. TFee tFee = tFeeMapper.selectTFeeById(fId);
  1540. if ("4".equals(tFee.getfBillstatus())
  1541. || "5".equals(tFee.getfBillstatus())
  1542. || "6".equals(tFee.getfBillstatus())) {
  1543. flag = false;
  1544. } else {
  1545. flag = true;
  1546. }
  1547. return flag;
  1548. }
  1549. @Override
  1550. @Transactional
  1551. public AjaxResult webVersionSubmitApplyFP(TFee tFee, LoginUser loginUser, String fBilltype) {
  1552. String key = "";
  1553. boolean isApprove = false;
  1554. long actId = 0L;
  1555. String billStatus = "";
  1556. if ("ApplyFP".equals(fBilltype)) {
  1557. actId = 470L;
  1558. key = "warehouse.kaiHeApplyFP.ApprovalFlow";
  1559. }
  1560. SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique(key);
  1561. if (StringUtils.isNull(sysConfig)) {
  1562. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1563. return AjaxResult.error("系统参数异常,未找到开启审批流参数");
  1564. }
  1565. if ("0".equals(sysConfig.getConfigValue())) {
  1566. isApprove = true;
  1567. }
  1568. if (isApprove) {
  1569. billStatus = "4";
  1570. } else {
  1571. billStatus = "6";
  1572. }
  1573. /*for (Long getfId : tFee.getfIds()) {*/
  1574. TFee fee = tFeeMapper.selectTFeeById(tFee.getfId());
  1575. if (fee == null) {
  1576. return AjaxResult.error("财务主表数据有误,请确认");
  1577. }
  1578. boolean change = this.change(tFee.getfId());
  1579. if (change == false) {
  1580. return AjaxResult.error("数据正在审批或审批通过,不允许提交审核");
  1581. }
  1582. fee.setfId(tFee.getfId());
  1583. fee.setfBillstatus(billStatus);
  1584. fee.setUpdateBy(loginUser.getUser().getUserName());
  1585. fee.setUpdateTime(new Date());
  1586. int updateTFee = tFeeMapper.updateTFee(fee);
  1587. if (updateTFee <= 0) {
  1588. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1589. return AjaxResult.error("更新财务主表数据出错,请找管理员");
  1590. }
  1591. TFeeDo tFeeDo = new TFeeDo();
  1592. tFeeDo.setfPid(tFee.getfId());
  1593. List<TFeeDo> tFeeDos = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  1594. if (CollectionUtils.isEmpty(tFeeDos)) {
  1595. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1596. return AjaxResult.error("财务从表数据有误,请确认");
  1597. }
  1598. for (TFeeDo feeDo : tFeeDos) {
  1599. feeDo.setfId(feeDo.getfId());
  1600. feeDo.setfStatus(billStatus);
  1601. feeDo.setUpdateBy(loginUser.getUser().getUserName());
  1602. feeDo.setUpdateTime(new Date());
  1603. int i = tFeeDoMapper.updateTFeeDo(feeDo);
  1604. if (i <= 0) {
  1605. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1606. return AjaxResult.error("更新财务主表数据出错,请找管理员");
  1607. }
  1608. }
  1609. TFeeInvoice tFeeInvoice = new TFeeInvoice();
  1610. tFeeInvoice.setfPid(tFee.getfId());
  1611. List<TFeeInvoice> tFeeInvoiceList = tFeeInvoiceMapper.selectTFeeInvoiceList(tFeeInvoice);
  1612. if (CollectionUtils.isNotEmpty(tFeeInvoiceList)) {
  1613. for (TFeeInvoice invoice : tFeeInvoiceList) {
  1614. tFeeInvoice.setfBillstatus(billStatus);
  1615. tFeeInvoice.setfId(invoice.getfId());
  1616. tFeeInvoice.setUpdateBy(loginUser.getUser().getUserName());
  1617. tFeeInvoice.setUpdateTime(new Date());
  1618. tFeeInvoiceMapper.updateTFeeInvoice(tFeeInvoice);
  1619. }
  1620. }
  1621. //添加审批流
  1622. if (isApprove) {
  1623. AuditItems auditItems = new AuditItems();
  1624. auditItems.setLevelId(0L);
  1625. auditItems.setBillId(fee.getfId());
  1626. auditItems.setActId(actId);
  1627. auditItems.setIffinalItem("F");
  1628. auditItems.setBillNo(fee.getfBillno()); // 业务编号
  1629. auditItems.setRefno1(String.valueOf(fee.getfCorpid())); // 货权方
  1630. auditItems.setRefno2(fee.getfBilltype());// 财务类型
  1631. auditItems.setRefno3(fee.gettMblno());// 提单号
  1632. auditItems.setSendUserId(loginUser.getUser().getUserId());
  1633. auditItems.setSendName(loginUser.getUsername());
  1634. auditItems.setSendTime(new Date());
  1635. auditItems.setAuditUserId(loginUser.getUser().getUserId());
  1636. auditItems.setAuditItem(new Date());
  1637. auditItems.setAuditOpTime(new Date());
  1638. auditItems.setFidStatus("f_billstatus");
  1639. auditItems.setTimes(1L);
  1640. auditItems.setAuditMsg("提交");
  1641. auditItems.setAuditStatus("O");
  1642. AjaxResult approvalFlow = auditItemsService.createApprovalFlow(auditItems);
  1643. Long code = Long.valueOf(String.valueOf(approvalFlow.get("code"))).longValue();
  1644. if (code.equals(500L)) {
  1645. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1646. return AjaxResult.error("提交审核失败,请找管理员");
  1647. }
  1648. return approvalFlow;
  1649. } else {
  1650. for (TFeeDo t : tFeeDos) {
  1651. // 跟新费用明细
  1652. int m = updateBillsFees(tFee.getfId(), t, fBilltype);
  1653. if (m == 0) {
  1654. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1655. return AjaxResult.error("更新费用明细失败");
  1656. }
  1657. }
  1658. AjaxResult ajaxResult = tfeeFollow(tFee.getfId(), 6L);
  1659. Long code = Long.valueOf(String.valueOf(ajaxResult.get("code"))).longValue();
  1660. if (code.equals(500L)) {
  1661. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1662. return AjaxResult.error("提交审核失败,请找管理员");
  1663. }
  1664. return ajaxResult;
  1665. }
  1666. /*}*/
  1667. //return AjaxResult.success();
  1668. }
  1669. @Override
  1670. public AjaxResult webVersionUpdateApplyFP(TFee tFee, LoginUser loginUser, String billType) {
  1671. TFeeInvoice tFeeInvoice = tFee.gettFeeInvoice();
  1672. tFeeInvoice.setfPid(tFee.getfId());
  1673. int i = 0;
  1674. if (tFeeInvoice.getfId() != null) {
  1675. tFeeInvoice.setUpdateBy(loginUser.getUser().getUserName());
  1676. tFeeInvoice.setUpdateTime(new Date());
  1677. i = tFeeInvoiceMapper.updateTFeeInvoice(tFeeInvoice);
  1678. } else {
  1679. return AjaxResult.error("开票信息为空,请找管理员");
  1680. }
  1681. if (i <= 0) {
  1682. return AjaxResult.error("更新数据失败,请找管理员");
  1683. } else {
  1684. return AjaxResult.success();
  1685. }
  1686. }
  1687. @Override
  1688. public List<FinancialTFee> selectFinancialTFeeList(TFee tFee) {
  1689. return tFeeMapper.selectFinancialTFeeList(tFee);
  1690. }
  1691. @Override
  1692. public List<Map<String, Object>> FinancialFeesList(TWareHouseFees tWareHouseFees) {
  1693. Map<String, Object> map = new HashMap<>();
  1694. map.put("tWareHouseFees", tWareHouseFees);
  1695. return tFeeMapper.FinancialFeesList(map);
  1696. }
  1697. @Override
  1698. public Map<String, Object> selectFinancialTFeeId(Long fId) {
  1699. Map<String, Object> map = new HashMap<>();
  1700. FinancialTFee financialTFee = tFeeMapper.selectFinancialTFeeId(fId);
  1701. List<FinancialTFeeDoExcel> financialTFeeDoExcels = tFeeDoMapper.selectFinancialTFeeDo(fId);
  1702. map.put("tFee", financialTFee);
  1703. map.put("tFeeDo", financialTFeeDoExcels);
  1704. return map;
  1705. }
  1706. @Override
  1707. public List<FinancialTFeeDoExcel> FinancialTFeeDoExcel(Long fId) {
  1708. return tFeeDoMapper.selectFinancialTFeeDo(fId);
  1709. }
  1710. @Override
  1711. @Transactional
  1712. public AjaxResult webVersionApplyFP(TFee tFee, LoginUser loginUser, String fBilltype, TFeeInvoice tFeeInvoice) {
  1713. Long fPid = null;
  1714. String billStatus = "2";
  1715. try {
  1716. /*for (Long getfId : tFee.getfIds()) {*/
  1717. TFee account = new TFee();
  1718. TFee fee = tFeeMapper.selectTFeeById(tFee.getfId());
  1719. if (fee == null) {
  1720. return AjaxResult.error("财务主表数据有误,请确认");
  1721. }
  1722. account.setfId(fee.getfId());
  1723. account.setfMake(1);
  1724. fee.setfBilltype(fBilltype);
  1725. fee.setfBillstatus(billStatus);
  1726. fee.setCreateBy(loginUser.getUser().getUserName());
  1727. fee.setCreateTime(new Date());
  1728. fee.setfDeptid(loginUser.getUser().getDeptId());
  1729. fee.setUpdateBy(null);
  1730. fee.setUpdateTime(null);
  1731. fee.setfInvoiceRise(tFee.getfInvoiceRise());
  1732. fee.setfAccountId(fee.getfId());
  1733. Date time = new Date();
  1734. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  1735. fee.setfBillno(billNo);
  1736. fee.setfAccbilldate(null);
  1737. fee.setfId(null);
  1738. tFeeMapper.insertTFee(fee);
  1739. tFeeMapper.updateTFee(account);
  1740. //修改原来的数据的开票金额
  1741. fPid = fee.getfId();
  1742. TFeeDo tFeeDo = new TFeeDo();
  1743. tFeeDo.setfPid(tFee.getfId());
  1744. List<TFeeDo> tFeeDos = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  1745. if (CollectionUtils.isEmpty(tFeeDos)) {
  1746. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1747. return AjaxResult.error("财务从表数据有误,请确认");
  1748. }
  1749. for (TFeeDo feeDo : tFeeDos) {
  1750. feeDo.setfPid(fPid);
  1751. feeDo.setfStatus(billStatus);
  1752. feeDo.setCreateBy(loginUser.getUser().getUserName());
  1753. feeDo.setCreateTime(new Date());
  1754. feeDo.setUpdateBy(null);
  1755. feeDo.setUpdateTime(null);
  1756. int i = tFeeDoMapper.insertTFeeDo(feeDo);
  1757. }
  1758. tFeeInvoice.setfBillstatus(billStatus);
  1759. tFeeInvoice.setfPid(fPid);
  1760. tFeeInvoice.setCreateBy(loginUser.getUser().getUserName());
  1761. tFeeInvoice.setCreateTime(new Date());
  1762. tFeeInvoiceMapper.insertTFeeInvoice(tFeeInvoice);
  1763. /*}*/
  1764. } catch (Exception e) {
  1765. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1766. return AjaxResult.error("申请发票出错,请找管理员");
  1767. }
  1768. return AjaxResult.success();
  1769. }
  1770. /**
  1771. * 判断金额是否超过可用金额
  1772. *
  1773. * @param fid 费用明细表主键
  1774. * @param money 申请金额
  1775. * @param type DZ 对账 SF 收费 FF 付费 ApplyFP 开票申请 invoiceFP 开票
  1776. * @return
  1777. */
  1778. public Map<String, Object> judgeMoney(long fid, BigDecimal money, String type, Long feeId) {
  1779. Map<String, Object> map = new HashMap<>();
  1780. boolean flag = true;
  1781. TWarehousebillsfees warehousebillsfees = tWarehousebillsfeesMapper.selectTWarehousebillsfeesById(fid);
  1782. TWarehouseBills bills = tWarehouseBillsMapper.selectTWarehousebillsById(warehousebillsfees.getfPid());
  1783. TFees tFees = tFeesMapper.selectTFeesById(feeId);
  1784. BigDecimal amount = warehousebillsfees.getfAmount();//金额
  1785. BigDecimal accamount = warehousebillsfees.getfAccamount();//对账金额
  1786. BigDecimal stlamount = warehousebillsfees.getfStlamount();//结算金额
  1787. BigDecimal invamount = warehousebillsfees.getfInvamount();//开票金额a
  1788. BigDecimal askamount = warehousebillsfees.getfAskamount();//申请金额
  1789. if (bills == null){
  1790. flag = false;
  1791. map.put("message", "费用明细数据有误,请找管理员");
  1792. }else if (warehousebillsfees == null) {
  1793. flag = false;
  1794. map.put("message", "费用明细数据有误,请找管理员");
  1795. } else if ("DZ".equals(type) || "KHDZ".equals(type)) {
  1796. BigDecimal subtract = amount.subtract(accamount);
  1797. if (subtract.compareTo(money) < 0) {
  1798. flag = false;
  1799. map.put("message", "提单号"+bills.getfMblno()+"的"+tFees.getfName() + "对账金额超过可对账金额,当前可对账金额为" + subtract + "元");
  1800. }
  1801. } else if ("SF".equals(type) || "KHSF".equals(type)) {
  1802. BigDecimal subtract = amount.subtract(stlamount);
  1803. if (subtract.compareTo(money) < 0) {
  1804. flag = false;
  1805. map.put("message", "提单号"+bills.getfMblno()+"的"+tFees.getfName() + "收费金额超过可收费金额,当前可对账金额为" + subtract + "元");
  1806. }
  1807. } else if ("FF".equals(type) || "KHFF".equals(type)) {
  1808. BigDecimal subtract = amount.subtract(stlamount);
  1809. if (subtract.compareTo(money) < 0) {
  1810. flag = false;
  1811. map.put("message", "提单号"+bills.getfMblno()+"的"+tFees.getfName() + "付费金额超过可付费金额,当前可对账金额为" + subtract + "元");
  1812. }
  1813. } else if ("ApplyFP".equals(type)) {
  1814. BigDecimal subtract = amount.subtract(askamount);
  1815. if (subtract.compareTo(money) < 0) {
  1816. flag = false;
  1817. map.put("message", "提单号"+bills.getfMblno()+"的"+tFees.getfName() + "开票金额超过可开票金额,当前可对账金额为" + subtract + "元");
  1818. }
  1819. } else if ("invoiceFP".equals(type)) {
  1820. BigDecimal subtract = amount.subtract(invamount);
  1821. if (subtract.compareTo(money) < 0) {
  1822. flag = false;
  1823. map.put("message", "提单号"+bills.getfMblno()+"的"+tFees.getfName() + "开票金额超过可开票金额,当前可对账金额为" + subtract + "元");
  1824. }
  1825. }
  1826. map.put("flag", flag);
  1827. return map;
  1828. }
  1829. /**
  1830. * 申请发票审核成功复制数据到销项发票中
  1831. *
  1832. * @param fId 主表id
  1833. * @param fBilltype 类型
  1834. * @return
  1835. */
  1836. @Transactional
  1837. public AjaxResult copyInvoiceFp(Long fId, String fBilltype) {
  1838. //查询费用主表信息复制主表信息
  1839. Integer insert = null;
  1840. TFee fee = tFeeMapper.selectTFeeById(fId);
  1841. TFee tFee = new TFee();
  1842. tFee.setfId(fee.getfId());
  1843. Date time = new Date();
  1844. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  1845. //查询费用从表信息复制主表信息
  1846. fee.setfAccountId(fee.getfId());
  1847. fee.setfBillno(billNo);
  1848. fee.setfBilltype(fBilltype);
  1849. fee.setfId(null);
  1850. insert = tFeeMapper.insertTFee(fee);
  1851. tFee.setfMake(1);
  1852. //修改原发票数据代表已开销项发票
  1853. insert = tFeeMapper.updateTFee(tFee);
  1854. TFeeDo tFeeDo = new TFeeDo();
  1855. tFeeDo.setfPid(fId);
  1856. List<TFeeDo> tFeeDoList = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  1857. if (CollectionUtils.isNotEmpty(tFeeDoList)) {
  1858. for (TFeeDo feeDo : tFeeDoList) {
  1859. feeDo.setfId(null);
  1860. feeDo.setfPid(fee.getfId());
  1861. feeDo.setfBilltype(fBilltype);
  1862. insert = tFeeDoMapper.insertTFeeDo(feeDo);
  1863. }
  1864. }
  1865. //查询开票信息复制主表信息
  1866. TFeeInvoice tFeeInvoice = new TFeeInvoice();
  1867. tFeeInvoice.setfPid(fId);
  1868. List<TFeeInvoice> tFeeInvoiceList = tFeeInvoiceMapper.selectTFeeInvoiceList(tFeeInvoice);
  1869. if (CollectionUtils.isNotEmpty(tFeeInvoiceList)) {
  1870. for (TFeeInvoice invoice : tFeeInvoiceList) {
  1871. invoice.setfId(null);
  1872. invoice.setfPid(fee.getfId());
  1873. insert = tFeeInvoiceMapper.insertTFeeInvoice(invoice);
  1874. }
  1875. }
  1876. if (insert != null && insert > 0) {
  1877. return AjaxResult.success();
  1878. } else {
  1879. return AjaxResult.error("生成销项发票失败,请找管理员");
  1880. }
  1881. }
  1882. /**
  1883. * 导出财务对账数据
  1884. *
  1885. * @param fId
  1886. * @return
  1887. */
  1888. @Override
  1889. public AjaxResult exportFinancial(Long fId) {
  1890. //获取数据
  1891. String shipsName = "";//船名
  1892. String voyage = "";//航次
  1893. String corpName = "";//客户
  1894. String fFromDate = "";//离港日期开始
  1895. String fToDate = "";//离港日期结束
  1896. BigDecimal fAmount = new BigDecimal(0);//合计
  1897. //查询财务主数据
  1898. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  1899. TFee fee = tFeeMapper.selectTFeeById(fId);
  1900. if (fee != null) {
  1901. corpName = fee.getfCtrlcorpid();
  1902. if (fee.getfFromDate() != null) {
  1903. fFromDate = simpleDateFormat.format(fee.getfFromDate());
  1904. }
  1905. if (fee.getfToDate() != null) {
  1906. fToDate = simpleDateFormat.format(fee.getfToDate());
  1907. }
  1908. if (fee.getfVslid() != null) {
  1909. TVessel vessel = tVesselMapper.selectTVesselById(fee.getfVslid());
  1910. if (vessel != null && StringUtils.isNotEmpty(vessel.getfName())) {
  1911. shipsName = vessel.getfName();
  1912. }
  1913. }
  1914. if (fee.getfVoyid() != null) {
  1915. TVoyage tVoyage = tVoyageMapper.selectTVoyageById(fee.getfVoyid());
  1916. if (tVoyage != null && StringUtils.isNotEmpty(tVoyage.getfNo())) {
  1917. voyage = tVoyage.getfNo();
  1918. }
  1919. }
  1920. }
  1921. //样式设置
  1922. //1.创建一个workbook,对应一个excel文件
  1923. HSSFWorkbook wb = new HSSFWorkbook();
  1924. //2.在workbook中添加一个sheet,对应Excel中的sheet
  1925. HSSFSheet sheet = wb.createSheet("对账");
  1926. //设置每一列的列宽
  1927. sheet.setColumnWidth(0, 256 * 15);
  1928. sheet.setColumnWidth(1, 256 * 20);
  1929. sheet.setColumnWidth(2, 256 * 20);
  1930. sheet.setColumnWidth(3, 256 * 20);
  1931. sheet.setColumnWidth(4, 256 * 15);
  1932. sheet.setColumnWidth(5, 256 * 15);
  1933. sheet.setColumnWidth(6, 256 * 15);
  1934. sheet.setColumnWidth(7, 100 * 35);
  1935. sheet.setColumnWidth(8, 256 * 15);
  1936. sheet.setColumnWidth(9, 256 * 15);
  1937. //3.设置样式以及字体样式
  1938. HSSFCellStyle titleStyle = ExcelUtils.createTitleCellStyle(wb);
  1939. HSSFCellStyle contentStyle = ExcelUtils.createContentCellStyle(wb);
  1940. HSSFCellStyle subheadingStyle = ExcelUtils.createSubheadingStyle(wb);
  1941. HSSFCellStyle endStyle = ExcelUtils.createEndStyle(wb);
  1942. //4.创建标题,合并标题单元格
  1943. //行号
  1944. int rowNum = 0;
  1945. //创建第一行,索引从0开始(标题行)
  1946. HSSFRow row0 = sheet.createRow(rowNum++);
  1947. row0.setHeight((short) 800);// 设置行高
  1948. for (int i = 0; i < 10; i++) {
  1949. HSSFCell tempCell = row0.createCell(i);
  1950. tempCell.setCellStyle(contentStyle);
  1951. }
  1952. String title = "青岛凯和志诚物流有限公司";
  1953. HSSFCell c00 = row0.createCell(0);
  1954. c00.setCellValue(title);
  1955. c00.setCellStyle(titleStyle);
  1956. // 合并单元格,参数依次为起始行,结束行,起始列,结束列 (索引0开始)
  1957. sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 9));//标题合并单元格操作,总列数为9
  1958. //第2行
  1959. HSSFRow row1 = sheet.createRow(rowNum++);
  1960. row1.setHeight((short) 500);
  1961. String message1 = "客户确认单";
  1962. for (int i = 0; i < 10; i++) {
  1963. HSSFCell tempCell = row1.createCell(i);
  1964. tempCell.setCellStyle(contentStyle);
  1965. }
  1966. HSSFCell c01 = row1.createCell(0);
  1967. c01.setCellValue(message1);
  1968. c01.setCellStyle(subheadingStyle);
  1969. sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 9));//标题合并单元格操作,总列数为9
  1970. //第3行
  1971. HSSFRow row2 = sheet.createRow(rowNum++);
  1972. row2.setHeight((short) 500);
  1973. String message2 = "尊敬的客户";
  1974. HSSFCell c02 = row2.createCell(0);
  1975. c02.setCellValue(message2);
  1976. c02.setCellStyle(contentStyle);
  1977. //第3行
  1978. for (int i = 1; i < 10; i++) {
  1979. HSSFCell tempCell = row2.createCell(i);
  1980. tempCell.setCellStyle(contentStyle);
  1981. }
  1982. HSSFCell c03 = row2.createCell(1);
  1983. c03.setCellValue(corpName);
  1984. c03.setCellStyle(contentStyle);
  1985. sheet.addMergedRegion(new CellRangeAddress(2, 2, 1, 9));//标题合并单元格操作,总列数为9
  1986. //合并单元格
  1987. sheet.addMergedRegion(new CellRangeAddress(3, 3, 1, 2));
  1988. sheet.addMergedRegion(new CellRangeAddress(3, 3, 3, 4));
  1989. sheet.addMergedRegion(new CellRangeAddress(3, 3, 5, 9));
  1990. //第4行
  1991. HSSFRow row3 = sheet.createRow(rowNum++);
  1992. for (int i = 0; i < 1; i++) {
  1993. HSSFCell tempCell = row3.createCell(i);
  1994. tempCell.setCellStyle(contentStyle);
  1995. }
  1996. for (int i = 1; i < 3; i++) {
  1997. HSSFCell tempCell = row3.createCell(i);
  1998. tempCell.setCellStyle(contentStyle);
  1999. }
  2000. for (int i = 3; i < 5; i++) {
  2001. HSSFCell tempCell = row3.createCell(i);
  2002. tempCell.setCellStyle(contentStyle);
  2003. }
  2004. for (int i = 5; i < 10; i++) {
  2005. HSSFCell tempCell = row3.createCell(i);
  2006. tempCell.setCellStyle(contentStyle);
  2007. }
  2008. row3.setHeight((short) 500);
  2009. HSSFCell c05 = row3.createCell(0);
  2010. c05.setCellValue("船名航次:");
  2011. c05.setCellStyle(contentStyle);
  2012. HSSFCell c051 = row3.createCell(1);
  2013. c051.setCellValue(shipsName + voyage);
  2014. c051.setCellStyle(contentStyle);
  2015. HSSFCell c052 = row3.createCell(3);
  2016. c052.setCellValue("离港日期:");
  2017. c052.setCellStyle(contentStyle);
  2018. String message = "";
  2019. HSSFCell c053 = row3.createCell(5);
  2020. if (StringUtils.isNotEmpty(fFromDate)) {
  2021. if (StringUtils.isNotEmpty(fFromDate)) {
  2022. message = fFromDate + "-" + fToDate;
  2023. } else {
  2024. message = fFromDate;
  2025. }
  2026. } else if (StringUtils.isNotEmpty(fToDate)) {
  2027. message = fToDate;
  2028. }
  2029. c053.setCellValue(message);
  2030. c053.setCellStyle(contentStyle);
  2031. //第5行
  2032. HSSFRow row4 = sheet.createRow(rowNum++);
  2033. for (int i = 0; i < 10; i++) {
  2034. HSSFCell tempCell = row4.createCell(i);
  2035. tempCell.setCellStyle(contentStyle);
  2036. }
  2037. row4.setHeight((short) 500);
  2038. String message4 = "费用明细";
  2039. HSSFCell c04 = row4.createCell(0);
  2040. c04.setCellValue(message4);
  2041. c04.setCellStyle(contentStyle);
  2042. sheet.addMergedRegion(new CellRangeAddress(4, 4, 0, 9));//标题合并单元格操作,总列数为9
  2043. //第四行
  2044. HSSFRow row5 = sheet.createRow(rowNum++);
  2045. row5.setHeight((short) 500);
  2046. String[] row_third = {"序号", "提单号", "始发港", "目的港", "运输条款", "货名", "箱量", "规格", "单价", "合计"};
  2047. for (int i = 0; i < row_third.length; i++) {
  2048. HSSFCell tempCell = row5.createCell(i);
  2049. tempCell.setCellValue(row_third[i]);
  2050. tempCell.setCellStyle(contentStyle);
  2051. }
  2052. //查询费用明细数据
  2053. List<ExportFinancial> list = tFeeMapper.exportFinancial(fId);
  2054. if (CollectionUtils.isNotEmpty(list)) {
  2055. for (int i = 0; i < list.size(); i++) {
  2056. HSSFRow tempRow = sheet.createRow(rowNum++);
  2057. tempRow.setHeight((short) 500);
  2058. //循环单元格填入数据
  2059. for (int j = 0; j < 10; j++) {
  2060. HSSFCell tempCell = tempRow.createCell(j);
  2061. tempCell.setCellStyle(contentStyle);
  2062. String cellValue = "";
  2063. if (j == 0) {
  2064. //序号
  2065. cellValue = list.get(i).getRankNo().toString();
  2066. } else if (j == 1) {
  2067. //提单号
  2068. cellValue = list.get(i).getfMblNo();
  2069. } else if (j == 2) {
  2070. //始发港
  2071. cellValue = list.get(i).getPortOfDeparture();
  2072. } else if (j == 3) {
  2073. //目的港
  2074. cellValue = list.get(i).getDestinationPort();
  2075. } else if (j == 4) {
  2076. //运输条款
  2077. cellValue = list.get(i).getfServiceitems()+"-"+list.get(i).getfServiceitemsNew();
  2078. } else if (j == 5) {
  2079. //货名
  2080. cellValue = list.get(i).getGoodName();
  2081. } else if (j == 6) {
  2082. //箱量
  2083. cellValue = list.get(i).getfCnTrCount().toString();
  2084. } else if (j == 7) {
  2085. //规格
  2086. cellValue = list.get(i).getSpecification();
  2087. } else if (j == 8) {
  2088. //单价
  2089. cellValue = list.get(i).getfUnitPrice().toString();
  2090. } else if (j == 9) {
  2091. //合计
  2092. cellValue = list.get(i).getfAmount().toString();
  2093. }
  2094. tempCell.setCellValue(cellValue);
  2095. }
  2096. }
  2097. fAmount = list.stream().map(ExportFinancial::getfAmount).reduce(BigDecimal.ZERO, BigDecimal::add);//求所有和的合计
  2098. }
  2099. //倒数第二行
  2100. HSSFRow row6 = sheet.createRow(rowNum++);
  2101. for (int i = 0; i < 10; i++) {
  2102. HSSFCell tempCell = row6.createCell(i);
  2103. tempCell.setCellStyle(contentStyle);
  2104. }
  2105. row6.setHeight((short) 500);
  2106. String message6 = "合计:";
  2107. HSSFCell c06 = row6.createCell(0);
  2108. c06.setCellValue(message6);
  2109. c06.setCellStyle(contentStyle);
  2110. HSSFCell c061 = row6.createCell(9);
  2111. c061.setCellValue(fAmount.toString());
  2112. c061.setCellStyle(contentStyle);
  2113. //最后一行
  2114. HSSFRow row7 = sheet.createRow(rowNum++);
  2115. for (int i = 0; i < 10; i++) {
  2116. HSSFCell tempCell = row7.createCell(i);
  2117. tempCell.setCellStyle(contentStyle);
  2118. }
  2119. row7.setHeight((short) 1500);
  2120. String message7 = "纳税人识别号:91370202MA3UG1T04A\n" +
  2121. "人民币账号:3803020309100171855\n" +
  2122. "人民币开户行:工商银行青岛分行营业部";
  2123. HSSFCell c07 = row7.createCell(0);
  2124. c07.setCellValue(message7);
  2125. c07.setCellStyle(endStyle);
  2126. sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, 0, 9));//标题合并单元格操作,总列数为9
  2127. //导出excel
  2128. String fileName = "客户对账单.xls";
  2129. try {
  2130. OutputStream out = null;
  2131. out = new FileOutputStream(getAbsoluteFile(fileName));
  2132. wb.write(out);
  2133. if (null != wb && null != out) {
  2134. wb.write(out);
  2135. wb.close();
  2136. out.close();
  2137. }
  2138. return AjaxResult.success(fileName);
  2139. } catch (Exception e) {
  2140. e.printStackTrace();
  2141. return AjaxResult.error("导出Excel失败");
  2142. }
  2143. }
  2144. /**
  2145. * 根据结算单位、费用状态、审核日期查询应付总帐明细
  2146. *
  2147. * @param feeDTO
  2148. * @return
  2149. */
  2150. @Override
  2151. public AjaxResult financialLedgerDetails(FeeDTO feeDTO) {
  2152. TFees ccf = tFeesMapper.seletFeesByCCF();
  2153. if (Objects.isNull(ccf)) {
  2154. throw new WarehouseException("未找到仓储费费用信息");
  2155. }
  2156. feeDTO.setFeesId(ccf.getfId());
  2157. List<FeeVO> feeVOList = tFeeMapper.selectFinancialLedgerDetails(feeDTO);
  2158. if (CollectionUtils.isNotEmpty(feeVOList)) {
  2159. List<FeeVO> voList = new ArrayList<>();
  2160. Map<Long, List<FeeVO>> map = feeVOList.stream().collect(Collectors.groupingBy(FeeVO::getFSrcpid));
  2161. map.forEach((key, value) -> {
  2162. FeeVO vo = new FeeVO();
  2163. FeeVO feeVO = value.stream().findFirst().orElseThrow(() ->
  2164. new WarehouseException("获取费用异常"));
  2165. BeanUtils.copyProperties(feeVO, vo);
  2166. // 仓储费
  2167. BigDecimal storageFee = value.stream().map(FeeVO::getStorageFee).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
  2168. // 其他费用
  2169. BigDecimal otherFee = value.stream().map(FeeVO::getOtherFee).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
  2170. // 应收费用
  2171. BigDecimal amount = value.stream().map(FeeVO::getFAmount).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
  2172. // 已收费用
  2173. BigDecimal stlamount = value.stream().map(FeeVO::getFStlamount).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
  2174. WarehouseTypeEnum storageType = WarehouseTypeEnum.fromTypeAndBusinessType(vo.getfBilltype(), "storageType");
  2175. vo.setfBilltype(storageType.getName());
  2176. vo.setStorageFee(storageFee);
  2177. vo.setFStlamount(stlamount);
  2178. vo.setOtherFee(otherFee);
  2179. vo.setFAmount(amount);
  2180. vo.setNnfinished(amount.subtract(stlamount));
  2181. voList.add(vo);
  2182. });
  2183. return AjaxResult.success(voList);
  2184. }
  2185. return AjaxResult.success(feeVOList);
  2186. }
  2187. /**
  2188. * 查询应付总帐明细
  2189. *
  2190. * @param feeDTO
  2191. * @return
  2192. */
  2193. @Override
  2194. public List<GeneralLedgerDetailExcel> financialLedgerDetailsExport(FeeDTO feeDTO) {
  2195. List<GeneralLedgerDetailExcel> detailExcelList = new ArrayList<>();
  2196. List<FeeVO> feeVOList = tFeeMapper.selectFinancialLedgerDetails(feeDTO);
  2197. feeVOList.forEach(vo -> {
  2198. GeneralLedgerDetailExcel detailExcel = new GeneralLedgerDetailExcel();
  2199. WarehouseTypeEnum storageType = WarehouseTypeEnum.fromTypeAndBusinessType(vo.getfBilltype(), "storageType");
  2200. detailExcel.setFMblno(vo.getFMblno());
  2201. detailExcel.setFMarks(vo.getFMarks());
  2202. detailExcel.setFAmount(vo.getFAmount());
  2203. detailExcel.setOtherFee(vo.getOtherFee());
  2204. detailExcel.setFFeesName(vo.getFFeesName());
  2205. detailExcel.setNnfinished(vo.getNnfinished());
  2206. detailExcel.setFStlamount(vo.getFStlamount());
  2207. detailExcel.setStorageFee(vo.getStorageFee());
  2208. detailExcel.setFBilltype(storageType.getName());
  2209. detailExcel.setFProductName(vo.getFProductName());
  2210. detailExcel.setFProductName(vo.getFProductName());
  2211. detailExcelList.add(detailExcel);
  2212. });
  2213. return detailExcelList;
  2214. }
  2215. @Override
  2216. public List<ReceivableExcel> receivable(TWareHouseFees tWareHouseFees) {
  2217. return tFeeMapper.receivable(tWareHouseFees);
  2218. }
  2219. @Override
  2220. public List<ProfitExcel> profit(TWareHouseFees tWareHouseFees) {
  2221. return tFeeMapper.profit(tWareHouseFees);
  2222. }
  2223. @Override
  2224. public List<HandleExcel> handle(TWareHouseFees tWareHouseFees) {
  2225. return tFeeMapper.handle(tWareHouseFees);
  2226. }
  2227. //下载路径
  2228. private String getAbsoluteFile(String fileName) {
  2229. String downloadPath = RuoYiConfig.getDownloadPath() + fileName;
  2230. File desc = new File(downloadPath);
  2231. if (!desc.getParentFile().exists()) {
  2232. desc.getParentFile().mkdirs();
  2233. }
  2234. return downloadPath;
  2235. }
  2236. }