TFeeServiceImpl.java 94 KB

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