TFeeServiceImpl.java 90 KB

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