TFeeServiceImpl.java 105 KB

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