TFeeServiceImpl.java 97 KB

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