TFeeServiceImpl.java 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707
  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.core.domain.AjaxResult;
  12. import com.ruoyi.common.core.domain.entity.SysDictData;
  13. import com.ruoyi.common.core.domain.model.LoginUser;
  14. import com.ruoyi.common.exception.WarehouseException;
  15. import com.ruoyi.common.utils.DateUtils;
  16. import com.ruoyi.common.utils.DictUtils;
  17. import com.ruoyi.common.utils.StringUtils;
  18. import com.ruoyi.finance.domain.TFee;
  19. import com.ruoyi.finance.domain.TFeeDo;
  20. import com.ruoyi.finance.domain.TWareHouseFees;
  21. import com.ruoyi.finance.excel.Charge;
  22. import com.ruoyi.finance.excel.Contrast;
  23. import com.ruoyi.finance.excel.Detailed;
  24. import com.ruoyi.finance.excel.Payment;
  25. import com.ruoyi.finance.mapper.TFeeDoMapper;
  26. import com.ruoyi.finance.mapper.TFeeMapper;
  27. import com.ruoyi.finance.service.ITFeeService;
  28. import com.ruoyi.finance.shipping.FinancialTFee;
  29. import com.ruoyi.finance.shipping.FinancialTFeeDoExcel;
  30. import com.ruoyi.reportManagement.dto.TWarehousebill;
  31. import com.ruoyi.reportManagement.excel.Payable;
  32. import com.ruoyi.reportManagement.excel.Profit;
  33. import com.ruoyi.reportManagement.excel.Receivable;
  34. import com.ruoyi.shipping.domain.TAccount;
  35. import com.ruoyi.shipping.domain.TFeeInvoice;
  36. import com.ruoyi.shipping.excel.Account;
  37. import com.ruoyi.shipping.mapper.TFeeInvoiceMapper;
  38. import com.ruoyi.system.domain.SysConfig;
  39. import com.ruoyi.system.mapper.SysConfigMapper;
  40. import com.ruoyi.system.mapper.SysDictDataMapper;
  41. import com.ruoyi.system.service.ISysDictDataService;
  42. import com.ruoyi.warehouseBusiness.domain.BillnoDel;
  43. import com.ruoyi.warehouseBusiness.domain.TWarehouseBills;
  44. import com.ruoyi.warehouseBusiness.domain.TWarehousebillsfees;
  45. import com.ruoyi.warehouseBusiness.domain.enums.FeesTypeEnum;
  46. import com.ruoyi.warehouseBusiness.domain.enums.WarehouseTypeEnum;
  47. import com.ruoyi.warehouseBusiness.excel.ListMapToBeanUtils;
  48. import com.ruoyi.warehouseBusiness.excel.TWareHouseExcelItem;
  49. import com.ruoyi.warehouseBusiness.mapper.BillnoDelMapper;
  50. import com.ruoyi.warehouseBusiness.mapper.TWarehouseBillsMapper;
  51. import com.ruoyi.warehouseBusiness.mapper.TWarehousebillsfeesMapper;
  52. import com.ruoyi.warehouseBusiness.service.impl.BillnoSerialServiceImpl;
  53. import org.apache.commons.compress.utils.Lists;
  54. import org.springframework.beans.factory.annotation.Autowired;
  55. import org.springframework.stereotype.Service;
  56. import org.springframework.transaction.annotation.Transactional;
  57. import org.springframework.transaction.interceptor.TransactionAspectSupport;
  58. import java.math.BigDecimal;
  59. import java.util.*;
  60. /**
  61. * 财务数据主Service业务层处理
  62. *
  63. * @author ruoyi
  64. * @date 2021-01-18
  65. */
  66. @Service
  67. public class TFeeServiceImpl implements ITFeeService {
  68. @Autowired
  69. private TFeeMapper tFeeMapper;
  70. @Autowired
  71. private TFeeDoMapper tFeeDoMapper;
  72. @Autowired
  73. private BillnoSerialServiceImpl billnoSerialServiceImpl;
  74. @Autowired
  75. private BillnoDelMapper billnoDelMapper;
  76. @Autowired
  77. private TCorpsMapper tCorpsMapper;
  78. @Autowired
  79. private TFeesMapper tFeesMapper;
  80. @Autowired
  81. private TWarehouseBillsMapper tWarehouseBillsMapper;
  82. @Autowired
  83. private TWarehousebillsfeesMapper tWarehousebillsfeesMapper;
  84. @Autowired
  85. private SysConfigMapper sysConfigMapper;
  86. @Autowired
  87. private AuditItemsServiceImpl auditItemsService;
  88. @Autowired
  89. private ISysDictDataService iSysDictDataService;
  90. @Autowired
  91. private SysDictDataMapper sysDictDataMapper;
  92. @Autowired
  93. private TFeeInvoiceMapper tFeeInvoiceMapper;
  94. private final String ST_IN_TYPE = "st_in_type";
  95. private final String ST_OUT_TYPE = "st_out_type";
  96. private final String ST_TRANS_TYPE = "st_trans_type";
  97. /**
  98. * 查询财务数据主
  99. *
  100. * @param fId 财务数据主ID
  101. * @return 财务数据主
  102. */
  103. @Override
  104. public Map<String, Object> selectTFeeById(Long fId) {
  105. Map<String, Object> map = new HashMap<>();
  106. // 客户表
  107. List<Long> corpsId = new ArrayList<>();
  108. // 费用
  109. List<Long> feesId = new ArrayList<>();
  110. //费用名称
  111. String feeName = null;
  112. TFee tFee = tFeeMapper.selectTFeeById(fId);
  113. if (StringUtils.isNotNull(tFee.getfCorpid())) {
  114. corpsId.add(tFee.getfCorpid());
  115. }
  116. corpsId.add(tFee.getfCorpid());
  117. // 查询从表数据
  118. TFeeDo tFeeDo = new TFeeDo();
  119. tFeeDo.setfPid(fId);
  120. List<TFeeDo> tFeeDoList = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  121. List<Map<String, Object>> feeDoList = new ArrayList<>();
  122. if (StringUtils.isNotEmpty(tFeeDoList)) {
  123. for (TFeeDo fees : tFeeDoList) {
  124. Map<String, Object> map1 = new HashMap<>();
  125. feesId.add(fees.getfFeeid());
  126. // 查询主表
  127. TWarehouseBills tWarehousebills = tWarehouseBillsMapper.selectTWarehousebillsById(fees.getfSrcpid());
  128. if (Objects.isNull(tWarehousebills)) {
  129. throw new WarehouseException("未找到仓储信息");
  130. }
  131. // 费用名称
  132. TFees tFees = tFeesMapper.selectTFeesById(fees.getfFeeid());
  133. if (tFees != null) {
  134. feeName = tFees.getfName();
  135. }
  136. // 费用表数据
  137. TWarehousebillsfees tWarehousebillsfees = tWarehousebillsfeesMapper.selectTWarehousebillsfeesById(fees.getfSrcid());
  138. if (tWarehousebillsfees == null) {
  139. return AjaxResult.error("费用数据为空,请确认");
  140. }
  141. // 字典宝
  142. SysDictData sysDictData = new SysDictData();
  143. sysDictData.setDictType("data_unitfees");
  144. sysDictData.setDictValue(String.valueOf(tWarehousebillsfees.getfFeeunitid()));
  145. sysDictData.setStatus("0");
  146. List<SysDictData> sysDictDataList = iSysDictDataService.selectDictDataList(sysDictData);
  147. List<SysDictData> sysDictDataListIn = new ArrayList<>();
  148. if (tWarehousebillsfees.getfBilltype().equals("SJRK")) {
  149. sysDictData.setDictType(ST_IN_TYPE);
  150. sysDictData.setDictValue(String.valueOf(tWarehousebillsfees.getfBusinessType()));
  151. sysDictData.setStatus("0");
  152. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  153. } else if (tWarehousebillsfees.getfBilltype().equals("SJCK")) {
  154. sysDictData.setDictType(ST_OUT_TYPE);
  155. sysDictData.setDictValue(String.valueOf(tWarehousebillsfees.getfBusinessType()));
  156. sysDictData.setStatus("0");
  157. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  158. } else if (tWarehousebillsfees.getfBilltype().equals("CKDB") | tWarehousebillsfees.getfBilltype().equals("HWTG")) {
  159. sysDictData.setDictType(ST_TRANS_TYPE);
  160. sysDictData.setDictValue(String.valueOf(tWarehousebillsfees.getfBusinessType()));
  161. sysDictData.setStatus("0");
  162. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  163. }
  164. // 之前遗留汉字特别处理
  165. FeesTypeEnum feesTypeEnum;
  166. if (fees.getfSrcdc().equals("收")) {
  167. feesTypeEnum = FeesTypeEnum.D;
  168. } else if (fees.getfSrcdc().equals("付")) {
  169. feesTypeEnum = FeesTypeEnum.C;
  170. } else {
  171. feesTypeEnum = FeesTypeEnum.fromType(fees.getfSrcdc());
  172. }
  173. map1.put("fSrcdcName", feesTypeEnum.getName());
  174. map1.put("fId", fees.getfId());
  175. map1.put("fSrcid", fees.getfSrcid());
  176. map1.put("fSrcpid", fees.getfSrcpid());
  177. map1.put("fMblno", tWarehousebillsfees.getfMblno());
  178. map1.put("fBscorpno", tWarehousebills.getfBscorpno());
  179. map1.put("fProductName", tWarehousebillsfees.getfProductName());
  180. map1.put("fBsdate", tWarehousebillsfees.getfBsdate());
  181. map1.put("fFeeid", fees.getfFeeid());
  182. map1.put("fFeeName", feeName);
  183. map1.put("fSrcdc", fees.getfSrcdc());
  184. map1.put("fAmt", fees.getfAmt());
  185. map1.put("fAmtdr", fees.getfAmtdr());
  186. map1.put("fRemarks", fees.getfRemarks());
  187. map1.put("srcBillNo", tWarehousebillsfees.getSrcId());
  188. map1.put("fMarks", tWarehousebillsfees.getfMarks());
  189. map1.put("fChargedate", tWarehousebillsfees.getfChargedate());
  190. map1.put("fBillingDeadline", tWarehousebillsfees.getfBillingDeadline());
  191. map1.put("fBillingDays", tWarehousebillsfees.getfBillingDays());
  192. map1.put("fInventoryDays", tWarehousebillsfees.getfInventoryDays());
  193. map1.put("fFeeunitid", sysDictDataList.get(0).getDictLabel());
  194. map1.put("fQty", tWarehousebillsfees.getfQty());
  195. map1.put("fUnitprice", tWarehousebillsfees.getfUnitprice());
  196. if (tWarehousebillsfees.getfBilltype().equals("KHDD")) {
  197. map1.put("fBusinessType", "船运订单");
  198. } else if (CollectionUtils.isNotEmpty(sysDictDataListIn)) {
  199. map1.put("fBusinessType", sysDictDataListIn.get(0).getDictLabel());
  200. }
  201. if (tWarehousebills.getfBilltype().equals("SJRK")) {
  202. map1.put("fBilltype", "入库");
  203. } else if (tWarehousebills.getfBilltype().equals("SJCK")) {
  204. map1.put("fBilltype", "出库");
  205. } else if (tWarehousebills.getfBilltype().equals("CKDB")) {
  206. map1.put("fBilltype", "调拨");
  207. } else if (tWarehousebills.getfBilltype().equals("HWTG")) {
  208. map1.put("fBilltype", "货物通关");
  209. } else if (tWarehousebills.getfBilltype().equals("HQZY")) {
  210. map1.put("fBilltype", "货权转移");
  211. } else if (tWarehousebills.getfBilltype().equals("KHDD")) {
  212. map1.put("fBilltype", "船运订单");
  213. }
  214. feeDoList.add(map1);
  215. }
  216. }
  217. List<TCorps> corpsList = new ArrayList<>();
  218. List<Long> corpsIdList = StringUtils.integerDeduplication(corpsId);
  219. for (Long corpId : corpsIdList) {
  220. TCorps corps = tCorpsMapper.selectTCorpsById(corpId);
  221. if (StringUtils.isNotNull(corps)) {
  222. corpsList.add(corps);
  223. }
  224. }
  225. List<TFees> feesList = new ArrayList<>();
  226. List<Long> longList = StringUtils.integerDeduplication(feesId);
  227. for (Long fees : longList) {
  228. TFees tFees = tFeesMapper.selectTFeesById(fees);
  229. if (StringUtils.isNotNull(tFees)) {
  230. feesList.add(tFees);
  231. }
  232. }
  233. map.put("tFee", tFee);
  234. map.put("corps", corpsList);
  235. map.put("feesList", feesList);
  236. map.put("feeDoList", feeDoList);
  237. return map;
  238. }
  239. @Override
  240. public Map<String, Object> selectTFeeByIdNew(Long fId) {
  241. Map<String, Object> map = new HashMap<>();
  242. TFee tFee = tFeeMapper.selectTFeeByIdNew(fId);
  243. List<TFeeDo> feeDoList = tFeeDoMapper.selectTFeeDoByfPid(fId);
  244. TFeeInvoice tFeeInvoice = new TFeeInvoice();
  245. tFeeInvoice.setfPid(fId);
  246. List<TFeeInvoice> tFeeInvoiceList = tFeeInvoiceMapper.selectTFeeInvoiceList(tFeeInvoice);
  247. map.put("tFee", tFee);
  248. map.put("feeDoList", feeDoList);
  249. map.put("tFeeInvoiceList", tFeeInvoiceList);
  250. return map;
  251. }
  252. /**
  253. * 查询财务数据主列表
  254. *
  255. * @param tFee 财务数据主
  256. * @return 财务数据主
  257. */
  258. @Override
  259. public List<TFee> selectTFeeList(TFee tFee) {
  260. return tFeeMapper.selectTFeeList(tFee);
  261. }
  262. @Override
  263. public List<Map<String, Object>> selectTFeeList1(TFee tFee) {
  264. return tFeeMapper.selectTFeeList1(tFee);
  265. }
  266. @Override
  267. public List<Map<String, Object>> webVersionTFee(TFee tFee) {
  268. return tFeeMapper.webVersionTFee(tFee);
  269. }
  270. @Override
  271. public List<Map<String, Object>> webVersionDetail(TAccount tAccount) {
  272. return tWarehousebillsfeesMapper.webVersionDetail(tAccount);
  273. }
  274. @Override
  275. public List<Map<String, Object>> webVersionInvoice(TFee tFee) {
  276. return tFeeMapper.webVersionInvoice(tFee);
  277. }
  278. @Override
  279. public List<Map<String, Object>> webVersionInvoiceDetail(TFee tFee) {
  280. List<Map<String, Object>> list = tFeeMapper.webVersionInvoice(tFee);
  281. if (CollectionUtils.isNotEmpty(list)) {
  282. for (Map<String, Object> map : list) {
  283. Long fId = Long.valueOf(map.get("fId").toString());
  284. List<TFeeDo> tFeeDos = tFeeDoMapper.selectTFeeDoByfPid(fId);
  285. map.put("tFeeDoList", tFeeDos);
  286. TFeeInvoice tFeeInvoice = new TFeeInvoice();
  287. tFeeInvoice.setfPid(fId);
  288. List<TFeeInvoice> tFeeInvoiceList = tFeeInvoiceMapper.selectTFeeInvoiceList(tFeeInvoice);
  289. map.put("tFeeInvoiceList", tFeeInvoiceList);
  290. }
  291. }
  292. return list;
  293. }
  294. @Override
  295. public List<Map<String, Object>> webVersionList(TAccount tAccount) {
  296. return tWarehousebillsfeesMapper.webVersionReconciliation(tAccount);
  297. }
  298. /**
  299. * 新增财务数据主
  300. *
  301. * @param tFee 财务数据主
  302. * @return 结果
  303. */
  304. @Override
  305. public int insertTFee(TFee tFee) {
  306. tFee.setCreateTime(DateUtils.getNowDate());
  307. return tFeeMapper.insertTFee(tFee);
  308. }
  309. /**
  310. * 新增对账 、收费、
  311. *
  312. * @param tfee
  313. * @param tfeeDo
  314. * @param loginUser
  315. * @param fBilltype
  316. * @return
  317. */
  318. @Override
  319. @Transactional
  320. public AjaxResult insertTFeeTFeeDo(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  321. Long fPid = null;
  322. Map<String, Object> map = new HashMap<>();
  323. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  324. if (StringUtils.isNull(tFee.getfId())) {
  325. // 如果是新数据
  326. tFee.setCreateBy(loginUser.getUser().getUserName());
  327. tFee.setCreateTime(new Date());
  328. tFee.setfDeptid(loginUser.getUser().getDeptId());
  329. tFee.setfBilltype(fBilltype);
  330. // 业务编码
  331. Date time = new Date();
  332. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  333. tFee.setfBillno(billNo);
  334. tFee.setSrcBillNo(billNo);
  335. tFee.setfBillstatus("2");
  336. tFeeMapper.insertTFee(tFee);
  337. fPid = tFee.getfId();
  338. } else {
  339. fPid = tFee.getfId();
  340. tFee.setUpdateBy(loginUser.getUser().getUserName());
  341. tFee.setUpdateTime(new Date());
  342. tFeeMapper.updateTFee(tFee);
  343. tFee = tFeeMapper.selectTFeeById(fPid);
  344. tFee.setSrcBillNo(tFee.getfBillno());
  345. // 删除从表
  346. tFeeDoMapper.deleteByFPid(fPid);
  347. }
  348. // 财务从表
  349. if (StringUtils.isNotNull(tfeeDo)) {
  350. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  351. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  352. for (TFeeDo tFeeDo : tFeeDoList) {
  353. tFeeDo.setfPid(fPid);
  354. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  355. tFeeDo.setCreateTime(new Date());
  356. tFeeDo.setfStatus("2");
  357. tFeeDoMapper.insertTFeeDo(tFeeDo);
  358. }
  359. }
  360. List<FinancialTFeeDoExcel> list = tFeeDoMapper.selectFinancialTFeeDo(fPid);
  361. map.put("tFee", tFee);
  362. map.put("tFeeDo",list);
  363. return AjaxResult.success("成功", map);
  364. }
  365. @Override
  366. public AjaxResult insertWebVersion(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  367. Long fPid = null;
  368. Map<String, Object> map = new HashMap<>();
  369. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  370. if (StringUtils.isNull(tFee.getfId())) {
  371. // 如果是新数据
  372. tFee.setCreateBy(loginUser.getUser().getUserName());
  373. tFee.setCreateTime(new Date());
  374. tFee.setfDeptid(loginUser.getUser().getDeptId());
  375. tFee.setfBilltype(fBilltype);
  376. // 业务编码
  377. Date time = new Date();
  378. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  379. tFee.setfBillno(billNo);
  380. tFee.setfBillstatus("2");
  381. tFee.setfAccbilldate(new Date());
  382. tFeeMapper.insertTFee(tFee);
  383. fPid = tFee.getfId();
  384. } else {
  385. fPid = tFee.getfId();
  386. tFee.setUpdateBy(loginUser.getUser().getUserName());
  387. tFee.setUpdateTime(new Date());
  388. tFeeMapper.updateTFee(tFee);
  389. // 删除从表
  390. tFeeDoMapper.deleteByFPid(fPid);
  391. }
  392. // 财务从表
  393. if (StringUtils.isNotNull(tfeeDo)) {
  394. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  395. List<TAccount> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TAccount.class);
  396. for (TAccount tAccount : tFeeDoList) {
  397. TFeeDo tFeeDo = new TFeeDo();
  398. tFeeDo.setfSrcid(tAccount.getfSrcid());
  399. tFeeDo.setfSrcpid(tAccount.getfSrcpid());
  400. tFeeDo.setfPid(fPid);
  401. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  402. tFeeDo.setCreateTime(new Date());
  403. tFeeDo.setfStatus("2");
  404. tFeeDo.setfSrcdc("D");
  405. tFeeDo.setfAmtdr(tAccount.getfAmtdr());
  406. tFeeDo.setfAmt(tAccount.getfAmt());
  407. tFeeDo.setfFeeid(tAccount.getfFeeid());
  408. tFeeDoMapper.insertTFeeDo(tFeeDo);
  409. }
  410. }
  411. map.put("tFee", tFee);
  412. return AjaxResult.success("成功", map);
  413. }
  414. /**
  415. * 新增对账 、收费、
  416. *
  417. * @param tfee
  418. * @param tfeeDo
  419. * @param loginUser
  420. * @param fBilltype
  421. * @return
  422. */
  423. @Override
  424. @Transactional
  425. public AjaxResult insertKHTFeeTFeeDo(String tfee, String tfeeDo, String tFeeInvoice, LoginUser loginUser, String fBilltype) {
  426. Long fPid = null;
  427. Map<String, Object> map = new HashMap<>();
  428. String billStatus = "2";
  429. if (fBilltype.equals("INV")) {
  430. billStatus = "6";
  431. }
  432. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  433. if (StringUtils.isNull(tFee.getfId())) {
  434. // 如果是新数据
  435. tFee.setCreateBy(loginUser.getUser().getUserName());
  436. tFee.setCreateTime(new Date());
  437. tFee.setfDeptid(loginUser.getUser().getDeptId());
  438. tFee.setfBilltype(fBilltype);
  439. // 业务编码
  440. Date time = new Date();
  441. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  442. tFee.setfBillno(billNo);
  443. tFee.setfBillstatus(billStatus);
  444. tFeeMapper.insertTFee(tFee);
  445. fPid = tFee.getfId();
  446. } else {
  447. fPid = tFee.getfId();
  448. boolean change = this.change(fPid);
  449. if (!change && !"INV".equals(fBilltype)) {
  450. return AjaxResult.error("当前数据不支持修改");
  451. }
  452. tFee.setUpdateBy(loginUser.getUser().getUserName());
  453. tFee.setUpdateTime(new Date());
  454. tFeeMapper.updateTFee(tFee);
  455. // 删除从表
  456. tFeeDoMapper.deleteByFPid(fPid);
  457. tFeeInvoiceMapper.deleteByFPid(fPid);
  458. }
  459. // 财务从表
  460. if (StringUtils.isNotNull(tfeeDo)) {
  461. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  462. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  463. for (TFeeDo tFeeDo : tFeeDoList) {
  464. tFeeDo.setfPid(fPid);
  465. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  466. tFeeDo.setCreateTime(new Date());
  467. tFeeDo.setfStatus(billStatus);
  468. tFeeDoMapper.insertTFeeDo(tFeeDo);
  469. }
  470. }
  471. if (!"".equals(tFeeInvoice) && tFeeInvoice != null && !"null".equals(tFeeInvoice)) {
  472. JSONArray jsonDrArray = JSONArray.parseArray(tFeeInvoice);
  473. List<TFeeInvoice> tFeeInvoiceList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeInvoice.class);
  474. for (TFeeInvoice feeInvoice : tFeeInvoiceList) {
  475. feeInvoice.setfPid(fPid);
  476. feeInvoice.setCreateBy(loginUser.getUser().getUserName());
  477. feeInvoice.setCreateTime(new Date());
  478. feeInvoice.setfBillstatus(billStatus);
  479. tFeeInvoiceMapper.insertTFeeInvoice(feeInvoice);
  480. }
  481. }
  482. map.put("tFee", tFee);
  483. return AjaxResult.success("成功", map);
  484. }
  485. /**
  486. * 修改财务数据主
  487. *
  488. * @param tFee 财务数据主
  489. * @return 结果
  490. */
  491. @Override
  492. public int updateTFee(TFee tFee) {
  493. tFee.setUpdateTime(DateUtils.getNowDate());
  494. return tFeeMapper.updateTFee(tFee);
  495. }
  496. /**
  497. * 批量删除财务数据主
  498. *
  499. * @param fIds 需要删除的财务数据主ID
  500. * @return 结果
  501. */
  502. @Override
  503. @Transactional
  504. public AjaxResult deleteWebVersionByIds(Long[] fIds) {
  505. // 取出业务编号、 放入 billno_del
  506. for (Long id : fIds) {
  507. // 1、查询主表信息
  508. TFee tFee = tFeeMapper.selectTFeeById(id);
  509. boolean change = this.change(id);
  510. if (change == false) {
  511. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  512. return AjaxResult.error("数据正在审批或审批通过,不允许删除");
  513. }
  514. // 2、业务编号、客存编号 放入 billno_del
  515. BillnoDel billnoDel = new BillnoDel();
  516. billnoDel.setBillType(tFee.getfBilltype());
  517. billnoDel.setBillNo(tFee.getfBillno());
  518. billnoDelMapper.insertBillnoDel(billnoDel);
  519. if (tFee.getfAccountId() != null) {
  520. TFee fee = tFeeMapper.selectTFeeById(tFee.getfAccountId());
  521. fee.setfMake(0);
  522. int updateTFee = tFeeMapper.updateTFee(fee);
  523. }
  524. }
  525. int i = tFeeMapper.deleteTFeeByIds(fIds);
  526. if (i <= 0) {
  527. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  528. return AjaxResult.error("删除发票申请失败,请找管理员");
  529. }
  530. return AjaxResult.success();
  531. }
  532. @Override
  533. public int deleteTFeeByIds(Long[] fIds) {
  534. // 取出业务编号、 放入 billno_del
  535. for (Long id : fIds) {
  536. // 1、查询主表信息
  537. TFee tFee = tFeeMapper.selectTFeeById(id);
  538. // 2、业务编号、客存编号 放入 billno_del
  539. BillnoDel billnoDel = new BillnoDel();
  540. billnoDel.setBillType(tFee.getfBilltype());
  541. billnoDel.setBillNo(tFee.getfBillno());
  542. billnoDelMapper.insertBillnoDel(billnoDel);
  543. if (tFee.getfAccountId() != null) {
  544. TFee fee = tFeeMapper.selectTFeeById(tFee.getfAccountId());
  545. fee.setfMake(0);
  546. int updateTFee = tFeeMapper.updateTFee(fee);
  547. }
  548. }
  549. return tFeeMapper.deleteTFeeByIds(fIds);
  550. }
  551. /**
  552. * 删除财务数据主信息
  553. *
  554. * @param fId 财务数据主ID
  555. * @return 结果
  556. */
  557. @Override
  558. public int deleteTFeeById(Long fId) {
  559. return tFeeMapper.deleteTFeeById(fId);
  560. }
  561. @Override
  562. public List<Map<String, Object>> warehouseBillsFeesList(TWareHouseFees tWareHouseFees, String billsType) {
  563. Map<String, Object> map = new HashMap<>();
  564. map.put("tWareHouseFees", tWareHouseFees);
  565. List<Map<String, Object>> mapList = new ArrayList<>();
  566. if (billsType.equals("DZ") || billsType.equals("KHDZ")) {
  567. mapList = tFeeMapper.warehouseBillsFeesListAccamount(map);
  568. updateBillTypeName(mapList, tWareHouseFees.getfBilltype());
  569. return mapList;
  570. } else if (billsType.equals("invoiceFP")) {
  571. mapList = tFeeMapper.warehouseInvoiceFPFeesList(map);
  572. return mapList;
  573. } else if (billsType.equals("ApplyFP")) {
  574. mapList = tFeeMapper.warehouseApplyFPFeesList(map);
  575. return mapList;
  576. } else {
  577. mapList = tFeeMapper.warehouseBillsFeesList(map);
  578. updateBillTypeName(mapList, tWareHouseFees.getfBilltype());
  579. return mapList;
  580. }
  581. }
  582. /**
  583. * 根据传入业务类型判断传入对应值
  584. *
  585. * @param mapList
  586. * @param type
  587. */
  588. private void updateBillTypeName(List<Map<String, Object>> mapList, String type) {
  589. if (CollectionUtils.isNotEmpty(mapList)) {
  590. List<String> typeList = Lists.newArrayList();
  591. typeList.add(ST_IN_TYPE);
  592. typeList.add(ST_OUT_TYPE);
  593. typeList.add(ST_TRANS_TYPE);
  594. List<SysDictData> sysDictDataList = sysDictDataMapper.selectByTypes(typeList);
  595. // 遍历map
  596. for (Map<String, Object> map : mapList) {
  597. // 如果类型为入库
  598. if (StringUtils.isEmpty(type) && Objects.nonNull(map.get("fBusinessType"))) {
  599. String fBusinessType = map.get("fBusinessType").toString();
  600. String dictLabel = sysDictDataList.stream().filter(li -> Objects.equals(li.getDictValue(), fBusinessType))
  601. .map(SysDictData::getDictLabel).findFirst().orElseThrow(() -> new WarehouseException("缺少字典表信息"));
  602. map.put("fBusinessType", dictLabel);
  603. } else if (StringUtils.isNotEmpty(type) && type.equals(WarehouseTypeEnum.SJRK.getType()) && Objects.nonNull(map.get("fBusinessType"))) {
  604. String dictLabel = DictUtils.getDictLabel(ST_IN_TYPE, map.get("fBusinessType").toString());
  605. if (StringUtils.isNotEmpty(dictLabel)) {
  606. map.put("fBusinessType", dictLabel);
  607. }
  608. } else if (StringUtils.isNotEmpty(type) && type.equals(WarehouseTypeEnum.SJCK.getType()) && Objects.nonNull(map.get("fBusinessType"))) {
  609. String dictLabel = DictUtils.getDictLabel(ST_OUT_TYPE, map.get("fBusinessType").toString());
  610. if (StringUtils.isNotEmpty(dictLabel)) {
  611. map.put("fBusinessType", dictLabel);
  612. }
  613. } else if (StringUtils.isNotEmpty(type) && type.equals(WarehouseTypeEnum.HQZY.getType()) && Objects.nonNull(map.get("fBusinessType"))) {
  614. String dictLabel = DictUtils.getDictLabel(ST_TRANS_TYPE, map.get("fBusinessType").toString());
  615. if (StringUtils.isNotEmpty(dictLabel)) {
  616. map.put("fBusinessType", dictLabel);
  617. }
  618. }
  619. }
  620. }
  621. }
  622. @Override
  623. public List<Map<String, Object>> warehouseBillsFeesList(TWareHouseFees tWareHouseFees) {
  624. return tFeeMapper.warehouseBillsFeesList1(tWareHouseFees);
  625. }
  626. @Override
  627. public List<Map<String, Object>> warehouseBillsFeesProfitList(TWareHouseFees tWareHouseFees) {
  628. return tFeeMapper.warehouseBillsFeesProfitList(tWareHouseFees);
  629. }
  630. public static BigDecimal calculation1(String fTotalgross, String fGrossweightblc) {
  631. BigDecimal num1 = new BigDecimal(fTotalgross);
  632. BigDecimal num2 = new BigDecimal(fGrossweightblc);
  633. BigDecimal result = num1.subtract(num2);
  634. return result.setScale(2, BigDecimal.ROUND_HALF_UP);
  635. }
  636. @Override
  637. @Transactional
  638. public AjaxResult confirm(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  639. String key = "";
  640. boolean isApprove = false;
  641. Map<String, Object> messageMap = new HashMap<>();
  642. long actId = 0L;
  643. if ("DZ".equals(fBilltype)) {
  644. actId = 210L;
  645. key = "warehouse.contrast.ApprovalFlow";
  646. } else if ("SF".equals(fBilltype)) {
  647. actId = 220L;
  648. key = "warehouse.charge.ApprovalFlow";
  649. } else if ("FF".equals(fBilltype)) {
  650. actId = 230L;
  651. key = "warehouse.payment.ApprovalFlow";
  652. } else if ("KHDZ".equals(fBilltype)) {
  653. actId = 430L;
  654. key = "warehouse.kaiHeContrast.ApprovalFlow";
  655. } else if ("KHSF".equals(fBilltype)) {
  656. actId = 440L;
  657. key = "warehouse.kaiHeCharge.ApprovalFlow";
  658. } else if ("KHFF".equals(fBilltype)) {
  659. actId = 450L;
  660. key = "warehouse.kaiHePayment.ApprovalFlow";
  661. }
  662. SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique(key);
  663. if (StringUtils.isNull(sysConfig)) {
  664. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  665. return AjaxResult.error("系统参数异常,未找到开启审批流参数");
  666. }
  667. if ("0".equals(sysConfig.getConfigValue())) {
  668. isApprove = true;
  669. }
  670. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  671. String billstatus = "";
  672. if (isApprove) {
  673. billstatus = "4";
  674. } else {
  675. billstatus = "6";
  676. }
  677. if (StringUtils.isNull(tFee.getfId())) {
  678. // 如果是新数据
  679. tFee.setCreateBy(loginUser.getUser().getUserName());
  680. tFee.setfDeptid(loginUser.getUser().getDeptId());
  681. tFee.setfBilltype(fBilltype);
  682. tFee.setfBillstatus(billstatus);
  683. // 业务编码
  684. Date time = new Date();
  685. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  686. tFee.setfBillno(billNo);
  687. tFeeMapper.insertTFee(tFee);
  688. } else {
  689. tFee.setUpdateBy(loginUser.getUser().getUserName());
  690. tFee.setUpdateTime(new Date());
  691. tFee.setfBillstatus(billstatus);
  692. tFeeMapper.updateTFee(tFee);
  693. }
  694. // 删除从表
  695. tFeeDoMapper.deleteByFPid(tFee.getfId());
  696. messageMap.put("tFee", tFee);
  697. // 财务从表
  698. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  699. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  700. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  701. for (TFeeDo tFeeDo : tFeeDoList) {
  702. Map<String, Object> map = this.judgeMoney(tFeeDo.getfSrcid(), tFeeDo.getfAmt(), fBilltype, tFeeDo.getfFeeid());
  703. boolean b = (Boolean) map.get("flag");
  704. if (b == false) {
  705. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  706. return AjaxResult.error(map.get("message").toString());
  707. }
  708. tFeeDo.setfPid(tFee.getfId());
  709. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  710. tFeeDo.setCreateTime(new Date());
  711. tFeeDo.setfStatus(billstatus);
  712. tFeeDoMapper.insertTFeeDo(tFeeDo);
  713. }
  714. }
  715. // 这里加个判断取系统参数来确定是否需要启用审批流
  716. if (isApprove) {
  717. AuditItems auditItems = new AuditItems();
  718. auditItems.setLevelId(0L);
  719. auditItems.setBillId(tFee.getfId());
  720. auditItems.setActId(actId);
  721. auditItems.setIffinalItem("F");
  722. auditItems.setBillNo(tFee.getfBillno()); // 业务编号
  723. auditItems.setRefno1(String.valueOf(tFee.getfCorpid())); // 货权方
  724. auditItems.setRefno2(fBilltype);// 财务类型
  725. auditItems.setRefno3(tFee.gettMblno());// 提单号
  726. auditItems.setSendUserId(loginUser.getUser().getUserId());
  727. auditItems.setSendName(loginUser.getUsername());
  728. auditItems.setSendTime(new Date());
  729. auditItems.setAuditUserId(loginUser.getUser().getUserId());
  730. auditItems.setAuditItem(new Date());
  731. auditItems.setAuditOpTime(new Date());
  732. auditItems.setFidStatus("f_billstatus");
  733. auditItems.setTimes(1L);
  734. auditItems.setAuditMsg("提交");
  735. auditItems.setAuditStatus("O");
  736. AjaxResult approvalFlow = auditItemsService.createApprovalFlow(auditItems);
  737. Long code = Long.valueOf(String.valueOf(approvalFlow.get("code"))).longValue();
  738. if (code.equals(500L)) {
  739. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  740. return AjaxResult.error("发票申请提交审核失败,请找管理员");
  741. }
  742. } else {
  743. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  744. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  745. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  746. for (TFeeDo tFeeDo : tFeeDoList) {
  747. // 跟新费用明细
  748. int m = updateBillsFees(tFee.getfId(), tFeeDo, fBilltype);
  749. if (m == 0) {
  750. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  751. return AjaxResult.error("更新费用明细失败");
  752. }
  753. }
  754. }
  755. AjaxResult ajaxResult = tfeeFollow(tFee.getfId(), 6L);
  756. Long code = Long.valueOf(String.valueOf(ajaxResult.get("code"))).longValue();
  757. if (code.equals(500L)) {
  758. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  759. return AjaxResult.error("发票申请提交审核失败,请找管理员");
  760. }
  761. }
  762. return AjaxResult.success("成功", messageMap);
  763. }
  764. @Override
  765. @Transactional
  766. public AjaxResult webVersionConfirm(Long[] fIds, String billsType, LoginUser loginUser) {
  767. String key = "";
  768. boolean isApprove = false;
  769. long actId = 0L;
  770. if ("DZ".equals(billsType)) {
  771. actId = 210L;
  772. key = "warehouse.contrast.ApprovalFlow";
  773. } else if ("SF".equals(billsType)) {
  774. actId = 220L;
  775. key = "warehouse.charge.ApprovalFlow";
  776. } else if ("FF".equals(billsType)) {
  777. actId = 230L;
  778. key = "warehouse.payment.ApprovalFlow";
  779. } else if ("KHDZ".equals(billsType)) {
  780. actId = 430L;
  781. key = "warehouse.kaiHeContrast.ApprovalFlow";
  782. } else if ("KHSF".equals(billsType)) {
  783. actId = 440L;
  784. key = "warehouse.kaiHeCharge.ApprovalFlow";
  785. } else if ("KHFF".equals(billsType)) {
  786. actId = 450L;
  787. key = "warehouse.kaiHePayment.ApprovalFlow";
  788. }
  789. SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique(key);
  790. if (StringUtils.isNull(sysConfig)) {
  791. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  792. return AjaxResult.error("系统参数异常,未找到开启审批流参数");
  793. }
  794. if ("0".equals(sysConfig.getConfigValue())) {
  795. isApprove = true;
  796. }
  797. String billStatus = null;
  798. if (isApprove) {
  799. billStatus = "4";
  800. } else {
  801. billStatus = "6";
  802. }
  803. for (Long fId : fIds) {
  804. TFee tFee = tFeeMapper.selectTFeeById(fId);
  805. if (tFee == null) {
  806. return AjaxResult.error("对账数据有误请确认");
  807. }
  808. boolean change = this.change(tFee.getfId());
  809. if (change == false) {
  810. return AjaxResult.error("数据正在审批或审批通过,不允许提交审核");
  811. }
  812. //更新主表数据状态
  813. TFee fee = new TFee();
  814. fee.setfId(fId);
  815. fee.setfBillstatus(billStatus);
  816. int i = tFeeMapper.updateTFee(fee);
  817. //更新从表数据状态
  818. int update = tFeeDoMapper.tfeeDoFollowUpdate(fId, Long.valueOf(billStatus));
  819. if (isApprove) {
  820. AuditItems auditItems = new AuditItems();
  821. auditItems.setLevelId(0L);
  822. auditItems.setBillId(tFee.getfId());
  823. auditItems.setActId(actId);
  824. auditItems.setIffinalItem("F");
  825. auditItems.setBillNo(tFee.getfBillno()); // 业务编号
  826. auditItems.setRefno1(String.valueOf(tFee.getfCorpid())); // 货权方
  827. auditItems.setRefno2(billsType);// 财务类型
  828. auditItems.setRefno3(tFee.gettMblno());// 提单号
  829. auditItems.setSendUserId(loginUser.getUser().getUserId());
  830. auditItems.setSendName(loginUser.getUsername());
  831. auditItems.setSendTime(new Date());
  832. auditItems.setAuditUserId(loginUser.getUser().getUserId());
  833. auditItems.setAuditItem(new Date());
  834. auditItems.setAuditOpTime(new Date());
  835. auditItems.setFidStatus("f_billstatus");
  836. auditItems.setTimes(1L);
  837. auditItems.setAuditMsg("提交");
  838. auditItems.setAuditStatus("O");
  839. AjaxResult approvalFlow = auditItemsService.createApprovalFlow(auditItems);
  840. Long code = Long.valueOf(String.valueOf(approvalFlow.get("code"))).longValue();
  841. if (code.equals(500L)) {
  842. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  843. }
  844. return approvalFlow;
  845. } else {
  846. TFeeDo tFeeDo = new TFeeDo();
  847. tFeeDo.setfPid(fId);
  848. List<TFeeDo> tFeeDoList = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  849. for (TFeeDo feeDo : tFeeDoList) {
  850. // 跟新费用明细
  851. int m = updateBillsFees(fId, feeDo, billsType);
  852. if (m == 0) {
  853. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  854. return AjaxResult.error("更新费用明细失败");
  855. }
  856. }
  857. }
  858. AjaxResult ajaxResult = tfeeFollow(tFee.getfId(), 6L);
  859. Long code = Long.valueOf(String.valueOf(ajaxResult.get("code"))).longValue();
  860. return ajaxResult;
  861. }
  862. return AjaxResult.success();
  863. }
  864. @Override
  865. @Transactional
  866. public AjaxResult confirmKaiHe(String tfee, String tfeeDo, String tFeeInvoice, LoginUser loginUser, String fBilltype) {
  867. Long fPid = null;
  868. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  869. Map<String, Object> messageMap = new HashMap<>();
  870. String key = "";
  871. boolean isApprove = false;
  872. long actId = 0L;
  873. String billStatus = "";
  874. if ("DZ".equals(fBilltype)) {
  875. actId = 210L;
  876. key = "warehouse.contrast.ApprovalFlow";
  877. } else if ("SF".equals(fBilltype)) {
  878. actId = 220L;
  879. key = "warehouse.charge.ApprovalFlow";
  880. } else if ("FF".equals(fBilltype)) {
  881. actId = 230L;
  882. key = "warehouse.payment.ApprovalFlow";
  883. } else if ("KHDZ".equals(fBilltype)) {
  884. actId = 430L;
  885. key = "warehouse.kaiHeContrast.ApprovalFlow";
  886. } else if ("KHSF".equals(fBilltype)) {
  887. actId = 440L;
  888. key = "warehouse.kaiHeCharge.ApprovalFlow";
  889. } else if ("KHFF".equals(fBilltype)) {
  890. actId = 450L;
  891. key = "warehouse.kaiHePayment.ApprovalFlow";
  892. } else if ("ApplyFP".equals(fBilltype)) {
  893. actId = 470L;
  894. key = "warehouse.kaiHeApplyFP.ApprovalFlow";
  895. }
  896. SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique(key);
  897. if (StringUtils.isNull(sysConfig)) {
  898. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  899. return AjaxResult.error("系统参数异常,未找到开启审批流参数");
  900. }
  901. if ("0".equals(sysConfig.getConfigValue())) {
  902. isApprove = true;
  903. }
  904. if (isApprove) {
  905. billStatus = "4";
  906. } else {
  907. billStatus = "6";
  908. }
  909. if (StringUtils.isNull(tFee.getfId())) {
  910. // 如果是新数据
  911. tFee.setCreateBy(loginUser.getUser().getUserName());
  912. tFee.setfDeptid(loginUser.getUser().getDeptId());
  913. tFee.setfBilltype(fBilltype);
  914. // 业务编码
  915. Date time = new Date();
  916. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  917. tFee.setfBillno(billNo);
  918. tFee.setfBillstatus(billStatus);
  919. tFeeMapper.insertTFee(tFee);
  920. fPid = tFee.getfId();
  921. } else {
  922. fPid = tFee.getfId();
  923. boolean change = this.change(fPid);
  924. if (!change) {
  925. return AjaxResult.error("当前数据不支持修改");
  926. }
  927. tFee.setUpdateBy(loginUser.getUser().getUserName());
  928. tFee.setUpdateTime(new Date());
  929. tFee.setfBillstatus(billStatus);
  930. tFeeMapper.updateTFee(tFee);
  931. // 删除从表
  932. tFeeDoMapper.deleteByFPid(tFee.getfId());
  933. //删除开票从表
  934. tFeeInvoiceMapper.deleteByFPid(tFee.getfId());
  935. }
  936. messageMap.put("tFee", tFee);
  937. // 财务从表
  938. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  939. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  940. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  941. for (TFeeDo tFeeDo : tFeeDoList) {
  942. Map<String, Object> map = this.judgeMoney(tFeeDo.getfSrcid(), tFeeDo.getfAmt(), fBilltype, tFeeDo.getfFeeid());
  943. boolean b = (Boolean) map.get("flag");
  944. if (b == false) {
  945. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  946. return AjaxResult.error(map.get("message").toString());
  947. }
  948. tFeeDo.setfPid(tFee.getfId());
  949. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  950. tFeeDo.setCreateTime(new Date());
  951. tFeeDo.setfStatus(billStatus);
  952. tFeeDoMapper.insertTFeeDo(tFeeDo);
  953. }
  954. }
  955. if (!"".equals(tFeeInvoice) && tFeeInvoice != null && !"null".equals(tFeeInvoice)) {
  956. JSONArray jsonDrArray = JSONArray.parseArray(tFeeInvoice);
  957. List<TFeeInvoice> tFeeInvoiceList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeInvoice.class);
  958. for (TFeeInvoice feeInvoice : tFeeInvoiceList) {
  959. feeInvoice.setfPid(fPid);
  960. feeInvoice.setCreateBy(loginUser.getUser().getUserName());
  961. feeInvoice.setCreateTime(new Date());
  962. feeInvoice.setfBillstatus(billStatus);
  963. tFeeInvoiceMapper.insertTFeeInvoice(feeInvoice);
  964. }
  965. }
  966. // 这里加个判断取系统参数来确定是否需要启用审批流
  967. if (isApprove) {
  968. AuditItems auditItems = new AuditItems();
  969. auditItems.setLevelId(0L);
  970. auditItems.setBillId(tFee.getfId());
  971. auditItems.setActId(actId);
  972. auditItems.setIffinalItem("F");
  973. auditItems.setBillNo(tFee.getfBillno()); // 业务编号
  974. auditItems.setRefno1(String.valueOf(tFee.getfCorpid())); // 货权方
  975. auditItems.setRefno2(fBilltype);// 财务类型
  976. auditItems.setRefno3(tFee.gettMblno());// 提单号
  977. auditItems.setSendUserId(loginUser.getUser().getUserId());
  978. auditItems.setSendName(loginUser.getUsername());
  979. auditItems.setSendTime(new Date());
  980. auditItems.setAuditUserId(loginUser.getUser().getUserId());
  981. auditItems.setAuditItem(new Date());
  982. auditItems.setAuditOpTime(new Date());
  983. auditItems.setFidStatus("f_billstatus");
  984. auditItems.setTimes(1L);
  985. auditItems.setAuditMsg("提交");
  986. auditItems.setAuditStatus("O");
  987. AjaxResult approvalFlow = auditItemsService.createApprovalFlow(auditItems);
  988. Long code = Long.valueOf(String.valueOf(approvalFlow.get("code"))).longValue();
  989. if (code.equals(500L)) {
  990. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  991. return AjaxResult.error("发票申请提交审核失败,请找管理员");
  992. }
  993. } else {
  994. if (StringUtils.isNotNull(tfeeDo) && !"[]".equals(tfeeDo)) {
  995. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  996. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  997. for (TFeeDo tFeeDo : tFeeDoList) {
  998. // 跟新费用明细
  999. int m = updateBillsFees(tFee.getfId(), tFeeDo, fBilltype);
  1000. if (m == 0) {
  1001. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1002. return AjaxResult.error("更新费用明细失败");
  1003. }
  1004. }
  1005. }
  1006. AjaxResult ajaxResult = tfeeFollow(tFee.getfId(), 6L);
  1007. Long code = Long.valueOf(String.valueOf(ajaxResult.get("code"))).longValue();
  1008. if (code.equals(500L)) {
  1009. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1010. return AjaxResult.error("发票申请提交审核失败,请找管理员");
  1011. }
  1012. }
  1013. return AjaxResult.success("成功", messageMap);
  1014. }
  1015. /**
  1016. * 根据财务主表id 更新对应明细表状态
  1017. *
  1018. * @param fPid 财务主表id
  1019. * @return 结果
  1020. */
  1021. @Transactional
  1022. public AjaxResult tfeeFollow(Long fPid, long fettle) {
  1023. if (StringUtils.isNull(fPid)) {
  1024. return AjaxResult.error("财务更新状态未找到主表信息,请与管理员联系");
  1025. }
  1026. TFee tFee = new TFee();
  1027. tFee.setfId(fPid);
  1028. tFee.setfBillstatus(String.valueOf(fettle));
  1029. int tFeeUpdateResult = tFeeMapper.updateTFee(tFee);
  1030. if (tFeeUpdateResult <= 0) {
  1031. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1032. return AjaxResult.error("更新财务明细状态失败,请联系管理员");
  1033. }
  1034. try {
  1035. int itemUpdateResult = tFeeDoMapper.tfeeDoFollowUpdate(fPid, fettle);
  1036. } catch (Exception exception) {
  1037. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1038. return AjaxResult.error("更新财务明细状态失败,请联系管理员");
  1039. }
  1040. TFeeInvoice invoice = new TFeeInvoice();
  1041. invoice.setfPid(fPid);
  1042. List<TFeeInvoice> tFeeInvoiceList = tFeeInvoiceMapper.selectTFeeInvoiceList(invoice);
  1043. if (CollectionUtils.isNotEmpty(tFeeInvoiceList)) {
  1044. try {
  1045. int itemUpdateResult = tFeeInvoiceMapper.tFeeInvoiceUpdate(fPid, fettle);
  1046. } catch (Exception exception) {
  1047. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1048. return AjaxResult.error("更新开票明细状态失败,请联系管理员");
  1049. }
  1050. }
  1051. return AjaxResult.success();
  1052. }
  1053. @Transactional
  1054. public AjaxResult billsfeesFollow(Long fPid) {
  1055. if (StringUtils.isNull(fPid)) {
  1056. return AjaxResult.error("费用明细更新状态未找到主表信息,请与管理员联系");
  1057. }
  1058. TFee tFee = tFeeMapper.selectTFeeById(fPid);
  1059. // 查询从表数据
  1060. TFeeDo tFeeDo = new TFeeDo();
  1061. tFeeDo.setfPid(fPid);
  1062. List<TFeeDo> tFeeDoList = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  1063. for (TFeeDo tFeeDo1 : tFeeDoList) {
  1064. // 跟新费用明细
  1065. Map<String, Object> map = this.judgeMoney(tFeeDo1.getfSrcid(), tFeeDo1.getfAmt(), tFee.getfBilltype(), tFeeDo1.getfFeeid());
  1066. if (!(Boolean) map.get("flag")) {
  1067. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1068. return AjaxResult.error(map.get("message").toString());
  1069. }
  1070. int m = updateBillsFees(fPid, tFeeDo1, tFee.getfBilltype());
  1071. if (m == 0) {
  1072. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1073. return AjaxResult.error("更新费用明细失败");
  1074. }
  1075. }
  1076. return AjaxResult.success();
  1077. }
  1078. @Override
  1079. @Transactional
  1080. public AjaxResult revoke(String tfee, String tfeeDo, LoginUser loginUser, String fBilltype) {
  1081. // 更新 主表、从表
  1082. TFee tFee = JSONArray.parseObject(tfee, TFee.class);
  1083. if ("DZApplyFP".equals(fBilltype)) {
  1084. TFee fee = tFeeMapper.selectTFeeById(tFee.getfId());
  1085. if (fee.getfMake() == 1) {
  1086. return AjaxResult.error("该申请发票已开销项发票,不能撤销");
  1087. }
  1088. }
  1089. tFee.setUpdateBy(loginUser.getUser().getUserName());
  1090. tFee.setUpdateTime(new Date());
  1091. tFeeMapper.updateTFee(tFee);
  1092. // 删除从表
  1093. tFeeDoMapper.deleteByFPid(tFee.getfId());
  1094. // 财务从表
  1095. if (StringUtils.isNotNull(tfeeDo)) {
  1096. JSONArray jsonDrArray = JSONArray.parseArray(tfeeDo);
  1097. List<TFeeDo> tFeeDoList = JSONObject.parseArray(jsonDrArray.toJSONString(), TFeeDo.class);
  1098. for (TFeeDo tFeeDo : tFeeDoList) {
  1099. tFeeDo.setfPid(tFee.getfId());
  1100. tFeeDo.setCreateBy(loginUser.getUser().getUserName());
  1101. tFeeDo.setCreateTime(new Date());
  1102. tFeeDoMapper.insertTFeeDo(tFeeDo);
  1103. // 跟新费用明细
  1104. int m = updateBillsFees(tFee.getfId(), tFeeDo, fBilltype);
  1105. if (m == 0) {
  1106. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1107. return AjaxResult.error("更新费用明细失败");
  1108. }
  1109. }
  1110. }
  1111. return AjaxResult.success();
  1112. }
  1113. @Override
  1114. public AjaxResult queryRemove(Long fId) {
  1115. TFee tFee = tFeeMapper.selectTFeeById(fId);
  1116. TFeeDo tFeeDo = new TFeeDo();
  1117. tFeeDo.setfPid(tFee.getfId());
  1118. List<TFeeDo> tFeeDoList = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  1119. if (StringUtils.isNull(tFee)) {
  1120. return AjaxResult.success("0");
  1121. } else if (StringUtils.isNotNull(tFee) && StringUtils.isEmpty(tFeeDoList)) {
  1122. return AjaxResult.success("1");
  1123. } else if (tFee.getfBilltype().equals("INV") && tFee.getfAccountId() != null) {
  1124. return AjaxResult.success("3");
  1125. } else {
  1126. return AjaxResult.success("2");
  1127. }
  1128. }
  1129. @Override
  1130. @Transactional
  1131. public AjaxResult remove(Long fId) {
  1132. TFee tFee = tFeeMapper.selectTFeeById(fId);
  1133. if ("4".equals(tFee.getfBillstatus())) {
  1134. return AjaxResult.error("数据已提交审批,暂不能删除");
  1135. } else if ("5".equals(tFee.getfBillstatus())) {
  1136. return AjaxResult.error("数据正在审批,暂不能删除");
  1137. } else if ("6".equals(tFee.getfBillstatus())) {
  1138. return AjaxResult.error("数据审批完成,不能删除");
  1139. } else {
  1140. try {
  1141. tFeeMapper.deleteTFeeById(fId);
  1142. tFeeDoMapper.deleteByFPid(fId);
  1143. tFeeInvoiceMapper.deleteByFPid(fId);
  1144. } catch (Exception e) {
  1145. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1146. return AjaxResult.error("删除失败,请找管理员");
  1147. }
  1148. return AjaxResult.success();
  1149. }
  1150. }
  1151. @Override
  1152. public List<TWareHouseExcelItem> selectTWarehousebillsItemsList(Long fId) {
  1153. List<TWareHouseExcelItem> tWareHouseExcelItemList = tFeeMapper.selectTWarehousebillsItemsList(fId);
  1154. List<TWareHouseExcelItem> tWareHouseExcelItemList1 = new ArrayList<>();
  1155. for (TWareHouseExcelItem tWareHouseExcelItem : tWareHouseExcelItemList) {
  1156. if (StringUtils.isNotNull(tWareHouseExcelItem.getfBusinessType())) {
  1157. List<SysDictData> sysDictDataListIn = new ArrayList<>();
  1158. SysDictData sysDictData = new SysDictData();
  1159. if (tWareHouseExcelItem.getfBilltype().equals("入库")) {
  1160. sysDictData.setDictType(ST_IN_TYPE);
  1161. sysDictData.setDictValue(String.valueOf(tWareHouseExcelItem.getfBusinessType()));
  1162. sysDictData.setStatus("0");
  1163. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  1164. } else if (tWareHouseExcelItem.getfBilltype().equals("出库")) {
  1165. sysDictData.setDictType(ST_OUT_TYPE);
  1166. sysDictData.setDictValue(String.valueOf(tWareHouseExcelItem.getfBusinessType()));
  1167. sysDictData.setStatus("0");
  1168. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  1169. } else if (tWareHouseExcelItem.getfBilltype().equals("调拨") | tWareHouseExcelItem.getfBilltype().equals("货物通关")) {
  1170. sysDictData.setDictType(ST_TRANS_TYPE);
  1171. sysDictData.setDictValue(String.valueOf(tWareHouseExcelItem.getfBusinessType()));
  1172. sysDictData.setStatus("0");
  1173. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  1174. }
  1175. if (null != sysDictDataListIn && sysDictDataListIn.size() > 0) {
  1176. tWareHouseExcelItem.setfBusinessType(sysDictDataListIn.get(0).getDictLabel());
  1177. }
  1178. }
  1179. tWareHouseExcelItemList1.add(tWareHouseExcelItem);
  1180. }
  1181. return tWareHouseExcelItemList1;
  1182. }
  1183. @Override
  1184. public String findCtrlcorpid(Long fId) {
  1185. TFee tFee = tFeeMapper.selectTFeeById(fId);
  1186. String exportName = tFee.getfCtrlcorpid() + "-" + tFee.getfBillno();
  1187. return exportName;
  1188. }
  1189. @Override
  1190. public List<Receivable> receivableExport(TWareHouseFees tWareHouseFees) throws Exception {
  1191. List<Map<String, Object>> list = tFeeMapper.warehouseBillsFeesList1(tWareHouseFees);
  1192. List<Receivable> list1 = ListMapToBeanUtils.castMapToBean(list, Receivable.class);
  1193. return list1;
  1194. }
  1195. @Override
  1196. public List<Payable> payableExport(TWareHouseFees tWareHouseFees) throws Exception {
  1197. List<Map<String, Object>> list = tFeeMapper.warehouseBillsFeesList1(tWareHouseFees);
  1198. List<Payable> list1 = ListMapToBeanUtils.castMapToBean(list, Payable.class);
  1199. return list1;
  1200. }
  1201. @Override
  1202. public List<Profit> profitExport(TWareHouseFees tWareHouseFees) throws Exception {
  1203. List<Map<String, Object>> list = tFeeMapper.warehouseBillsFeesProfitList(tWareHouseFees);
  1204. List<Profit> list1 = ListMapToBeanUtils.castMapToBean(list, Profit.class);
  1205. return list1;
  1206. }
  1207. @Override
  1208. public List<Contrast> contrastExport(TFee tFee) throws Exception {
  1209. List<Map<String, Object>> list = tFeeMapper.selectTFeeList1(tFee);
  1210. List<Contrast> list1 = ListMapToBeanUtils.castMapToBean(list, Contrast.class);
  1211. return list1;
  1212. }
  1213. @Override
  1214. public List<Payment> paymentExport(TFee tFee) throws Exception {
  1215. List<Map<String, Object>> list = tFeeMapper.selectFeeList(tFee);
  1216. List<Payment> list1 = ListMapToBeanUtils.castMapToBean(list, Payment.class);
  1217. return list1;
  1218. }
  1219. @Override
  1220. public List<Charge> chargeExport(TFee tFee) throws Exception {
  1221. List<Map<String, Object>> list = tFeeMapper.selectFeeList(tFee);
  1222. List<Charge> list1 = ListMapToBeanUtils.castMapToBean(list, Charge.class);
  1223. return list1;
  1224. }
  1225. @Override
  1226. public List<Account> accountExport(TFee tFee) throws Exception {
  1227. List<Map<String, Object>> list = tFeeMapper.webVersionTFee(tFee);
  1228. List<Account> accountList = ListMapToBeanUtils.castMapToBean(list, Account.class);
  1229. return accountList;
  1230. }
  1231. @Override
  1232. public List<Detailed> selectDetailedList(Long fId) {
  1233. List<Detailed> detailedList = tFeeMapper.selectDetailedList(fId);
  1234. List<Detailed> detailedList1 = new ArrayList<>();
  1235. for (Detailed tWareHouseExcelItem : detailedList) {
  1236. if (StringUtils.isNotNull(tWareHouseExcelItem.getfBusinessType())) {
  1237. List<SysDictData> sysDictDataListIn = new ArrayList<>();
  1238. SysDictData sysDictData = new SysDictData();
  1239. if (tWareHouseExcelItem.getfBilltype().equals("入库")) {
  1240. sysDictData.setDictType(ST_IN_TYPE);
  1241. sysDictData.setDictValue(String.valueOf(tWareHouseExcelItem.getfBusinessType()));
  1242. sysDictData.setStatus("0");
  1243. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  1244. } else if (tWareHouseExcelItem.getfBilltype().equals("出库")) {
  1245. sysDictData.setDictType(ST_OUT_TYPE);
  1246. sysDictData.setDictValue(String.valueOf(tWareHouseExcelItem.getfBusinessType()));
  1247. sysDictData.setStatus("0");
  1248. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  1249. } else if (tWareHouseExcelItem.getfBilltype().equals("调拨") | tWareHouseExcelItem.getfBilltype().equals("货物通关")) {
  1250. sysDictData.setDictType(ST_TRANS_TYPE);
  1251. sysDictData.setDictValue(String.valueOf(tWareHouseExcelItem.getfBusinessType()));
  1252. sysDictData.setStatus("0");
  1253. sysDictDataListIn = iSysDictDataService.selectDictDataList(sysDictData);
  1254. }
  1255. if (null != sysDictDataListIn && sysDictDataListIn.size() > 0) {
  1256. tWareHouseExcelItem.setfBusinessType(sysDictDataListIn.get(0).getDictLabel());
  1257. }
  1258. }
  1259. detailedList1.add(tWareHouseExcelItem);
  1260. }
  1261. return detailedList1;
  1262. }
  1263. @Override
  1264. public List<Map<String, Object>> selectdetailedList(TWarehousebill tWarehousebill) {
  1265. return tFeeMapper.selectDetailedList1(tWarehousebill);
  1266. }
  1267. /**
  1268. * 更新费用明细
  1269. *
  1270. * @param fid
  1271. * @param tFeeDo
  1272. * @param billsType
  1273. * @return
  1274. */
  1275. @Transactional
  1276. public int updateBillsFees(Long fid, TFeeDo tFeeDo, String billsType) {
  1277. // 查询从表数据
  1278. TFee tFee = tFeeMapper.selectTFeeById(fid);
  1279. if (billsType.equals("SF") || billsType.equals("FF")
  1280. || billsType.equals("KHSF") || billsType.equals("KHFF")) {
  1281. billsType = "DC";
  1282. }
  1283. Map<String, Object> map = new HashMap<>();
  1284. map.put("tFee", tFee);
  1285. map.put("billType", billsType);
  1286. map.put("tFeeDo", tFeeDo);
  1287. return tWarehousebillsfeesMapper.updateTWarehousebillsfee(map);
  1288. }
  1289. public boolean change(Long fId) {
  1290. boolean flag = false;
  1291. TFee tFee = tFeeMapper.selectTFeeById(fId);
  1292. if ("4".equals(tFee.getfBillstatus())
  1293. || "5".equals(tFee.getfBillstatus())
  1294. || "6".equals(tFee.getfBillstatus())) {
  1295. flag = false;
  1296. } else {
  1297. flag = true;
  1298. }
  1299. return flag;
  1300. }
  1301. @Override
  1302. @Transactional
  1303. public AjaxResult webVersionSubmitApplyFP(TFee tFee, LoginUser loginUser, String fBilltype) {
  1304. String key = "";
  1305. boolean isApprove = false;
  1306. long actId = 0L;
  1307. String billStatus = "";
  1308. if ("ApplyFP".equals(fBilltype)) {
  1309. actId = 470L;
  1310. key = "warehouse.kaiHeApplyFP.ApprovalFlow";
  1311. }
  1312. SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique(key);
  1313. if (StringUtils.isNull(sysConfig)) {
  1314. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1315. return AjaxResult.error("系统参数异常,未找到开启审批流参数");
  1316. }
  1317. if ("0".equals(sysConfig.getConfigValue())) {
  1318. isApprove = true;
  1319. }
  1320. if (isApprove) {
  1321. billStatus = "4";
  1322. } else {
  1323. billStatus = "6";
  1324. }
  1325. /*for (Long getfId : tFee.getfIds()) {*/
  1326. TFee fee = tFeeMapper.selectTFeeById(tFee.getfId());
  1327. if (fee == null) {
  1328. return AjaxResult.error("财务主表数据有误,请确认");
  1329. }
  1330. boolean change = this.change(tFee.getfId());
  1331. if (change == false) {
  1332. return AjaxResult.error("数据正在审批或审批通过,不允许提交审核");
  1333. }
  1334. fee.setfId(tFee.getfId());
  1335. fee.setfBillstatus(billStatus);
  1336. fee.setUpdateBy(loginUser.getUser().getUserName());
  1337. fee.setUpdateTime(new Date());
  1338. int updateTFee = tFeeMapper.updateTFee(fee);
  1339. if (updateTFee <= 0) {
  1340. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1341. return AjaxResult.error("更新财务主表数据出错,请找管理员");
  1342. }
  1343. TFeeDo tFeeDo = new TFeeDo();
  1344. tFeeDo.setfPid(tFee.getfId());
  1345. List<TFeeDo> tFeeDos = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  1346. if (CollectionUtils.isEmpty(tFeeDos)) {
  1347. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1348. return AjaxResult.error("财务从表数据有误,请确认");
  1349. }
  1350. for (TFeeDo feeDo : tFeeDos) {
  1351. feeDo.setfId(feeDo.getfId());
  1352. feeDo.setfStatus(billStatus);
  1353. feeDo.setUpdateBy(loginUser.getUser().getUserName());
  1354. feeDo.setUpdateTime(new Date());
  1355. int i = tFeeDoMapper.updateTFeeDo(feeDo);
  1356. if (i <= 0) {
  1357. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1358. return AjaxResult.error("更新财务主表数据出错,请找管理员");
  1359. }
  1360. }
  1361. TFeeInvoice tFeeInvoice = new TFeeInvoice();
  1362. tFeeInvoice.setfPid(tFee.getfId());
  1363. List<TFeeInvoice> tFeeInvoiceList = tFeeInvoiceMapper.selectTFeeInvoiceList(tFeeInvoice);
  1364. if (CollectionUtils.isNotEmpty(tFeeInvoiceList)) {
  1365. for (TFeeInvoice invoice : tFeeInvoiceList) {
  1366. tFeeInvoice.setfBillstatus(billStatus);
  1367. tFeeInvoice.setfId(invoice.getfId());
  1368. tFeeInvoice.setUpdateBy(loginUser.getUser().getUserName());
  1369. tFeeInvoice.setUpdateTime(new Date());
  1370. tFeeInvoiceMapper.updateTFeeInvoice(tFeeInvoice);
  1371. }
  1372. }
  1373. //添加审批流
  1374. if (isApprove) {
  1375. AuditItems auditItems = new AuditItems();
  1376. auditItems.setLevelId(0L);
  1377. auditItems.setBillId(fee.getfId());
  1378. auditItems.setActId(actId);
  1379. auditItems.setIffinalItem("F");
  1380. auditItems.setBillNo(fee.getfBillno()); // 业务编号
  1381. auditItems.setRefno1(String.valueOf(fee.getfCorpid())); // 货权方
  1382. auditItems.setRefno2(fee.getfBilltype());// 财务类型
  1383. auditItems.setRefno3(fee.gettMblno());// 提单号
  1384. auditItems.setSendUserId(loginUser.getUser().getUserId());
  1385. auditItems.setSendName(loginUser.getUsername());
  1386. auditItems.setSendTime(new Date());
  1387. auditItems.setAuditUserId(loginUser.getUser().getUserId());
  1388. auditItems.setAuditItem(new Date());
  1389. auditItems.setAuditOpTime(new Date());
  1390. auditItems.setFidStatus("f_billstatus");
  1391. auditItems.setTimes(1L);
  1392. auditItems.setAuditMsg("提交");
  1393. auditItems.setAuditStatus("O");
  1394. AjaxResult approvalFlow = auditItemsService.createApprovalFlow(auditItems);
  1395. Long code = Long.valueOf(String.valueOf(approvalFlow.get("code"))).longValue();
  1396. if (code.equals(500L)) {
  1397. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1398. return AjaxResult.error("提交审核失败,请找管理员");
  1399. }
  1400. return approvalFlow;
  1401. } else {
  1402. for (TFeeDo t : tFeeDos) {
  1403. // 跟新费用明细
  1404. int m = updateBillsFees(tFee.getfId(), t, fBilltype);
  1405. if (m == 0) {
  1406. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1407. return AjaxResult.error("更新费用明细失败");
  1408. }
  1409. }
  1410. AjaxResult ajaxResult = tfeeFollow(tFee.getfId(), 6L);
  1411. Long code = Long.valueOf(String.valueOf(ajaxResult.get("code"))).longValue();
  1412. if (code.equals(500L)) {
  1413. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1414. return AjaxResult.error("提交审核失败,请找管理员");
  1415. }
  1416. return ajaxResult;
  1417. }
  1418. /*}*/
  1419. //return AjaxResult.success();
  1420. }
  1421. @Override
  1422. public AjaxResult webVersionUpdateApplyFP(TFee tFee, LoginUser loginUser, String billType) {
  1423. TFeeInvoice tFeeInvoice = tFee.gettFeeInvoice();
  1424. tFeeInvoice.setfPid(tFee.getfId());
  1425. int i = 0;
  1426. if (tFeeInvoice.getfId() != null) {
  1427. tFeeInvoice.setUpdateBy(loginUser.getUser().getUserName());
  1428. tFeeInvoice.setUpdateTime(new Date());
  1429. i = tFeeInvoiceMapper.updateTFeeInvoice(tFeeInvoice);
  1430. } else {
  1431. return AjaxResult.error("开票信息为空,请找管理员");
  1432. }
  1433. if (i <= 0) {
  1434. return AjaxResult.error("更新数据失败,请找管理员");
  1435. } else {
  1436. return AjaxResult.success();
  1437. }
  1438. }
  1439. @Override
  1440. public List<FinancialTFee> selectFinancialTFeeList(TFee tFee) {
  1441. return tFeeMapper.selectFinancialTFeeList(tFee);
  1442. }
  1443. @Override
  1444. public List<Map<String, Object>> FinancialFeesList(TWareHouseFees tWareHouseFees) {
  1445. Map<String, Object> map = new HashMap<>();
  1446. map.put("tWareHouseFees", tWareHouseFees);
  1447. return tFeeMapper.FinancialFeesList(map);
  1448. }
  1449. @Override
  1450. public Map<String, Object> selectFinancialTFeeId(Long fId) {
  1451. Map<String,Object> map = new HashMap<>();
  1452. FinancialTFee financialTFee = tFeeMapper.selectFinancialTFeeId(fId);
  1453. List<FinancialTFeeDoExcel> financialTFeeDoExcels = tFeeDoMapper.selectFinancialTFeeDo(fId);
  1454. map.put("tFee", financialTFee);
  1455. map.put("tFeeDo", financialTFeeDoExcels);
  1456. return map;
  1457. }
  1458. @Override
  1459. public List<FinancialTFeeDoExcel> FinancialTFeeDoExcel(Long fId) {
  1460. return tFeeDoMapper.selectFinancialTFeeDo(fId);
  1461. }
  1462. @Override
  1463. @Transactional
  1464. public AjaxResult webVersionApplyFP(TFee tFee, LoginUser loginUser, String fBilltype, TFeeInvoice tFeeInvoice) {
  1465. Long fPid = null;
  1466. String billStatus = "2";
  1467. try {
  1468. /*for (Long getfId : tFee.getfIds()) {*/
  1469. TFee account = new TFee();
  1470. TFee fee = tFeeMapper.selectTFeeById(tFee.getfId());
  1471. if (fee == null) {
  1472. return AjaxResult.error("财务主表数据有误,请确认");
  1473. }
  1474. account.setfId(fee.getfId());
  1475. account.setfMake(1);
  1476. fee.setfBilltype(fBilltype);
  1477. fee.setfBillstatus(billStatus);
  1478. fee.setCreateBy(loginUser.getUser().getUserName());
  1479. fee.setCreateTime(new Date());
  1480. fee.setfDeptid(loginUser.getUser().getDeptId());
  1481. fee.setUpdateBy(null);
  1482. fee.setUpdateTime(null);
  1483. fee.setfInvoiceRise(tFee.getfInvoiceRise());
  1484. fee.setfAccountId(fee.getfId());
  1485. Date time = new Date();
  1486. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  1487. fee.setfBillno(billNo);
  1488. fee.setfAccbilldate(null);
  1489. fee.setfId(null);
  1490. tFeeMapper.insertTFee(fee);
  1491. tFeeMapper.updateTFee(account);
  1492. //修改原来的数据的开票金额
  1493. fPid = fee.getfId();
  1494. TFeeDo tFeeDo = new TFeeDo();
  1495. tFeeDo.setfPid(tFee.getfId());
  1496. List<TFeeDo> tFeeDos = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  1497. if (CollectionUtils.isEmpty(tFeeDos)) {
  1498. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1499. return AjaxResult.error("财务从表数据有误,请确认");
  1500. }
  1501. for (TFeeDo feeDo : tFeeDos) {
  1502. feeDo.setfPid(fPid);
  1503. feeDo.setfStatus(billStatus);
  1504. feeDo.setCreateBy(loginUser.getUser().getUserName());
  1505. feeDo.setCreateTime(new Date());
  1506. feeDo.setUpdateBy(null);
  1507. feeDo.setUpdateTime(null);
  1508. int i = tFeeDoMapper.insertTFeeDo(feeDo);
  1509. }
  1510. tFeeInvoice.setfBillstatus(billStatus);
  1511. tFeeInvoice.setfPid(fPid);
  1512. tFeeInvoice.setCreateBy(loginUser.getUser().getUserName());
  1513. tFeeInvoice.setCreateTime(new Date());
  1514. tFeeInvoiceMapper.insertTFeeInvoice(tFeeInvoice);
  1515. /*}*/
  1516. } catch (Exception e) {
  1517. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1518. return AjaxResult.error("申请发票出错,请找管理员");
  1519. }
  1520. return AjaxResult.success();
  1521. }
  1522. /**
  1523. * 判断金额是否超过可用金额
  1524. *
  1525. * @param fid 费用明细表主键
  1526. * @param money 申请金额
  1527. * @param type DZ 对账 SF 收费 FF 付费 ApplyFP 开票申请 invoiceFP 开票
  1528. * @return
  1529. */
  1530. public Map<String, Object> judgeMoney(long fid, BigDecimal money, String type, Long feeId) {
  1531. Map<String, Object> map = new HashMap<>();
  1532. boolean flag = true;
  1533. TWarehousebillsfees warehousebillsfees = tWarehousebillsfeesMapper.selectTWarehousebillsfeesById(fid);
  1534. TFees tFees = tFeesMapper.selectTFeesById(feeId);
  1535. BigDecimal amount = warehousebillsfees.getfAmount();//金额
  1536. BigDecimal accamount = warehousebillsfees.getfAccamount();//对账金额
  1537. BigDecimal stlamount = warehousebillsfees.getfStlamount();//结算金额
  1538. BigDecimal invamount = warehousebillsfees.getfInvamount();//开票金额a
  1539. BigDecimal askamount = warehousebillsfees.getfAskamount();//申请金额
  1540. if (warehousebillsfees == null) {
  1541. map.put("message", "费用明细数据有误,请找管理员");
  1542. } else if ("DZ".equals(type) || "KHDZ".equals(type)) {
  1543. BigDecimal subtract = amount.subtract(accamount);
  1544. if (subtract.compareTo(money) < 0) {
  1545. flag = false;
  1546. map.put("message", tFees.getfName() + "对账金额超过可对账金额,当前可对账金额为" + subtract + "元");
  1547. }
  1548. } else if ("SF".equals(type) || "KHSF".equals(type)) {
  1549. BigDecimal subtract = amount.subtract(stlamount);
  1550. if (subtract.compareTo(money) < 0) {
  1551. flag = false;
  1552. map.put("message", tFees.getfName() + "收费金额超过可收费金额,当前可对账金额为" + subtract + "元");
  1553. }
  1554. } else if ("FF".equals(type) || "KHFF".equals(type)) {
  1555. BigDecimal subtract = amount.subtract(stlamount);
  1556. if (subtract.compareTo(money) < 0) {
  1557. flag = false;
  1558. map.put("message", tFees.getfName() + "付费金额超过可付费金额,当前可对账金额为" + subtract + "元");
  1559. }
  1560. } else if ("ApplyFP".equals(type)) {
  1561. BigDecimal subtract = amount.subtract(askamount);
  1562. if (subtract.compareTo(money) < 0) {
  1563. flag = false;
  1564. map.put("message", tFees.getfName() + "开票金额超过可开票金额,当前可对账金额为" + subtract + "元");
  1565. }
  1566. } else if ("invoiceFP".equals(type)) {
  1567. BigDecimal subtract = amount.subtract(invamount);
  1568. if (subtract.compareTo(money) < 0) {
  1569. flag = false;
  1570. map.put("message", tFees.getfName() + "开票金额超过可开票金额,当前可对账金额为" + subtract + "元");
  1571. }
  1572. }
  1573. map.put("flag", flag);
  1574. return map;
  1575. }
  1576. /**
  1577. * 申请发票审核成功复制数据到销项发票中
  1578. *
  1579. * @param fId 主表id
  1580. * @param fBilltype 类型
  1581. * @return
  1582. */
  1583. @Transactional
  1584. public AjaxResult copyInvoiceFp(Long fId, String fBilltype) {
  1585. //查询费用主表信息复制主表信息
  1586. Integer insert = null;
  1587. TFee fee = tFeeMapper.selectTFeeById(fId);
  1588. TFee tFee = new TFee();
  1589. tFee.setfId(fee.getfId());
  1590. Date time = new Date();
  1591. String billNo = billnoSerialServiceImpl.getBillNo(fBilltype, time);
  1592. //查询费用从表信息复制主表信息
  1593. fee.setfAccountId(fee.getfId());
  1594. fee.setfBillno(billNo);
  1595. fee.setfBilltype(fBilltype);
  1596. fee.setfId(null);
  1597. insert = tFeeMapper.insertTFee(fee);
  1598. tFee.setfMake(1);
  1599. //修改原发票数据代表已开销项发票
  1600. insert = tFeeMapper.updateTFee(tFee);
  1601. TFeeDo tFeeDo = new TFeeDo();
  1602. tFeeDo.setfPid(fId);
  1603. List<TFeeDo> tFeeDoList = tFeeDoMapper.selectTFeeDoList(tFeeDo);
  1604. if (CollectionUtils.isNotEmpty(tFeeDoList)) {
  1605. for (TFeeDo feeDo : tFeeDoList) {
  1606. feeDo.setfId(null);
  1607. feeDo.setfPid(fee.getfId());
  1608. feeDo.setfBilltype(fBilltype);
  1609. insert = tFeeDoMapper.insertTFeeDo(feeDo);
  1610. }
  1611. }
  1612. //查询开票信息复制主表信息
  1613. TFeeInvoice tFeeInvoice = new TFeeInvoice();
  1614. tFeeInvoice.setfPid(fId);
  1615. List<TFeeInvoice> tFeeInvoiceList = tFeeInvoiceMapper.selectTFeeInvoiceList(tFeeInvoice);
  1616. if (CollectionUtils.isNotEmpty(tFeeInvoiceList)) {
  1617. for (TFeeInvoice invoice : tFeeInvoiceList) {
  1618. invoice.setfId(null);
  1619. invoice.setfPid(fee.getfId());
  1620. insert = tFeeInvoiceMapper.insertTFeeInvoice(invoice);
  1621. }
  1622. }
  1623. if (insert != null && insert > 0) {
  1624. return AjaxResult.success();
  1625. } else {
  1626. return AjaxResult.error("生成销项发票失败,请找管理员");
  1627. }
  1628. }
  1629. }