TFeeServiceImpl.java 87 KB

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