TFeeServiceImpl.java 95 KB

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