TFeeServiceImpl.java 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102
  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.*;
  35. import com.ruoyi.reportManagement.dto.TWarehousebill;
  36. import com.ruoyi.reportManagement.excel.Profit;
  37. import com.ruoyi.reportManagement.excel.Receivable;
  38. import com.ruoyi.shipping.domain.TAccount;
  39. import com.ruoyi.shipping.domain.TFeeInvoice;
  40. import com.ruoyi.shipping.domain.TVessel;
  41. import com.ruoyi.shipping.domain.TVoyage;
  42. import com.ruoyi.shipping.excel.Account;
  43. import com.ruoyi.shipping.excel.ExportFinancial;
  44. import com.ruoyi.shipping.mapper.TFeeInvoiceMapper;
  45. import com.ruoyi.shipping.mapper.TVesselMapper;
  46. import com.ruoyi.shipping.mapper.TVoyageMapper;
  47. import com.ruoyi.system.domain.SysConfig;
  48. import com.ruoyi.system.mapper.SysConfigMapper;
  49. import com.ruoyi.system.mapper.SysDictDataMapper;
  50. import com.ruoyi.system.service.ISysDictDataService;
  51. import com.ruoyi.warehouseBusiness.domain.BillnoDel;
  52. import com.ruoyi.warehouseBusiness.domain.TWarehouseBills;
  53. import com.ruoyi.warehouseBusiness.domain.TWarehousebillsfees;
  54. import com.ruoyi.warehouseBusiness.domain.enums.FeesTypeEnum;
  55. import com.ruoyi.warehouseBusiness.domain.enums.WarehouseTypeEnum;
  56. import com.ruoyi.warehouseBusiness.excel.ListMapToBeanUtils;
  57. import com.ruoyi.warehouseBusiness.excel.TWareHouseExcelItem;
  58. import com.ruoyi.warehouseBusiness.mapper.BillnoDelMapper;
  59. import com.ruoyi.warehouseBusiness.mapper.TWarehouseBillsMapper;
  60. import com.ruoyi.warehouseBusiness.mapper.TWarehousebillsfeesMapper;
  61. import com.ruoyi.warehouseBusiness.service.impl.BillnoSerialServiceImpl;
  62. import org.apache.commons.compress.utils.Lists;
  63. import org.apache.poi.hssf.usermodel.*;
  64. import org.apache.poi.ss.util.CellRangeAddress;
  65. import org.springframework.beans.BeanUtils;
  66. import org.springframework.beans.factory.annotation.Autowired;
  67. import org.springframework.stereotype.Service;
  68. import org.springframework.transaction.annotation.Transactional;
  69. import org.springframework.transaction.interceptor.TransactionAspectSupport;
  70. import java.io.File;
  71. import java.io.FileOutputStream;
  72. import java.io.OutputStream;
  73. import java.math.BigDecimal;
  74. import java.text.SimpleDateFormat;
  75. import java.util.*;
  76. import java.util.stream.Collectors;
  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 (!fBilltype.equals(FeesTypeEnum.INVOICE.getType())) {
  669. if ("DZ".equals(fBilltype)) {
  670. actId = 210L;
  671. key = "warehouse.contrast.ApprovalFlow";
  672. } else if ("SF".equals(fBilltype)) {
  673. actId = 220L;
  674. key = "warehouse.charge.ApprovalFlow";
  675. } else if ("FF".equals(fBilltype)) {
  676. actId = 230L;
  677. key = "warehouse.payment.ApprovalFlow";
  678. } else if ("KHDZ".equals(fBilltype)) {
  679. actId = 430L;
  680. key = "warehouse.kaiHeContrast.ApprovalFlow";
  681. } else if ("KHSF".equals(fBilltype)) {
  682. actId = 440L;
  683. key = "warehouse.kaiHeCharge.ApprovalFlow";
  684. } else if ("KHFF".equals(fBilltype)) {
  685. actId = 450L;
  686. key = "warehouse.kaiHePayment.ApprovalFlow";
  687. }
  688. SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique(key);
  689. if (StringUtils.isNull(sysConfig)) {
  690. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  691. return AjaxResult.error("系统参数异常,未找到开启审批流参数");
  692. }
  693. if ("0".equals(sysConfig.getConfigValue())) {
  694. isApprove = true;
  695. }
  696. }
  697. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  698. String billstatus = "";
  699. if (isApprove) {
  700. billstatus = "4";
  701. } else {
  702. billstatus = "6";
  703. }
  704. if (StringUtils.isNull(tFee.getfId())) {
  705. // 如果是新数据
  706. tFee.setCreateBy(loginUser.getUser().getUserName());
  707. tFee.setfDeptid(loginUser.getUser().getDeptId());
  708. tFee.setfBilltype(fBilltype);
  709. tFee.setfBillstatus(billstatus);
  710. // 业务编码
  711. Date time = new Date();
  712. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  713. tFee.setfBillno(billNo);
  714. tFeeMapper.insertTFee(tFee);
  715. } else {
  716. tFee.setUpdateBy(loginUser.getUser().getUserName());
  717. tFee.setUpdateTime(new Date());
  718. tFee.setfBillstatus(billstatus);
  719. tFeeMapper.updateTFee(tFee);
  720. }
  721. // 删除从表
  722. tFeeDoMapper.deleteByFPid(tFee.getfId());
  723. messageMap.put("tFee", tFee);
  724. // 财务从表
  725. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  726. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  727. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  728. for (TFeeDo tFeeDo : tFeeDoList) {
  729. Map<String, Object> map = this.judgeMoney(tFeeDo.getfSrcid(), tFeeDo.getfAmt(), fBilltype, tFeeDo.getfFeeid());
  730. if (!(Boolean) map.get("flag")) {
  731. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  732. return AjaxResult.error(map.get("message").toString());
  733. }
  734. tFeeDo.setfPid(tFee.getfId());
  735. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  736. tFeeDo.setCreateTime(new Date());
  737. tFeeDo.setfStatus(billstatus);
  738. tFeeDoMapper.insertTFeeDo(tFeeDo);
  739. }
  740. }
  741. // 这里加个判断取系统参数来确定是否需要启用审批流
  742. if (isApprove) {
  743. AuditItems auditItems = new AuditItems();
  744. auditItems.setLevelId(0L);
  745. auditItems.setBillId(tFee.getfId());
  746. auditItems.setActId(actId);
  747. auditItems.setIffinalItem("F");
  748. auditItems.setBillNo(tFee.getfBillno()); // 业务编号
  749. auditItems.setRefno1(String.valueOf(tFee.getfCorpid())); // 货权方
  750. auditItems.setRefno2(fBilltype);// 财务类型
  751. auditItems.setRefno3(tFee.gettMblno());// 提单号
  752. auditItems.setSendUserId(loginUser.getUser().getUserId());
  753. auditItems.setSendName(loginUser.getUsername());
  754. auditItems.setSendTime(new Date());
  755. auditItems.setAuditUserId(loginUser.getUser().getUserId());
  756. auditItems.setAuditItem(new Date());
  757. auditItems.setAuditOpTime(new Date());
  758. auditItems.setFidStatus("f_billstatus");
  759. auditItems.setTimes(1L);
  760. auditItems.setAuditMsg("提交");
  761. auditItems.setAuditStatus("O");
  762. AjaxResult approvalFlow = auditItemsService.createApprovalFlow(auditItems);
  763. Long code = Long.valueOf(String.valueOf(approvalFlow.get("code"))).longValue();
  764. if (code.equals(500L)) {
  765. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  766. return AjaxResult.error("发票申请提交审核失败,请找管理员");
  767. }
  768. } else {
  769. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  770. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  771. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  772. for (TFeeDo tFeeDo : tFeeDoList) {
  773. // 跟新费用明细
  774. int m = updateBillsFees(tFee.getfId(), tFeeDo, fBilltype);
  775. if (m == 0) {
  776. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  777. return AjaxResult.error("更新费用明细失败");
  778. }
  779. }
  780. }
  781. AjaxResult ajaxResult = tfeeFollow(tFee.getfId(), 6L);
  782. Long code = Long.valueOf(String.valueOf(ajaxResult.get("code"))).longValue();
  783. if (code.equals(500L)) {
  784. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  785. return AjaxResult.error("发票申请提交审核失败,请找管理员");
  786. }
  787. }
  788. return AjaxResult.success("成功", messageMap);
  789. }
  790. @Override
  791. @Transactional
  792. public AjaxResult webVersionConfirm(Long[] fIds, String billsType, LoginUser loginUser) {
  793. String key = "";
  794. boolean isApprove = false;
  795. long actId = 0L;
  796. if ("DZ".equals(billsType)) {
  797. actId = 210L;
  798. key = "warehouse.contrast.ApprovalFlow";
  799. } else if ("SF".equals(billsType)) {
  800. actId = 220L;
  801. key = "warehouse.charge.ApprovalFlow";
  802. } else if ("FF".equals(billsType)) {
  803. actId = 230L;
  804. key = "warehouse.payment.ApprovalFlow";
  805. } else if ("KHDZ".equals(billsType)) {
  806. actId = 430L;
  807. key = "warehouse.kaiHeContrast.ApprovalFlow";
  808. } else if ("KHSF".equals(billsType)) {
  809. actId = 440L;
  810. key = "warehouse.kaiHeCharge.ApprovalFlow";
  811. } else if ("KHFF".equals(billsType)) {
  812. actId = 450L;
  813. key = "warehouse.kaiHePayment.ApprovalFlow";
  814. }
  815. SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique(key);
  816. if (StringUtils.isNull(sysConfig)) {
  817. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  818. return AjaxResult.error("系统参数异常,未找到开启审批流参数");
  819. }
  820. if ("0".equals(sysConfig.getConfigValue())) {
  821. isApprove = true;
  822. }
  823. String billStatus = null;
  824. if (isApprove) {
  825. billStatus = "4";
  826. } else {
  827. billStatus = "6";
  828. }
  829. for (Long fId : fIds) {
  830. TFee tFee = tFeeMapper.selectTFeeById(fId);
  831. if (tFee == null) {
  832. return AjaxResult.error("对账数据有误请确认");
  833. }
  834. boolean change = this.change(tFee.getfId());
  835. if (change == false) {
  836. return AjaxResult.error("数据正在审批或审批通过,不允许提交审核");
  837. }
  838. //更新主表数据状态
  839. TFee fee = new TFee();
  840. fee.setfId(fId);
  841. fee.setfBillstatus(billStatus);
  842. int i = tFeeMapper.updateTFee(fee);
  843. //更新从表数据状态
  844. int update = tFeeDoMapper.tfeeDoFollowUpdate(fId, Long.valueOf(billStatus));
  845. if (isApprove) {
  846. AuditItems auditItems = new AuditItems();
  847. auditItems.setLevelId(0L);
  848. auditItems.setBillId(tFee.getfId());
  849. auditItems.setActId(actId);
  850. auditItems.setIffinalItem("F");
  851. auditItems.setBillNo(tFee.getfBillno()); // 业务编号
  852. auditItems.setRefno1(String.valueOf(tFee.getfCorpid())); // 货权方
  853. auditItems.setRefno2(billsType);// 财务类型
  854. auditItems.setRefno3(tFee.gettMblno());// 提单号
  855. auditItems.setSendUserId(loginUser.getUser().getUserId());
  856. auditItems.setSendName(loginUser.getUsername());
  857. auditItems.setSendTime(new Date());
  858. auditItems.setAuditUserId(loginUser.getUser().getUserId());
  859. auditItems.setAuditItem(new Date());
  860. auditItems.setAuditOpTime(new Date());
  861. auditItems.setFidStatus("f_billstatus");
  862. auditItems.setTimes(1L);
  863. auditItems.setAuditMsg("提交");
  864. auditItems.setAuditStatus("O");
  865. AjaxResult approvalFlow = auditItemsService.createApprovalFlow(auditItems);
  866. Long code = Long.valueOf(String.valueOf(approvalFlow.get("code"))).longValue();
  867. if (code.equals(500L)) {
  868. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  869. }
  870. return approvalFlow;
  871. } else {
  872. TFeeDo tFeeDo = new TFeeDo();
  873. tFeeDo.setfPid(fId);
  874. List<TFeeDo> tFeeDoList = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  875. for (TFeeDo feeDo : tFeeDoList) {
  876. // 跟新费用明细
  877. int m = updateBillsFees(fId, feeDo, billsType);
  878. if (m == 0) {
  879. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  880. return AjaxResult.error("更新费用明细失败");
  881. }
  882. }
  883. }
  884. AjaxResult ajaxResult = tfeeFollow(tFee.getfId(), 6L);
  885. Long code = Long.valueOf(String.valueOf(ajaxResult.get("code"))).longValue();
  886. return ajaxResult;
  887. }
  888. return AjaxResult.success();
  889. }
  890. @Override
  891. @Transactional
  892. public AjaxResult confirmKaiHe(String tfee, String tfeeDo, String tFeeInvoice, LoginUser loginUser, String fBilltype) {
  893. Long fPid = null;
  894. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  895. Map<String, Object> messageMap = new HashMap<>();
  896. String key = "";
  897. boolean isApprove = false;
  898. long actId = 0L;
  899. String billStatus = "";
  900. if ("DZ".equals(fBilltype)) {
  901. actId = 210L;
  902. key = "warehouse.contrast.ApprovalFlow";
  903. } else if ("SF".equals(fBilltype)) {
  904. actId = 220L;
  905. key = "warehouse.charge.ApprovalFlow";
  906. } else if ("FF".equals(fBilltype)) {
  907. actId = 230L;
  908. key = "warehouse.payment.ApprovalFlow";
  909. } else if ("KHDZ".equals(fBilltype)) {
  910. actId = 430L;
  911. key = "warehouse.kaiHeContrast.ApprovalFlow";
  912. } else if ("KHSF".equals(fBilltype)) {
  913. actId = 440L;
  914. key = "warehouse.kaiHeCharge.ApprovalFlow";
  915. } else if ("KHFF".equals(fBilltype)) {
  916. actId = 450L;
  917. key = "warehouse.kaiHePayment.ApprovalFlow";
  918. } else if ("ApplyFP".equals(fBilltype)) {
  919. actId = 470L;
  920. key = "warehouse.kaiHeApplyFP.ApprovalFlow";
  921. }
  922. SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique(key);
  923. if (StringUtils.isNull(sysConfig)) {
  924. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  925. return AjaxResult.error("系统参数异常,未找到开启审批流参数");
  926. }
  927. if ("0".equals(sysConfig.getConfigValue())) {
  928. isApprove = true;
  929. }
  930. if (isApprove) {
  931. billStatus = "4";
  932. } else {
  933. billStatus = "6";
  934. }
  935. if (StringUtils.isNull(tFee.getfId())) {
  936. // 如果是新数据
  937. tFee.setCreateBy(loginUser.getUser().getUserName());
  938. tFee.setfDeptid(loginUser.getUser().getDeptId());
  939. tFee.setfBilltype(fBilltype);
  940. // 业务编码
  941. Date time = new Date();
  942. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  943. tFee.setfBillno(billNo);
  944. tFee.setfBillstatus(billStatus);
  945. tFeeMapper.insertTFee(tFee);
  946. fPid = tFee.getfId();
  947. } else {
  948. fPid = tFee.getfId();
  949. boolean change = this.change(fPid);
  950. if (!change) {
  951. return AjaxResult.error("当前数据不支持修改");
  952. }
  953. tFee.setUpdateBy(loginUser.getUser().getUserName());
  954. tFee.setUpdateTime(new Date());
  955. tFee.setfBillstatus(billStatus);
  956. tFeeMapper.updateTFee(tFee);
  957. // 删除从表
  958. tFeeDoMapper.deleteByFPid(tFee.getfId());
  959. //删除开票从表
  960. tFeeInvoiceMapper.deleteByFPid(tFee.getfId());
  961. }
  962. messageMap.put("tFee", tFee);
  963. // 财务从表
  964. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  965. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  966. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  967. for (TFeeDo tFeeDo : tFeeDoList) {
  968. Map<String, Object> map = this.judgeMoney(tFeeDo.getfSrcid(), tFeeDo.getfAmt(), fBilltype, tFeeDo.getfFeeid());
  969. boolean b = (Boolean) map.get("flag");
  970. if (b == false) {
  971. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  972. return AjaxResult.error(map.get("message").toString());
  973. }
  974. tFeeDo.setfPid(tFee.getfId());
  975. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  976. tFeeDo.setCreateTime(new Date());
  977. tFeeDo.setfStatus(billStatus);
  978. tFeeDoMapper.insertTFeeDo(tFeeDo);
  979. }
  980. }
  981. if (!"".equals(tFeeInvoice) && tFeeInvoice != null && !"null".equals(tFeeInvoice)) {
  982. JSONArray jsonDrArray = JSONArray.parseArray(tFeeInvoice);
  983. List<TFeeInvoice> tFeeInvoiceList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeInvoice.class);
  984. for (TFeeInvoice feeInvoice : tFeeInvoiceList) {
  985. feeInvoice.setfPid(fPid);
  986. feeInvoice.setCreateBy(loginUser.getUser().getUserName());
  987. feeInvoice.setCreateTime(new Date());
  988. feeInvoice.setfBillstatus(billStatus);
  989. tFeeInvoiceMapper.insertTFeeInvoice(feeInvoice);
  990. }
  991. }
  992. // 这里加个判断取系统参数来确定是否需要启用审批流
  993. if (isApprove) {
  994. AuditItems auditItems = new AuditItems();
  995. auditItems.setLevelId(0L);
  996. auditItems.setBillId(tFee.getfId());
  997. auditItems.setActId(actId);
  998. auditItems.setIffinalItem("F");
  999. auditItems.setBillNo(tFee.getfBillno()); // 业务编号
  1000. auditItems.setRefno1(String.valueOf(tFee.getfCorpid())); // 货权方
  1001. auditItems.setRefno2(fBilltype);// 财务类型
  1002. auditItems.setRefno3(tFee.gettMblno());// 提单号
  1003. auditItems.setSendUserId(loginUser.getUser().getUserId());
  1004. auditItems.setSendName(loginUser.getUsername());
  1005. auditItems.setSendTime(new Date());
  1006. auditItems.setAuditUserId(loginUser.getUser().getUserId());
  1007. auditItems.setAuditItem(new Date());
  1008. auditItems.setAuditOpTime(new Date());
  1009. auditItems.setFidStatus("f_billstatus");
  1010. auditItems.setTimes(1L);
  1011. auditItems.setAuditMsg("提交");
  1012. auditItems.setAuditStatus("O");
  1013. AjaxResult approvalFlow = auditItemsService.createApprovalFlow(auditItems);
  1014. Long code = Long.valueOf(String.valueOf(approvalFlow.get("code"))).longValue();
  1015. if (code.equals(500L)) {
  1016. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1017. return AjaxResult.error("发票申请提交审核失败,请找管理员");
  1018. }
  1019. } else {
  1020. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  1021. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  1022. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  1023. for (TFeeDo tFeeDo : tFeeDoList) {
  1024. // 跟新费用明细
  1025. int m = updateBillsFees(tFee.getfId(), tFeeDo, fBilltype);
  1026. if (m == 0) {
  1027. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1028. return AjaxResult.error("更新费用明细失败");
  1029. }
  1030. }
  1031. }
  1032. AjaxResult ajaxResult = tfeeFollow(tFee.getfId(), 6L);
  1033. Long code = Long.valueOf(String.valueOf(ajaxResult.get("code"))).longValue();
  1034. if (code.equals(500L)) {
  1035. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1036. return AjaxResult.error("发票申请提交审核失败,请找管理员");
  1037. }
  1038. }
  1039. return AjaxResult.success("成功", messageMap);
  1040. }
  1041. /**
  1042. * 根据财务主表id 更新对应明细表状态
  1043. *
  1044. * @param fPid 财务主表id
  1045. * @return 结果
  1046. */
  1047. @Transactional
  1048. public AjaxResult tfeeFollow(Long fPid, long fettle) {
  1049. if (StringUtils.isNull(fPid)) {
  1050. return AjaxResult.error("财务更新状态未找到主表信息,请与管理员联系");
  1051. }
  1052. TFee tFee = new TFee();
  1053. tFee.setfId(fPid);
  1054. tFee.setfBillstatus(String.valueOf(fettle));
  1055. int tFeeUpdateResult = tFeeMapper.updateTFee(tFee);
  1056. if (tFeeUpdateResult <= 0) {
  1057. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1058. return AjaxResult.error("更新财务明细状态失败,请联系管理员");
  1059. }
  1060. try {
  1061. int itemUpdateResult = tFeeDoMapper.tfeeDoFollowUpdate(fPid, fettle);
  1062. } catch (Exception exception) {
  1063. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1064. return AjaxResult.error("更新财务明细状态失败,请联系管理员");
  1065. }
  1066. TFeeInvoice invoice = new TFeeInvoice();
  1067. invoice.setfPid(fPid);
  1068. List<TFeeInvoice> tFeeInvoiceList = tFeeInvoiceMapper.selectTFeeInvoiceList(invoice);
  1069. if (CollectionUtils.isNotEmpty(tFeeInvoiceList)) {
  1070. try {
  1071. int itemUpdateResult = tFeeInvoiceMapper.tFeeInvoiceUpdate(fPid, fettle);
  1072. } catch (Exception exception) {
  1073. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1074. return AjaxResult.error("更新开票明细状态失败,请联系管理员");
  1075. }
  1076. }
  1077. return AjaxResult.success();
  1078. }
  1079. @Transactional
  1080. public AjaxResult billsfeesFollow(Long fPid) {
  1081. if (StringUtils.isNull(fPid)) {
  1082. return AjaxResult.error("费用明细更新状态未找到主表信息,请与管理员联系");
  1083. }
  1084. TFee tFee = tFeeMapper.selectTFeeById(fPid);
  1085. // 查询从表数据
  1086. TFeeDo tFeeDo = new TFeeDo();
  1087. tFeeDo.setfPid(fPid);
  1088. List<TFeeDo> tFeeDoList = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  1089. for (TFeeDo tFeeDo1 : tFeeDoList) {
  1090. // 跟新费用明细
  1091. Map<String, Object> map = this.judgeMoney(tFeeDo1.getfSrcid(), tFeeDo1.getfAmt(), tFee.getfBilltype(), tFeeDo1.getfFeeid());
  1092. if (!(Boolean) map.get("flag")) {
  1093. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1094. return AjaxResult.error(map.get("message").toString());
  1095. }
  1096. int m = updateBillsFees(fPid, tFeeDo1, tFee.getfBilltype());
  1097. if (m == 0) {
  1098. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1099. return AjaxResult.error("更新费用明细失败");
  1100. }
  1101. }
  1102. return AjaxResult.success();
  1103. }
  1104. @Override
  1105. @Transactional
  1106. public AjaxResult revoke(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  1107. // 更新 主表、从表
  1108. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  1109. if ("DZApplyFP".equals(fBilltype)) {
  1110. TFee fee = tFeeMapper.selectTFeeById(tFee.getfId());
  1111. if (fee.getfMake() == 1) {
  1112. return AjaxResult.error("该申请发票已开销项发票,不能撤销");
  1113. }
  1114. }
  1115. tFee.setUpdateBy(loginUser.getUser().getUserName());
  1116. tFee.setUpdateTime(new Date());
  1117. tFeeMapper.updateTFee(tFee);
  1118. // 删除从表
  1119. tFeeDoMapper.deleteByFPid(tFee.getfId());
  1120. // 财务从表
  1121. if (StringUtils.isNotNull(tfeeDo)) {
  1122. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  1123. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  1124. for (TFeeDo tFeeDo : tFeeDoList) {
  1125. tFeeDo.setfPid(tFee.getfId());
  1126. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  1127. tFeeDo.setCreateTime(new Date());
  1128. tFeeDoMapper.insertTFeeDo(tFeeDo);
  1129. // 跟新费用明细
  1130. int m = updateBillsFees(tFee.getfId(), tFeeDo, fBilltype);
  1131. if (m == 0) {
  1132. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1133. return AjaxResult.error("更新费用明细失败");
  1134. }
  1135. }
  1136. }
  1137. return AjaxResult.success();
  1138. }
  1139. @Override
  1140. public AjaxResult queryRemove(Long fId) {
  1141. TFee tFee = tFeeMapper.selectTFeeById(fId);
  1142. TFeeDo tFeeDo = new TFeeDo();
  1143. tFeeDo.setfPid(tFee.getfId());
  1144. List<TFeeDo> tFeeDoList = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  1145. if (StringUtils.isNull(tFee)) {
  1146. return AjaxResult.success("0");
  1147. } else if (StringUtils.isNotNull(tFee) && StringUtils.isEmpty(tFeeDoList)) {
  1148. return AjaxResult.success("1");
  1149. } else if (tFee.getfBilltype().equals("INV") && tFee.getfAccountId() != null) {
  1150. return AjaxResult.success("3");
  1151. } else {
  1152. return AjaxResult.success("2");
  1153. }
  1154. }
  1155. @Override
  1156. @Transactional
  1157. public AjaxResult remove(Long fId) {
  1158. TFee tFee = tFeeMapper.selectTFeeById(fId);
  1159. if ("4".equals(tFee.getfBillstatus())) {
  1160. return AjaxResult.error("数据已提交审批,暂不能删除");
  1161. } else if ("5".equals(tFee.getfBillstatus())) {
  1162. return AjaxResult.error("数据正在审批,暂不能删除");
  1163. } else if ("6".equals(tFee.getfBillstatus())) {
  1164. return AjaxResult.error("数据审批完成,不能删除");
  1165. } else {
  1166. try {
  1167. tFeeMapper.deleteTFeeById(fId);
  1168. tFeeDoMapper.deleteByFPid(fId);
  1169. tFeeInvoiceMapper.deleteByFPid(fId);
  1170. } catch (Exception e) {
  1171. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1172. return AjaxResult.error("删除失败,请找管理员");
  1173. }
  1174. return AjaxResult.success();
  1175. }
  1176. }
  1177. @Override
  1178. public List<TWareHouseExcelItem> selectTWarehousebillsItemsList(Long fId) {
  1179. List<TWareHouseExcelItem> tWareHouseExcelItemList = tFeeMapper.selectTWarehousebillsItemsList(fId);
  1180. List<TWareHouseExcelItem> tWareHouseExcelItemList1 = new ArrayList<>();
  1181. for (TWareHouseExcelItem tWareHouseExcelItem : tWareHouseExcelItemList) {
  1182. if (StringUtils.isNotNull(tWareHouseExcelItem.getfBusinessType())) {
  1183. List<SysDictData> sysDictDataListIn = new ArrayList<>();
  1184. SysDictData sysDictData = new SysDictData();
  1185. if (tWareHouseExcelItem.getfBilltype().equals("入库")) {
  1186. sysDictData.setDictType(ST_IN_TYPE);
  1187. sysDictData.setDictValue(String.valueOf(tWareHouseExcelItem.getfBusinessType()));
  1188. sysDictData.setStatus("0");
  1189. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  1190. } else if (tWareHouseExcelItem.getfBilltype().equals("出库")) {
  1191. sysDictData.setDictType(ST_OUT_TYPE);
  1192. sysDictData.setDictValue(String.valueOf(tWareHouseExcelItem.getfBusinessType()));
  1193. sysDictData.setStatus("0");
  1194. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  1195. } else if (tWareHouseExcelItem.getfBilltype().equals("调拨") | tWareHouseExcelItem.getfBilltype().equals("货物通关")) {
  1196. sysDictData.setDictType(ST_TRANS_TYPE);
  1197. sysDictData.setDictValue(String.valueOf(tWareHouseExcelItem.getfBusinessType()));
  1198. sysDictData.setStatus("0");
  1199. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  1200. }
  1201. if (null != sysDictDataListIn && sysDictDataListIn.size() > 0) {
  1202. tWareHouseExcelItem.setfBusinessType(sysDictDataListIn.get(0).getDictLabel());
  1203. }
  1204. }
  1205. tWareHouseExcelItemList1.add(tWareHouseExcelItem);
  1206. }
  1207. return tWareHouseExcelItemList1;
  1208. }
  1209. @Override
  1210. public String findCtrlcorpid(Long fId) {
  1211. TFee tFee = tFeeMapper.selectTFeeById(fId);
  1212. String exportName = tFee.getfCtrlcorpid() + "-" + tFee.getfBillno();
  1213. return exportName;
  1214. }
  1215. @Override
  1216. public List<Receivable> receivableExport(TWareHouseFees tWareHouseFees) throws Exception {
  1217. List<Map<String, Object>> list = tFeeMapper.warehouseBillsFeesList1(tWareHouseFees);
  1218. List<Receivable> list1 = ListMapToBeanUtils.castMapToBean(list, Receivable.class);
  1219. return list1;
  1220. }
  1221. @Override
  1222. public List<GeneralLedgerExcel> payableExport(TWareHouseFees tWareHouseFees) throws Exception {
  1223. List<GeneralLedgerExcel> ledgerExcelList = new ArrayList<>();
  1224. List<FeeVO> feeVOList = tFeeMapper.selectFinancialLedgerList(tWareHouseFees);
  1225. feeVOList.forEach(vo -> {
  1226. GeneralLedgerExcel ledgerExcel = new GeneralLedgerExcel();
  1227. ledgerExcel.setFAmount(vo.getFAmount());
  1228. ledgerExcel.setFFeesName(vo.getFFeesName());
  1229. ledgerExcel.setNnfinished(vo.getNnfinished());
  1230. ledgerExcel.setFStlamount(vo.getFStlamount());
  1231. ledgerExcelList.add(ledgerExcel);
  1232. });
  1233. return ledgerExcelList;
  1234. }
  1235. @Override
  1236. public List<Profit> profitExport(TWareHouseFees tWareHouseFees) throws Exception {
  1237. List<Map<String, Object>> list = tFeeMapper.warehouseBillsFeesProfitList(tWareHouseFees);
  1238. List<Profit> list1 = ListMapToBeanUtils.castMapToBean(list, Profit.class);
  1239. return list1;
  1240. }
  1241. @Override
  1242. public List<Contrast> contrastExport(TFee tFee) throws Exception {
  1243. List<Map<String, Object>> list = tFeeMapper.selectTFeeList1(tFee);
  1244. List<Contrast> list1 = ListMapToBeanUtils.castMapToBean(list, Contrast.class);
  1245. return list1;
  1246. }
  1247. @Override
  1248. public List<Payment> paymentExport(TFee tFee) throws Exception {
  1249. List<Map<String, Object>> list = tFeeMapper.selectFeeList(tFee);
  1250. return ListMapToBeanUtils.castMapToBean(list, Payment.class);
  1251. }
  1252. @Override
  1253. public List<Charge> chargeExport(TFee tFee) throws Exception {
  1254. List<Map<String, Object>> list = tFeeMapper.selectFeeList(tFee);
  1255. return ListMapToBeanUtils.castMapToBean(list, Charge.class);
  1256. }
  1257. @Override
  1258. public List<Account> accountExport(TFee tFee) throws Exception {
  1259. List<Map<String, Object>> list = tFeeMapper.webVersionTFee(tFee);
  1260. return ListMapToBeanUtils.castMapToBean(list, Account.class);
  1261. }
  1262. @Override
  1263. public List<Detailed> selectDetailedList(Long fId) {
  1264. List<Detailed> detailedList = tFeeMapper.selectDetailedList(fId);
  1265. List<Detailed> detailedList1 = new ArrayList<>();
  1266. for (Detailed tWareHouseExcelItem : detailedList) {
  1267. if (StringUtils.isNotNull(tWareHouseExcelItem.getfBusinessType())) {
  1268. List<SysDictData> sysDictDataListIn = new ArrayList<>();
  1269. SysDictData sysDictData = new SysDictData();
  1270. if (tWareHouseExcelItem.getfBilltype().equals("入库")) {
  1271. sysDictData.setDictType(ST_IN_TYPE);
  1272. sysDictData.setDictValue(String.valueOf(tWareHouseExcelItem.getfBusinessType()));
  1273. sysDictData.setStatus("0");
  1274. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  1275. } else if (tWareHouseExcelItem.getfBilltype().equals("出库")) {
  1276. sysDictData.setDictType(ST_OUT_TYPE);
  1277. sysDictData.setDictValue(String.valueOf(tWareHouseExcelItem.getfBusinessType()));
  1278. sysDictData.setStatus("0");
  1279. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  1280. } else if (tWareHouseExcelItem.getfBilltype().equals("调拨") | tWareHouseExcelItem.getfBilltype().equals("货物通关")) {
  1281. sysDictData.setDictType(ST_TRANS_TYPE);
  1282. sysDictData.setDictValue(String.valueOf(tWareHouseExcelItem.getfBusinessType()));
  1283. sysDictData.setStatus("0");
  1284. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  1285. }
  1286. if (CollectionUtils.isNotEmpty(sysDictDataListIn)) {
  1287. tWareHouseExcelItem.setfBusinessType(sysDictDataListIn.get(0).getDictLabel());
  1288. }
  1289. }
  1290. detailedList1.add(tWareHouseExcelItem);
  1291. }
  1292. return detailedList1;
  1293. }
  1294. @Override
  1295. public List<Map<String, Object>> selectdetailedList(TWarehousebill tWarehousebill) {
  1296. return tFeeMapper.selectDetailedList1(tWarehousebill);
  1297. }
  1298. /**
  1299. * 更新费用明细
  1300. *
  1301. * @param fid
  1302. * @param tFeeDo
  1303. * @param billsType
  1304. * @return
  1305. */
  1306. @Transactional
  1307. public int updateBillsFees(Long fid, TFeeDo tFeeDo, String billsType) {
  1308. // 查询从表数据
  1309. TFee tFee = tFeeMapper.selectTFeeById(fid);
  1310. if (billsType.equals("SF") || billsType.equals("FF")
  1311. || billsType.equals("KHSF") || billsType.equals("KHFF")) {
  1312. billsType = "DC";
  1313. }
  1314. Map<String, Object> map = new HashMap<>();
  1315. map.put("tFee", tFee);
  1316. map.put("billType", billsType);
  1317. map.put("tFeeDo", tFeeDo);
  1318. return tWarehousebillsfeesMapper.updateTWarehousebillsfee(map);
  1319. }
  1320. public boolean change(Long fId) {
  1321. boolean flag = false;
  1322. TFee tFee = tFeeMapper.selectTFeeById(fId);
  1323. if ("4".equals(tFee.getfBillstatus())
  1324. || "5".equals(tFee.getfBillstatus())
  1325. || "6".equals(tFee.getfBillstatus())) {
  1326. flag = false;
  1327. } else {
  1328. flag = true;
  1329. }
  1330. return flag;
  1331. }
  1332. @Override
  1333. @Transactional
  1334. public AjaxResult webVersionSubmitApplyFP(TFee tFee, LoginUser loginUser, String fBilltype) {
  1335. String key = "";
  1336. boolean isApprove = false;
  1337. long actId = 0L;
  1338. String billStatus = "";
  1339. if ("ApplyFP".equals(fBilltype)) {
  1340. actId = 470L;
  1341. key = "warehouse.kaiHeApplyFP.ApprovalFlow";
  1342. }
  1343. SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique(key);
  1344. if (StringUtils.isNull(sysConfig)) {
  1345. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1346. return AjaxResult.error("系统参数异常,未找到开启审批流参数");
  1347. }
  1348. if ("0".equals(sysConfig.getConfigValue())) {
  1349. isApprove = true;
  1350. }
  1351. if (isApprove) {
  1352. billStatus = "4";
  1353. } else {
  1354. billStatus = "6";
  1355. }
  1356. /*for (Long getfId : tFee.getfIds()) {*/
  1357. TFee fee = tFeeMapper.selectTFeeById(tFee.getfId());
  1358. if (fee == null) {
  1359. return AjaxResult.error("财务主表数据有误,请确认");
  1360. }
  1361. boolean change = this.change(tFee.getfId());
  1362. if (change == false) {
  1363. return AjaxResult.error("数据正在审批或审批通过,不允许提交审核");
  1364. }
  1365. fee.setfId(tFee.getfId());
  1366. fee.setfBillstatus(billStatus);
  1367. fee.setUpdateBy(loginUser.getUser().getUserName());
  1368. fee.setUpdateTime(new Date());
  1369. int updateTFee = tFeeMapper.updateTFee(fee);
  1370. if (updateTFee <= 0) {
  1371. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1372. return AjaxResult.error("更新财务主表数据出错,请找管理员");
  1373. }
  1374. TFeeDo tFeeDo = new TFeeDo();
  1375. tFeeDo.setfPid(tFee.getfId());
  1376. List<TFeeDo> tFeeDos = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  1377. if (CollectionUtils.isEmpty(tFeeDos)) {
  1378. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1379. return AjaxResult.error("财务从表数据有误,请确认");
  1380. }
  1381. for (TFeeDo feeDo : tFeeDos) {
  1382. feeDo.setfId(feeDo.getfId());
  1383. feeDo.setfStatus(billStatus);
  1384. feeDo.setUpdateBy(loginUser.getUser().getUserName());
  1385. feeDo.setUpdateTime(new Date());
  1386. int i = tFeeDoMapper.updateTFeeDo(feeDo);
  1387. if (i <= 0) {
  1388. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1389. return AjaxResult.error("更新财务主表数据出错,请找管理员");
  1390. }
  1391. }
  1392. TFeeInvoice tFeeInvoice = new TFeeInvoice();
  1393. tFeeInvoice.setfPid(tFee.getfId());
  1394. List<TFeeInvoice> tFeeInvoiceList = tFeeInvoiceMapper.selectTFeeInvoiceList(tFeeInvoice);
  1395. if (CollectionUtils.isNotEmpty(tFeeInvoiceList)) {
  1396. for (TFeeInvoice invoice : tFeeInvoiceList) {
  1397. tFeeInvoice.setfBillstatus(billStatus);
  1398. tFeeInvoice.setfId(invoice.getfId());
  1399. tFeeInvoice.setUpdateBy(loginUser.getUser().getUserName());
  1400. tFeeInvoice.setUpdateTime(new Date());
  1401. tFeeInvoiceMapper.updateTFeeInvoice(tFeeInvoice);
  1402. }
  1403. }
  1404. //添加审批流
  1405. if (isApprove) {
  1406. AuditItems auditItems = new AuditItems();
  1407. auditItems.setLevelId(0L);
  1408. auditItems.setBillId(fee.getfId());
  1409. auditItems.setActId(actId);
  1410. auditItems.setIffinalItem("F");
  1411. auditItems.setBillNo(fee.getfBillno()); // 业务编号
  1412. auditItems.setRefno1(String.valueOf(fee.getfCorpid())); // 货权方
  1413. auditItems.setRefno2(fee.getfBilltype());// 财务类型
  1414. auditItems.setRefno3(fee.gettMblno());// 提单号
  1415. auditItems.setSendUserId(loginUser.getUser().getUserId());
  1416. auditItems.setSendName(loginUser.getUsername());
  1417. auditItems.setSendTime(new Date());
  1418. auditItems.setAuditUserId(loginUser.getUser().getUserId());
  1419. auditItems.setAuditItem(new Date());
  1420. auditItems.setAuditOpTime(new Date());
  1421. auditItems.setFidStatus("f_billstatus");
  1422. auditItems.setTimes(1L);
  1423. auditItems.setAuditMsg("提交");
  1424. auditItems.setAuditStatus("O");
  1425. AjaxResult approvalFlow = auditItemsService.createApprovalFlow(auditItems);
  1426. Long code = Long.valueOf(String.valueOf(approvalFlow.get("code"))).longValue();
  1427. if (code.equals(500L)) {
  1428. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1429. return AjaxResult.error("提交审核失败,请找管理员");
  1430. }
  1431. return approvalFlow;
  1432. } else {
  1433. for (TFeeDo t : tFeeDos) {
  1434. // 跟新费用明细
  1435. int m = updateBillsFees(tFee.getfId(), t, fBilltype);
  1436. if (m == 0) {
  1437. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1438. return AjaxResult.error("更新费用明细失败");
  1439. }
  1440. }
  1441. AjaxResult ajaxResult = tfeeFollow(tFee.getfId(), 6L);
  1442. Long code = Long.valueOf(String.valueOf(ajaxResult.get("code"))).longValue();
  1443. if (code.equals(500L)) {
  1444. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1445. return AjaxResult.error("提交审核失败,请找管理员");
  1446. }
  1447. return ajaxResult;
  1448. }
  1449. /*}*/
  1450. //return AjaxResult.success();
  1451. }
  1452. @Override
  1453. public AjaxResult webVersionUpdateApplyFP(TFee tFee, LoginUser loginUser, String billType) {
  1454. TFeeInvoice tFeeInvoice = tFee.gettFeeInvoice();
  1455. tFeeInvoice.setfPid(tFee.getfId());
  1456. int i = 0;
  1457. if (tFeeInvoice.getfId() != null) {
  1458. tFeeInvoice.setUpdateBy(loginUser.getUser().getUserName());
  1459. tFeeInvoice.setUpdateTime(new Date());
  1460. i = tFeeInvoiceMapper.updateTFeeInvoice(tFeeInvoice);
  1461. } else {
  1462. return AjaxResult.error("开票信息为空,请找管理员");
  1463. }
  1464. if (i <= 0) {
  1465. return AjaxResult.error("更新数据失败,请找管理员");
  1466. } else {
  1467. return AjaxResult.success();
  1468. }
  1469. }
  1470. @Override
  1471. public List<FinancialTFee> selectFinancialTFeeList(TFee tFee) {
  1472. return tFeeMapper.selectFinancialTFeeList(tFee);
  1473. }
  1474. @Override
  1475. public List<Map<String, Object>> FinancialFeesList(TWareHouseFees tWareHouseFees) {
  1476. Map<String, Object> map = new HashMap<>();
  1477. map.put("tWareHouseFees", tWareHouseFees);
  1478. return tFeeMapper.FinancialFeesList(map);
  1479. }
  1480. @Override
  1481. public Map<String, Object> selectFinancialTFeeId(Long fId) {
  1482. Map<String, Object> map = new HashMap<>();
  1483. FinancialTFee financialTFee = tFeeMapper.selectFinancialTFeeId(fId);
  1484. List<FinancialTFeeDoExcel> financialTFeeDoExcels = tFeeDoMapper.selectFinancialTFeeDo(fId);
  1485. map.put("tFee", financialTFee);
  1486. map.put("tFeeDo", financialTFeeDoExcels);
  1487. return map;
  1488. }
  1489. @Override
  1490. public List<FinancialTFeeDoExcel> FinancialTFeeDoExcel(Long fId) {
  1491. return tFeeDoMapper.selectFinancialTFeeDo(fId);
  1492. }
  1493. @Override
  1494. @Transactional
  1495. public AjaxResult webVersionApplyFP(TFee tFee, LoginUser loginUser, String fBilltype, TFeeInvoice tFeeInvoice) {
  1496. Long fPid = null;
  1497. String billStatus = "2";
  1498. try {
  1499. /*for (Long getfId : tFee.getfIds()) {*/
  1500. TFee account = new TFee();
  1501. TFee fee = tFeeMapper.selectTFeeById(tFee.getfId());
  1502. if (fee == null) {
  1503. return AjaxResult.error("财务主表数据有误,请确认");
  1504. }
  1505. account.setfId(fee.getfId());
  1506. account.setfMake(1);
  1507. fee.setfBilltype(fBilltype);
  1508. fee.setfBillstatus(billStatus);
  1509. fee.setCreateBy(loginUser.getUser().getUserName());
  1510. fee.setCreateTime(new Date());
  1511. fee.setfDeptid(loginUser.getUser().getDeptId());
  1512. fee.setUpdateBy(null);
  1513. fee.setUpdateTime(null);
  1514. fee.setfInvoiceRise(tFee.getfInvoiceRise());
  1515. fee.setfAccountId(fee.getfId());
  1516. Date time = new Date();
  1517. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  1518. fee.setfBillno(billNo);
  1519. fee.setfAccbilldate(null);
  1520. fee.setfId(null);
  1521. tFeeMapper.insertTFee(fee);
  1522. tFeeMapper.updateTFee(account);
  1523. //修改原来的数据的开票金额
  1524. fPid = fee.getfId();
  1525. TFeeDo tFeeDo = new TFeeDo();
  1526. tFeeDo.setfPid(tFee.getfId());
  1527. List<TFeeDo> tFeeDos = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  1528. if (CollectionUtils.isEmpty(tFeeDos)) {
  1529. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1530. return AjaxResult.error("财务从表数据有误,请确认");
  1531. }
  1532. for (TFeeDo feeDo : tFeeDos) {
  1533. feeDo.setfPid(fPid);
  1534. feeDo.setfStatus(billStatus);
  1535. feeDo.setCreateBy(loginUser.getUser().getUserName());
  1536. feeDo.setCreateTime(new Date());
  1537. feeDo.setUpdateBy(null);
  1538. feeDo.setUpdateTime(null);
  1539. int i = tFeeDoMapper.insertTFeeDo(feeDo);
  1540. }
  1541. tFeeInvoice.setfBillstatus(billStatus);
  1542. tFeeInvoice.setfPid(fPid);
  1543. tFeeInvoice.setCreateBy(loginUser.getUser().getUserName());
  1544. tFeeInvoice.setCreateTime(new Date());
  1545. tFeeInvoiceMapper.insertTFeeInvoice(tFeeInvoice);
  1546. /*}*/
  1547. } catch (Exception e) {
  1548. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1549. return AjaxResult.error("申请发票出错,请找管理员");
  1550. }
  1551. return AjaxResult.success();
  1552. }
  1553. /**
  1554. * 判断金额是否超过可用金额
  1555. *
  1556. * @param fid 费用明细表主键
  1557. * @param money 申请金额
  1558. * @param type DZ 对账 SF 收费 FF 付费 ApplyFP 开票申请 invoiceFP 开票
  1559. * @return
  1560. */
  1561. public Map<String, Object> judgeMoney(long fid, BigDecimal money, String type, Long feeId) {
  1562. Map<String, Object> map = new HashMap<>();
  1563. boolean flag = true;
  1564. TWarehousebillsfees warehousebillsfees = tWarehousebillsfeesMapper.selectTWarehousebillsfeesById(fid);
  1565. TFees tFees = tFeesMapper.selectTFeesById(feeId);
  1566. BigDecimal amount = warehousebillsfees.getfAmount();//金额
  1567. BigDecimal accamount = warehousebillsfees.getfAccamount();//对账金额
  1568. BigDecimal stlamount = warehousebillsfees.getfStlamount();//结算金额
  1569. BigDecimal invamount = warehousebillsfees.getfInvamount();//开票金额a
  1570. BigDecimal askamount = warehousebillsfees.getfAskamount();//申请金额
  1571. if (warehousebillsfees == null) {
  1572. map.put("message", "费用明细数据有误,请找管理员");
  1573. } else if ("DZ".equals(type) || "KHDZ".equals(type)) {
  1574. BigDecimal subtract = amount.subtract(accamount);
  1575. if (subtract.compareTo(money) < 0) {
  1576. flag = false;
  1577. map.put("message", tFees.getfName() + "对账金额超过可对账金额,当前可对账金额为" + subtract + "元");
  1578. }
  1579. } else if ("SF".equals(type) || "KHSF".equals(type)) {
  1580. BigDecimal subtract = amount.subtract(stlamount);
  1581. if (subtract.compareTo(money) < 0) {
  1582. flag = false;
  1583. map.put("message", tFees.getfName() + "收费金额超过可收费金额,当前可对账金额为" + subtract + "元");
  1584. }
  1585. } else if ("FF".equals(type) || "KHFF".equals(type)) {
  1586. BigDecimal subtract = amount.subtract(stlamount);
  1587. if (subtract.compareTo(money) < 0) {
  1588. flag = false;
  1589. map.put("message", tFees.getfName() + "付费金额超过可付费金额,当前可对账金额为" + subtract + "元");
  1590. }
  1591. } else if ("ApplyFP".equals(type)) {
  1592. BigDecimal subtract = amount.subtract(askamount);
  1593. if (subtract.compareTo(money) < 0) {
  1594. flag = false;
  1595. map.put("message", tFees.getfName() + "开票金额超过可开票金额,当前可对账金额为" + subtract + "元");
  1596. }
  1597. } else if ("invoiceFP".equals(type)) {
  1598. BigDecimal subtract = amount.subtract(invamount);
  1599. if (subtract.compareTo(money) < 0) {
  1600. flag = false;
  1601. map.put("message", tFees.getfName() + "开票金额超过可开票金额,当前可对账金额为" + subtract + "元");
  1602. }
  1603. }
  1604. map.put("flag", flag);
  1605. return map;
  1606. }
  1607. /**
  1608. * 申请发票审核成功复制数据到销项发票中
  1609. *
  1610. * @param fId 主表id
  1611. * @param fBilltype 类型
  1612. * @return
  1613. */
  1614. @Transactional
  1615. public AjaxResult copyInvoiceFp(Long fId, String fBilltype) {
  1616. //查询费用主表信息复制主表信息
  1617. Integer insert = null;
  1618. TFee fee = tFeeMapper.selectTFeeById(fId);
  1619. TFee tFee = new TFee();
  1620. tFee.setfId(fee.getfId());
  1621. Date time = new Date();
  1622. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  1623. //查询费用从表信息复制主表信息
  1624. fee.setfAccountId(fee.getfId());
  1625. fee.setfBillno(billNo);
  1626. fee.setfBilltype(fBilltype);
  1627. fee.setfId(null);
  1628. insert = tFeeMapper.insertTFee(fee);
  1629. tFee.setfMake(1);
  1630. //修改原发票数据代表已开销项发票
  1631. insert = tFeeMapper.updateTFee(tFee);
  1632. TFeeDo tFeeDo = new TFeeDo();
  1633. tFeeDo.setfPid(fId);
  1634. List<TFeeDo> tFeeDoList = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  1635. if (CollectionUtils.isNotEmpty(tFeeDoList)) {
  1636. for (TFeeDo feeDo : tFeeDoList) {
  1637. feeDo.setfId(null);
  1638. feeDo.setfPid(fee.getfId());
  1639. feeDo.setfBilltype(fBilltype);
  1640. insert = tFeeDoMapper.insertTFeeDo(feeDo);
  1641. }
  1642. }
  1643. //查询开票信息复制主表信息
  1644. TFeeInvoice tFeeInvoice = new TFeeInvoice();
  1645. tFeeInvoice.setfPid(fId);
  1646. List<TFeeInvoice> tFeeInvoiceList = tFeeInvoiceMapper.selectTFeeInvoiceList(tFeeInvoice);
  1647. if (CollectionUtils.isNotEmpty(tFeeInvoiceList)) {
  1648. for (TFeeInvoice invoice : tFeeInvoiceList) {
  1649. invoice.setfId(null);
  1650. invoice.setfPid(fee.getfId());
  1651. insert = tFeeInvoiceMapper.insertTFeeInvoice(invoice);
  1652. }
  1653. }
  1654. if (insert != null && insert > 0) {
  1655. return AjaxResult.success();
  1656. } else {
  1657. return AjaxResult.error("生成销项发票失败,请找管理员");
  1658. }
  1659. }
  1660. /**
  1661. * 导出财务对账数据
  1662. *
  1663. * @param fId
  1664. * @return
  1665. */
  1666. @Override
  1667. public AjaxResult exportFinancial(Long fId) {
  1668. //获取数据
  1669. String shipsName = "";//船名
  1670. String voyage = "";//航次
  1671. String corpName = "";//客户
  1672. String fFromDate = "";//离港日期开始
  1673. String fToDate = "";//离港日期结束
  1674. BigDecimal fAmount = new BigDecimal(0);//合计
  1675. //查询财务主数据
  1676. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  1677. TFee fee = tFeeMapper.selectTFeeById(fId);
  1678. if (fee != null) {
  1679. corpName = fee.getfCtrlcorpid();
  1680. if (fee.getfFromDate() != null) {
  1681. fFromDate = simpleDateFormat.format(fee.getfFromDate());
  1682. }
  1683. if (fee.getfToDate() != null) {
  1684. fToDate = simpleDateFormat.format(fee.getfToDate());
  1685. }
  1686. if (fee.getfVslid() != null) {
  1687. TVessel vessel = tVesselMapper.selectTVesselById(fee.getfVslid());
  1688. if (vessel != null && StringUtils.isNotEmpty(vessel.getfName())) {
  1689. shipsName = vessel.getfName();
  1690. }
  1691. }
  1692. if (fee.getfVoyid() != null) {
  1693. TVoyage tVoyage = tVoyageMapper.selectTVoyageById(fee.getfVoyid());
  1694. if (tVoyage != null && StringUtils.isNotEmpty(tVoyage.getfNo())) {
  1695. voyage = tVoyage.getfNo();
  1696. }
  1697. }
  1698. }
  1699. //样式设置
  1700. //1.创建一个workbook,对应一个excel文件
  1701. HSSFWorkbook wb = new HSSFWorkbook();
  1702. //2.在workbook中添加一个sheet,对应Excel中的sheet
  1703. HSSFSheet sheet = wb.createSheet("对账");
  1704. //设置每一列的列宽
  1705. sheet.setColumnWidth(0, 256 * 15);
  1706. sheet.setColumnWidth(1, 256 * 20);
  1707. sheet.setColumnWidth(2, 256 * 20);
  1708. sheet.setColumnWidth(3, 256 * 20);
  1709. sheet.setColumnWidth(4, 256 * 15);
  1710. sheet.setColumnWidth(5, 256 * 15);
  1711. sheet.setColumnWidth(6, 256 * 15);
  1712. sheet.setColumnWidth(7, 100 * 35);
  1713. sheet.setColumnWidth(8, 256 * 15);
  1714. sheet.setColumnWidth(9, 256 * 15);
  1715. //3.设置样式以及字体样式
  1716. HSSFCellStyle titleStyle = ExcelUtils.createTitleCellStyle(wb);
  1717. HSSFCellStyle contentStyle = ExcelUtils.createContentCellStyle(wb);
  1718. HSSFCellStyle subheadingStyle = ExcelUtils.createSubheadingStyle(wb);
  1719. HSSFCellStyle endStyle = ExcelUtils.createEndStyle(wb);
  1720. //4.创建标题,合并标题单元格
  1721. //行号
  1722. int rowNum = 0;
  1723. //创建第一行,索引从0开始(标题行)
  1724. HSSFRow row0 = sheet.createRow(rowNum++);
  1725. row0.setHeight((short) 800);// 设置行高
  1726. for (int i = 0; i < 10; i++) {
  1727. HSSFCell tempCell = row0.createCell(i);
  1728. tempCell.setCellStyle(contentStyle);
  1729. }
  1730. String title = "青岛凯和志诚物流有限公司";
  1731. HSSFCell c00 = row0.createCell(0);
  1732. c00.setCellValue(title);
  1733. c00.setCellStyle(titleStyle);
  1734. // 合并单元格,参数依次为起始行,结束行,起始列,结束列 (索引0开始)
  1735. sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 9));//标题合并单元格操作,总列数为9
  1736. //第2行
  1737. HSSFRow row1 = sheet.createRow(rowNum++);
  1738. row1.setHeight((short) 500);
  1739. String message1 = "客户确认单";
  1740. for (int i = 0; i < 10; i++) {
  1741. HSSFCell tempCell = row1.createCell(i);
  1742. tempCell.setCellStyle(contentStyle);
  1743. }
  1744. HSSFCell c01 = row1.createCell(0);
  1745. c01.setCellValue(message1);
  1746. c01.setCellStyle(subheadingStyle);
  1747. sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 9));//标题合并单元格操作,总列数为9
  1748. //第3行
  1749. HSSFRow row2 = sheet.createRow(rowNum++);
  1750. row2.setHeight((short) 500);
  1751. String message2 = "尊敬的客户";
  1752. HSSFCell c02 = row2.createCell(0);
  1753. c02.setCellValue(message2);
  1754. c02.setCellStyle(contentStyle);
  1755. //第3行
  1756. for (int i = 1; i < 10; i++) {
  1757. HSSFCell tempCell = row2.createCell(i);
  1758. tempCell.setCellStyle(contentStyle);
  1759. }
  1760. HSSFCell c03 = row2.createCell(1);
  1761. c03.setCellValue(corpName);
  1762. c03.setCellStyle(contentStyle);
  1763. sheet.addMergedRegion(new CellRangeAddress(2, 2, 1, 9));//标题合并单元格操作,总列数为9
  1764. //合并单元格
  1765. sheet.addMergedRegion(new CellRangeAddress(3, 3, 1, 2));
  1766. sheet.addMergedRegion(new CellRangeAddress(3, 3, 3, 4));
  1767. sheet.addMergedRegion(new CellRangeAddress(3, 3, 5, 9));
  1768. //第4行
  1769. HSSFRow row3 = sheet.createRow(rowNum++);
  1770. for (int i = 0; i < 1; i++) {
  1771. HSSFCell tempCell = row3.createCell(i);
  1772. tempCell.setCellStyle(contentStyle);
  1773. }
  1774. for (int i = 1; i < 3; i++) {
  1775. HSSFCell tempCell = row3.createCell(i);
  1776. tempCell.setCellStyle(contentStyle);
  1777. }
  1778. for (int i = 3; i < 5; i++) {
  1779. HSSFCell tempCell = row3.createCell(i);
  1780. tempCell.setCellStyle(contentStyle);
  1781. }
  1782. for (int i = 5; i < 10; i++) {
  1783. HSSFCell tempCell = row3.createCell(i);
  1784. tempCell.setCellStyle(contentStyle);
  1785. }
  1786. row3.setHeight((short) 500);
  1787. HSSFCell c05 = row3.createCell(0);
  1788. c05.setCellValue("船名航次:");
  1789. c05.setCellStyle(contentStyle);
  1790. HSSFCell c051 = row3.createCell(1);
  1791. c051.setCellValue(shipsName + voyage);
  1792. c051.setCellStyle(contentStyle);
  1793. HSSFCell c052 = row3.createCell(3);
  1794. c052.setCellValue("离港日期:");
  1795. c052.setCellStyle(contentStyle);
  1796. String message = "";
  1797. HSSFCell c053 = row3.createCell(5);
  1798. if (StringUtils.isNotEmpty(fFromDate)) {
  1799. if (StringUtils.isNotEmpty(fFromDate)) {
  1800. message = fFromDate + "-" + fToDate;
  1801. } else {
  1802. message = fFromDate;
  1803. }
  1804. } else if (StringUtils.isNotEmpty(fToDate)) {
  1805. message = fToDate;
  1806. }
  1807. c053.setCellValue(message);
  1808. c053.setCellStyle(contentStyle);
  1809. //第5行
  1810. HSSFRow row4 = sheet.createRow(rowNum++);
  1811. for (int i = 0; i < 10; i++) {
  1812. HSSFCell tempCell = row4.createCell(i);
  1813. tempCell.setCellStyle(contentStyle);
  1814. }
  1815. row4.setHeight((short) 500);
  1816. String message4 = "费用明细";
  1817. HSSFCell c04 = row4.createCell(0);
  1818. c04.setCellValue(message4);
  1819. c04.setCellStyle(contentStyle);
  1820. sheet.addMergedRegion(new CellRangeAddress(4, 4, 0, 9));//标题合并单元格操作,总列数为9
  1821. //第四行
  1822. HSSFRow row5 = sheet.createRow(rowNum++);
  1823. row5.setHeight((short) 500);
  1824. String[] row_third = {"序号", "提单号", "始发港", "目的港", "运输条款", "货名", "箱量", "规格", "单价", "合计"};
  1825. for (int i = 0; i < row_third.length; i++) {
  1826. HSSFCell tempCell = row5.createCell(i);
  1827. tempCell.setCellValue(row_third[i]);
  1828. tempCell.setCellStyle(contentStyle);
  1829. }
  1830. //查询费用明细数据
  1831. List<ExportFinancial> list = tFeeMapper.exportFinancial(fId);
  1832. if (CollectionUtils.isNotEmpty(list)) {
  1833. for (int i = 0; i < list.size(); i++) {
  1834. HSSFRow tempRow = sheet.createRow(rowNum++);
  1835. tempRow.setHeight((short) 500);
  1836. //循环单元格填入数据
  1837. for (int j = 0; j < 10; j++) {
  1838. HSSFCell tempCell = tempRow.createCell(j);
  1839. tempCell.setCellStyle(contentStyle);
  1840. String cellValue = "";
  1841. if (j == 0) {
  1842. //序号
  1843. cellValue = list.get(i).getRankNo().toString();
  1844. } else if (j == 1) {
  1845. //提单号
  1846. cellValue = list.get(i).getfMblNo();
  1847. } else if (j == 2) {
  1848. //始发港
  1849. cellValue = list.get(i).getPortOfDeparture();
  1850. } else if (j == 3) {
  1851. //目的港
  1852. cellValue = list.get(i).getDestinationPort();
  1853. } else if (j == 4) {
  1854. //运输条款
  1855. cellValue = list.get(i).getfServiceitems();
  1856. } else if (j == 5) {
  1857. //货名
  1858. cellValue = list.get(i).getGoodName();
  1859. } else if (j == 6) {
  1860. //箱量
  1861. cellValue = list.get(i).getfCnTrCount().toString();
  1862. } else if (j == 7) {
  1863. //规格
  1864. cellValue = list.get(i).getSpecification();
  1865. } else if (j == 8) {
  1866. //单价
  1867. cellValue = list.get(i).getfUnitPrice().toString();
  1868. } else if (j == 9) {
  1869. //合计
  1870. cellValue = list.get(i).getfAmount().toString();
  1871. }
  1872. tempCell.setCellValue(cellValue);
  1873. }
  1874. }
  1875. fAmount = list.stream().map(ExportFinancial::getfAmount).reduce(BigDecimal.ZERO, BigDecimal::add);//求所有和的合计
  1876. }
  1877. //倒数第二行
  1878. HSSFRow row6 = sheet.createRow(rowNum++);
  1879. for (int i = 0; i < 10; i++) {
  1880. HSSFCell tempCell = row6.createCell(i);
  1881. tempCell.setCellStyle(contentStyle);
  1882. }
  1883. row6.setHeight((short) 500);
  1884. String message6 = "合计:";
  1885. HSSFCell c06 = row6.createCell(0);
  1886. c06.setCellValue(message6);
  1887. c06.setCellStyle(contentStyle);
  1888. HSSFCell c061 = row6.createCell(9);
  1889. c061.setCellValue(fAmount.toString());
  1890. c061.setCellStyle(contentStyle);
  1891. //最后一行
  1892. HSSFRow row7 = sheet.createRow(rowNum++);
  1893. for (int i = 0; i < 10; i++) {
  1894. HSSFCell tempCell = row7.createCell(i);
  1895. tempCell.setCellStyle(contentStyle);
  1896. }
  1897. row7.setHeight((short) 1500);
  1898. String message7 = "纳税人识别号:91370202MA3UG1T04A\n" +
  1899. "人民币账号:3803020309100171855\n" +
  1900. "人民币开户行:工商银行青岛分行营业部";
  1901. HSSFCell c07 = row7.createCell(0);
  1902. c07.setCellValue(message7);
  1903. c07.setCellStyle(endStyle);
  1904. sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, 0, 9));//标题合并单元格操作,总列数为9
  1905. //导出excel
  1906. String fileName = "客户对账单.xls";
  1907. try {
  1908. OutputStream out = null;
  1909. out = new FileOutputStream(getAbsoluteFile(fileName));
  1910. wb.write(out);
  1911. if (null != wb && null != out) {
  1912. wb.write(out);
  1913. wb.close();
  1914. out.close();
  1915. }
  1916. return AjaxResult.success(fileName);
  1917. } catch (Exception e) {
  1918. e.printStackTrace();
  1919. return AjaxResult.error("导出Excel失败");
  1920. }
  1921. }
  1922. /**
  1923. * 根据结算单位、费用状态、审核日期查询应付总帐明细
  1924. *
  1925. * @param feeDTO
  1926. * @return
  1927. */
  1928. @Override
  1929. public AjaxResult financialLedgerDetails(FeeDTO feeDTO) {
  1930. TFees ccf = tFeesMapper.seletFeesByCCF();
  1931. if (Objects.isNull(ccf)) {
  1932. throw new WarehouseException("未找到仓储费费用信息");
  1933. }
  1934. feeDTO.setFeesId(ccf.getfId());
  1935. List<FeeVO> feeVOList = tFeeMapper.selectFinancialLedgerDetails(feeDTO);
  1936. if (CollectionUtils.isNotEmpty(feeVOList)) {
  1937. List<FeeVO> voList = new ArrayList<>();
  1938. Map<Long, List<FeeVO>> map = feeVOList.stream().collect(Collectors.groupingBy(FeeVO::getFSrcpid));
  1939. map.forEach((key, value) -> {
  1940. FeeVO vo = new FeeVO();
  1941. FeeVO feeVO = value.stream().findFirst().orElseThrow(() ->
  1942. new WarehouseException("获取费用异常"));
  1943. BeanUtils.copyProperties(feeVO, vo);
  1944. // 仓储费
  1945. BigDecimal storageFee = value.stream().map(FeeVO::getStorageFee).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
  1946. // 其他费用
  1947. BigDecimal otherFee = value.stream().map(FeeVO::getOtherFee).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
  1948. // 应收费用
  1949. BigDecimal amount = value.stream().map(FeeVO::getFAmount).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
  1950. // 已收费用
  1951. BigDecimal stlamount = value.stream().map(FeeVO::getFStlamount).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
  1952. WarehouseTypeEnum storageType = WarehouseTypeEnum.fromTypeAndBusinessType(vo.getfBilltype(), "storageType");
  1953. vo.setfBilltype(storageType.getName());
  1954. vo.setStorageFee(storageFee);
  1955. vo.setFStlamount(stlamount);
  1956. vo.setOtherFee(otherFee);
  1957. vo.setFAmount(amount);
  1958. vo.setNnfinished(amount.subtract(stlamount));
  1959. voList.add(vo);
  1960. });
  1961. return AjaxResult.success(voList);
  1962. }
  1963. return AjaxResult.success(feeVOList);
  1964. }
  1965. /**
  1966. * 查询应付总帐明细
  1967. *
  1968. * @param feeDTO
  1969. * @return
  1970. */
  1971. @Override
  1972. public List<GeneralLedgerDetailExcel> financialLedgerDetailsExport(FeeDTO feeDTO) {
  1973. List<GeneralLedgerDetailExcel> detailExcelList = new ArrayList<>();
  1974. List<FeeVO> feeVOList = tFeeMapper.selectFinancialLedgerDetails(feeDTO);
  1975. feeVOList.forEach(vo -> {
  1976. GeneralLedgerDetailExcel detailExcel = new GeneralLedgerDetailExcel();
  1977. WarehouseTypeEnum storageType = WarehouseTypeEnum.fromTypeAndBusinessType(vo.getfBilltype(), "storageType");
  1978. detailExcel.setFMblno(vo.getFMblno());
  1979. detailExcel.setFMarks(vo.getFMarks());
  1980. detailExcel.setFAmount(vo.getFAmount());
  1981. detailExcel.setOtherFee(vo.getOtherFee());
  1982. detailExcel.setFFeesName(vo.getFFeesName());
  1983. detailExcel.setNnfinished(vo.getNnfinished());
  1984. detailExcel.setFStlamount(vo.getFStlamount());
  1985. detailExcel.setStorageFee(vo.getStorageFee());
  1986. detailExcel.setFBilltype(storageType.getName());
  1987. detailExcel.setFProductName(vo.getFProductName());
  1988. detailExcel.setFProductName(vo.getFProductName());
  1989. detailExcelList.add(detailExcel);
  1990. });
  1991. return detailExcelList;
  1992. }
  1993. @Override
  1994. public List<ReceivableExcel> receivable(TWareHouseFees tWareHouseFees) {
  1995. return tFeeMapper.receivable(tWareHouseFees);
  1996. }
  1997. @Override
  1998. public List<ProfitExcel> profit(TWareHouseFees tWareHouseFees) {
  1999. return tFeeMapper.profit(tWareHouseFees);
  2000. }
  2001. @Override
  2002. public List<HandleExcel> handle(TWareHouseFees tWareHouseFees) {
  2003. return tFeeMapper.handle(tWareHouseFees);
  2004. }
  2005. //下载路径
  2006. private String getAbsoluteFile(String fileName) {
  2007. String downloadPath = RuoYiConfig.getDownloadPath() + fileName;
  2008. File desc = new File(downloadPath);
  2009. if (!desc.getParentFile().exists()) {
  2010. desc.getParentFile().mkdirs();
  2011. }
  2012. return downloadPath;
  2013. }
  2014. }