TFeeServiceImpl.java 89 KB

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