TFeeServiceImpl.java 104 KB

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