TFeeServiceImpl.java 115 KB

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