OwnCreditController.java 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159
  1. package com.huyi.service.credit.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.huyi.service.base.entity.*;
  5. import com.huyi.service.base.service.*;
  6. import com.huyi.service.common.flowable.service.ApprovalService;
  7. import com.huyi.service.credit.service.OwnCreditService;
  8. import com.huyi.service.util.FlowableService;
  9. import com.keao.tianhu.starter.mybatis.plus.entity.QueryRequest;
  10. import com.tianhu.common.core.domain.R;
  11. import com.tianhu.common.core.utils.AmtUtil;
  12. import com.tianhu.common.core.utils.CommonUtil;
  13. import com.tianhu.common.core.utils.DateUtils;
  14. import com.tianhu.common.core.utils.IdUtils;
  15. import com.tianhu.common.core.web.controller.BaseController;
  16. import com.tianhu.common.core.web.domain.AjaxResult;
  17. import com.tianhu.common.log.annotation.Log;
  18. import com.tianhu.common.log.enums.BusinessType;
  19. import com.tianhu.common.security.annotation.PreAuthorize;
  20. import com.tianhu.common.security.service.TokenService;
  21. import com.tianhu.system.api.domain.SysUser;
  22. import com.tianhu.system.api.model.LoginUser;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.transaction.annotation.Transactional;
  25. import org.springframework.web.bind.annotation.*;
  26. import java.lang.reflect.InvocationTargetException;
  27. import java.text.SimpleDateFormat;
  28. import java.util.*;
  29. /**
  30. * 融信信息
  31. * xuefy
  32. * 2021-08-17
  33. */
  34. @RestController
  35. @RequestMapping("/ownCredit")
  36. public class OwnCreditController extends BaseController {
  37. @Autowired
  38. private TokenService tokenService;
  39. //自写融信服务类
  40. @Autowired
  41. private OwnCreditService ownCreditService;
  42. //核心授信服务类
  43. @Autowired
  44. private IZcFinanceProComRelService financeProComRelService;
  45. //融信应收付关系的服务类
  46. @Autowired
  47. private IZcFinanceBillRelService financeBillRelService;
  48. //融信应收付关系的服务类
  49. @Autowired
  50. private IZcFinanceInfService financeInfService;
  51. //供应商授信服务类
  52. @Autowired
  53. private IZcFinanceSupplierQuotaService financeSupplierQuotaService;
  54. //用户服务类
  55. @Autowired
  56. private ISysUserService sysUserService;
  57. //公司服务类
  58. @Autowired
  59. private ISysCompanyService companyService;
  60. //产品服务类
  61. @Autowired
  62. private IZcFinanceProductService productService;
  63. //收付款与发票关系表
  64. @Autowired
  65. private IZcBillInvoiceRelService billInvoiceRelService;
  66. //发票服务
  67. @Autowired
  68. private IZcInvoiceInfService invoiceInfService;
  69. //文件服务类
  70. @Autowired
  71. private IPubFileInfService fileInfService;
  72. //收付款和文件的关系表服务类
  73. @Autowired
  74. private IZcBillFileRelService billFileRelService;
  75. @Autowired
  76. private FlowableService flowableService;
  77. //审批服务类
  78. @Autowired
  79. private ApprovalService approvalService;
  80. /**
  81. * 查询融信信息
  82. * @param zfiNumber
  83. * @param zfiStatus
  84. * @param openCompany
  85. * @param receiveCompany
  86. * @param zfpName
  87. * @param zfiSignDate
  88. * @param zfiExpireDate
  89. * @param zfiRate
  90. * @param request
  91. * @return
  92. */
  93. @PreAuthorize(hasPermi = "credit:credit:list")
  94. @GetMapping("/list")
  95. public R list(
  96. @RequestParam(required=false) String zfiNumber,
  97. @RequestParam(required=false) String zfiStatus,
  98. @RequestParam(required=false) String openCompany,
  99. @RequestParam(required=false) String receiveCompany,
  100. @RequestParam(required=false) String zfpName,
  101. @RequestParam(required=false) String startAmt,
  102. @RequestParam(required=false) String endAmt,
  103. @RequestParam(required=false) Map zfiSignDate,
  104. @RequestParam(required=false) Map zfiExpireDate,
  105. @RequestParam(required=false) String zfiRate,
  106. QueryRequest request) {
  107. //查询当前操作员
  108. LoginUser userInfo = tokenService.getLoginUser();
  109. SysUser use = userInfo.getSysUser();
  110. //获取企业
  111. String companyId = use.getCompanyId();
  112. Map map = new HashMap();
  113. /*if (!SalaryConstants.OPEX.equals(companyId)) {
  114. map.put("ziiCompanyId", companyId);
  115. }*/
  116. //融信编号
  117. map.put("zfiNumber", zfiNumber);
  118. //状态
  119. if(!CommonUtil.isEmpty(zfiStatus)){
  120. List<String> stateList = new ArrayList<>();
  121. if(!zfiStatus.contains(",")){
  122. stateList.add(zfiStatus);
  123. }else{
  124. String arr [] = zfiStatus.split(",");
  125. for(int i = 0 ; i < arr.length;i++){
  126. if(!CommonUtil.isEmpty(arr[i])){
  127. stateList.add(arr[i]);
  128. }
  129. }
  130. }
  131. map.put("stateList",CommonUtil.listToStr4InSql(stateList));
  132. }
  133. //开立企业
  134. map.put("openCompany", openCompany);
  135. //接收企业
  136. map.put("receiveCompany", receiveCompany);
  137. //融资产品
  138. map.put("zfpName",zfpName);
  139. //利率
  140. map.put("zfiRate",CommonUtil.objToBigDecimal(zfiRate));
  141. //签收日期
  142. map.put("startTime",zfiSignDate.get("zfiSignDate[0]"));
  143. map.put("endTime",zfiSignDate.get("zfiSignDate[1]"));
  144. //承诺还款日
  145. map.put("zfiExpireDateStart",zfiExpireDate.get("zfiExpireDate[0]"));
  146. map.put("zfiExpireDateEnd",zfiExpireDate.get("zfiExpireDate[1]"));
  147. if(!CommonUtil.isEmpty(startAmt)){
  148. if(!AmtUtil.isMoney(startAmt)){
  149. return R.fail("请输入正确的融信金额开始范围值");
  150. }
  151. if(CommonUtil.isEmpty(endAmt)){
  152. return R.fail("请输入融信金额的结束范围值");
  153. }
  154. }
  155. if(!CommonUtil.isEmpty(endAmt)){
  156. if(CommonUtil.isEmpty(startAmt)){
  157. map.put("startAmt","0");
  158. }
  159. }
  160. //合同金额结束范围
  161. if(!CommonUtil.isEmpty(endAmt)){
  162. if(!AmtUtil.isMoney(endAmt)){
  163. return R.fail("请输入正确的融信金额结束范围值");
  164. }
  165. }
  166. if(!CommonUtil.isEmpty(startAmt) && !CommonUtil.isEmpty(endAmt)){
  167. if(CommonUtil.compare(startAmt,endAmt) == 1){
  168. return R.fail("融信金额范围输入有误");
  169. }
  170. }
  171. map.put("startAmt",CommonUtil.objToBigDecimal(startAmt));
  172. map.put("endAmt",CommonUtil.objToBigDecimal(endAmt));
  173. //获取企业类型
  174. String companyType = use.getCompanyType();
  175. map.put("companyType",companyType);
  176. map.put("companyId",companyId);
  177. IPage<Map> list = ownCreditService.selectCreditList(map,request);
  178. return R.ok(list);
  179. }
  180. /**
  181. * 获取融信详情
  182. * @param zfiId
  183. * @return
  184. */
  185. @PreAuthorize(hasPermi = "credit:credit:query")
  186. @GetMapping(value = "/{zfiId}")
  187. public AjaxResult getInfo(@PathVariable("zfiId") String zfiId,QueryRequest request) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
  188. //查询融信详情
  189. ZcFinanceInf financeInf = financeInfService.getById(zfiId);
  190. if(financeInf == null){
  191. return AjaxResult.error("获取融信信息失败");
  192. }
  193. //查询创建人
  194. String userId = financeInf.getCreateBy();
  195. com.huyi.service.base.entity.SysUser user = sysUserService.getById(userId);
  196. String createName = "";
  197. Map map = new HashMap();
  198. if(user != null){
  199. createName = user.getNickName();
  200. }
  201. //创建人
  202. map.put("createName",createName);
  203. //融信
  204. map.put("financeInf",financeInf);
  205. //接收方
  206. String zfiSupplierId = financeInf.getZfiSupplierId();
  207. SysCompany company = companyService.getById(zfiSupplierId);
  208. String receiveName = "";
  209. if(company != null){
  210. receiveName = company.getScyName();
  211. }
  212. map.put("receiveName",receiveName);
  213. //开立方
  214. String zfiCoreId = financeInf.getZfiCoreId();
  215. SysCompany coreCompany = companyService.getById(zfiCoreId);
  216. String openName = "";
  217. if(coreCompany != null){
  218. openName = coreCompany.getScyName();
  219. }
  220. map.put("openName",openName);
  221. //产品
  222. String productId = financeInf.getZfiProductId();
  223. ZcFinanceProduct product = productService.getById(productId);
  224. String zfpName = "";
  225. //意愿类型
  226. String zfpAuthType = "";
  227. if(product != null){
  228. zfpName = product.getZfpName();
  229. zfpAuthType = product.getZfpAuthType();
  230. }
  231. map.put("zfpName",zfpName);
  232. map.put("zfpAuthType",zfpAuthType);
  233. //获取核心授信额度信息
  234. String zfiCoreQuotaId = financeInf.getZfiCoreQuotaId();
  235. ZcFinanceProComRel proComRel = financeProComRelService.getById(zfiCoreQuotaId);
  236. map.put("proComRel",proComRel);
  237. //查询该融信下关联的应收付款
  238. LambdaQueryWrapper<ZcFinanceBillRel> relLambdaQueryWrapper = new LambdaQueryWrapper<>();
  239. relLambdaQueryWrapper.eq(ZcFinanceBillRel::getZfbrFinanceId,zfiId);
  240. List<ZcFinanceBillRel> relList = financeBillRelService.findZcFinanceBillRels(relLambdaQueryWrapper);
  241. if(relList.size() > 0 ){
  242. //提取应收付款的编号
  243. List<String> payIdList = CommonUtil.getIdFromList(relList,"zfbrBillId");
  244. Map p = new HashMap();
  245. p.put("payIdList",CommonUtil.listToStr4InSql(payIdList));
  246. IPage<Map> payList = ownCreditService.getAccountsPay(p,request);
  247. map.put("payList",payList);
  248. }
  249. return AjaxResult.success(map);
  250. }
  251. /**
  252. * 修改融信
  253. * @param map
  254. * @return
  255. * @throws Exception
  256. */
  257. @PreAuthorize(hasPermi = "credit:credit:update")
  258. @Log(title = "融信管理", businessType = BusinessType.UPDATE)
  259. @Transactional(rollbackFor = Exception.class)
  260. @PutMapping
  261. public AjaxResult edit(@RequestBody Map<String, Object> map) throws Exception{
  262. //获取此操作员
  263. LoginUser userInfo = tokenService.getLoginUser();
  264. SysUser user = userInfo.getSysUser();
  265. //获取用户编号
  266. String userId = user.getUserId()+"";
  267. //获取融信编号
  268. String id = CommonUtil.objToString(map.get("zfiId"));
  269. //获取融信的类型
  270. String type = CommonUtil.objToString(map.get("type"));
  271. //获取产品是否可拆分
  272. String zfpSplit = CommonUtil.objToString(map.get("zfpSplit"));
  273. //获取放款方式
  274. String zfpcrLoanType = CommonUtil.objToString(map.get("zfpcrLoanType"));
  275. //融信编号
  276. String str = "";
  277. //判断类型
  278. //开立
  279. if("1".equals(type) || "2".equals(type)){
  280. str = "CM";
  281. }else if("0".equals(type)){
  282. //申请
  283. str = "SM";
  284. }
  285. //产品不可拆分
  286. if("0".equals(zfpSplit)){
  287. str += "D";
  288. }else if("1".equals(zfpSplit)){
  289. //可拆分
  290. str += "R";
  291. }
  292. //放款方式--供应商
  293. if("0".equals(zfpcrLoanType)){
  294. str += "P";
  295. }else if("1".equals(zfpcrLoanType)){
  296. //平台电子记账
  297. str += "E";
  298. }
  299. ZcFinanceInf inf = new ZcFinanceInf();
  300. //主键
  301. inf.setZfiId(id);
  302. //非开立
  303. if(!"0".equals(type)){
  304. //获取之前的融信编号
  305. String zfiNumber = CommonUtil.objToString(map.get("zfiNumber"));
  306. //获取之前融信编号的时间戳
  307. String time = zfiNumber.substring(zfiNumber.length() - 14,zfiNumber.length());
  308. str += time;
  309. //融信编号
  310. inf.setZfiNumber(str);
  311. }
  312. //获取申请金额
  313. String zfiAmount = CommonUtil.objToString(map.get("zfiAmount"));
  314. if(CommonUtil.isEmpty(zfiAmount)){
  315. throw new Exception("请输入申请金额");
  316. }
  317. if(!AmtUtil.isMoney(zfiAmount)){
  318. throw new Exception("请输入正确的申请金额");
  319. }
  320. //非供应商申请
  321. if(!"0".equals(type)){
  322. //获取可用额度
  323. String availableAmt = CommonUtil.objToString(map.get("availableAmt"));
  324. if(CommonUtil.compare(zfiAmount,availableAmt) == 1){
  325. throw new Exception("签发金额不可大于可用额度");
  326. }
  327. //承诺付款日
  328. String zfiExpireDate = CommonUtil.objToString(map.get("zfiExpireDate"));
  329. //签发有效期
  330. String zfiEffectiveDate = CommonUtil.objToString(map.get("zfiEffectiveDate"));
  331. if(CommonUtil.isEmpty(zfiEffectiveDate)){
  332. throw new Exception("请选择签发有效期");
  333. }
  334. if(CommonUtil.isEmpty(zfiExpireDate)){
  335. throw new Exception("请选择承诺付款日");
  336. }
  337. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  338. Date date = simpleDateFormat.parse(zfiEffectiveDate);
  339. inf.setZfiEffectiveDate(date);
  340. Date signDate = simpleDateFormat.parse(zfiExpireDate);
  341. inf.setZfiExpireDate(signDate);
  342. }
  343. //修改人
  344. inf.setUpdateBy(userId);
  345. //修改时间
  346. inf.setUpdateTime(DateUtils.getNowDate());
  347. //获取产品
  348. String productId = CommonUtil.objToString(map.get("zfpId"));
  349. inf.setZfiProductId(productId);
  350. //获取收付款
  351. List<Map<String,String>> ticketList = (List<Map<String, String>>) map.get("ticketList");
  352. if("1".equals(type)){
  353. //核心企业授信额度
  354. String zfiCoreQuotaId = CommonUtil.objToString(map.get("zfiCoreQuotaId"));
  355. inf.setZfiCoreQuotaId(zfiCoreQuotaId);
  356. //接收企业
  357. String zfiSupplierId = CommonUtil.objToString(map.get("zfiSupplierId"));
  358. inf.setZfiSupplierId(zfiSupplierId);
  359. //选择
  360. if(ticketList.size() > 1){
  361. //获取第一个应收企业
  362. String receiveName = ticketList.get(0).get("receiveName");
  363. //获取预计还款日期
  364. String zbiPayDate = ticketList.get(0).get("zbiPayDate");
  365. for(int i = 0 ; i < ticketList.size();i++){
  366. if(!receiveName.equals(ticketList.get(i).get("receiveName"))){
  367. throw new Exception("请选择应收企业相同的应付账款");
  368. }
  369. if(!zbiPayDate.equals(ticketList.get(i).get("zbiPayDate"))){
  370. throw new Exception("请选择预计还款日期相同的应付账款");
  371. }
  372. }
  373. }
  374. }else if("0".equals(type) || "2".equals(type)){//供应商开立/申请
  375. //获取合计金额
  376. String checkTotalAmt = CommonUtil.objToString(map.get("checkTotalAmt"));
  377. //供应商开立
  378. if("2".equals(type)){
  379. //供应商企业授信额度
  380. String zfiSupplierQuotaId = CommonUtil.objToString(map.get("zfiSupplierQuotaId"));
  381. inf.setZfiSupplierQuotaId(zfiSupplierQuotaId);
  382. //获取供应商对应的核心授信额度
  383. ZcFinanceSupplierQuota supplierQuota = financeSupplierQuotaService.getById(zfiSupplierQuotaId);
  384. if(supplierQuota == null){
  385. throw new Exception("获取供应商授信额度失败");
  386. }
  387. String zfsqCoreQuotaId = supplierQuota.getZfsqCoreQuotaId();
  388. //核心授信额度
  389. inf.setZfiCoreQuotaId(zfsqCoreQuotaId);
  390. //获取收款账号
  391. /* String zfiCollectionAccount = CommonUtil.objToString(map.get("zfiCollectionAccount"));
  392. //获取放款方式--供应商指定的话为收款账号必输
  393. if("1".equals(zfpcrLoanType)){
  394. if(CommonUtil.isEmpty(zfiCollectionAccount)){
  395. throw new Exception("请输入收款账号");
  396. }
  397. }
  398. if(!"0".equals(zfpcrLoanType)){
  399. inf.setZfiCollectionAccount(zfiCollectionAccount);
  400. }*/
  401. }
  402. if(CommonUtil.compare(zfiAmount,checkTotalAmt) == 1){
  403. throw new Exception("签发金额不可大于合计金额");
  404. }
  405. if(ticketList.size() < 1){
  406. throw new Exception("请选择应收账款");
  407. }else if(ticketList.size() > 1){
  408. //获取第一个应付企业
  409. String payName = ticketList.get(0).get("payName");
  410. //获取预计还款日期
  411. String zbiPayDate = ticketList.get(0).get("zbiPayDate");
  412. for(int i = 0 ; i < ticketList.size();i++){
  413. if(!payName.equals(ticketList.get(i).get("payName"))){
  414. throw new Exception("请选择应付企业相同的应收账款");
  415. }
  416. if(!zbiPayDate.equals(ticketList.get(i).get("zbiPayDate"))){
  417. throw new Exception("请选择预计还款日期相同的应收账款");
  418. }
  419. }
  420. }
  421. //开立方==应付企业
  422. inf.setZfiCoreId(ticketList.get(0).get("zbiPayerId"));
  423. }
  424. //利率
  425. String zfiRate = CommonUtil.objToString(map.get("zfiRate"));
  426. inf.setZfiRate(zfiRate);
  427. //先删除该融信与应收付款的关系
  428. LambdaQueryWrapper<ZcFinanceBillRel> relLambdaQueryWrapper = new LambdaQueryWrapper<>();
  429. relLambdaQueryWrapper.eq(ZcFinanceBillRel::getZfbrFinanceId,id);
  430. financeBillRelService.deleteZcFinanceBillRel(relLambdaQueryWrapper);
  431. //插入融信和应收付款的关系
  432. for(int i = 0 ; i < ticketList.size();i++){
  433. //获取收付款编号
  434. String billId = ticketList.get(i).get("zbiId");
  435. ZcFinanceBillRel rel = new ZcFinanceBillRel();
  436. rel.setZfbrFinanceId(id);
  437. rel.setZfbrBillId(billId);
  438. financeBillRelService.createZcFinanceBillRel(rel);
  439. }
  440. inf.setZfiAmount(zfiAmount);
  441. //修改数据
  442. financeInfService.updateById(inf);
  443. return AjaxResult.success();
  444. }
  445. /**
  446. * 查询核心开立授信额度
  447. * @param zfpcrId
  448. * @return
  449. */
  450. @GetMapping("/getCreditLineList")
  451. public AjaxResult getCreditLineList(@RequestParam(required=false) String zfpcrId,
  452. @RequestParam(required=false) String type)
  453. {
  454. //获取当前企业的编号
  455. LoginUser userInfo = tokenService.getLoginUser();
  456. SysUser use = userInfo.getSysUser();
  457. Map<String,String> map = new HashMap<>();
  458. //获取企业
  459. String companyId = use.getCompanyId();
  460. map.put("zfpcrCompanyId", companyId);
  461. //授信额度编号
  462. map.put("zfpcrId",zfpcrId);
  463. //类型--1查询反向产品 0 查询正向产品
  464. map.put("type",type);
  465. List<Map> creditLineList = ownCreditService.selectCreditLineList(map);
  466. for(int i = 0 ; i < creditLineList.size();i++){
  467. Map<String,String> mmp = creditLineList.get(i);
  468. //获取授信额度编号
  469. String sxId = mmp.get("zfpcrId");
  470. LambdaQueryWrapper<ZcFinanceProComRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  471. //公司
  472. lambdaQueryWrapper.eq(ZcFinanceProComRel::getZfpcrCompanyId,companyId);
  473. //授信编号
  474. lambdaQueryWrapper.eq(ZcFinanceProComRel::getZfpcrId,sxId);
  475. //授信额度
  476. String amount = "";
  477. List<ZcFinanceProComRel> list = financeProComRelService.findZcFinanceProComRels(lambdaQueryWrapper);
  478. if(list.size() < 1){
  479. return AjaxResult.error("获取授信额度信息失败");
  480. }
  481. amount = list.get(0).getZfpcrAmount();
  482. //获取已用的授信额度
  483. Map m = new HashMap();
  484. m.put("zfpcrId",sxId);
  485. m.put("companyId",companyId);
  486. String userdBalance = ownCreditService.getUsedBalance(m);
  487. //获取剩余额度
  488. String remaining = AmtUtil.subtract(amount,userdBalance,2);
  489. mmp.put("remaining",remaining);
  490. }
  491. return AjaxResult.success(creditLineList);
  492. }
  493. /**
  494. * 获取供应商授信额度
  495. * @param zfsqId
  496. * @return
  497. */
  498. @GetMapping("/getSupplierCreditLineList")
  499. public AjaxResult getSupplierCreditLineList(@RequestParam(required=false) String zfsqId)
  500. {
  501. //获取当前企业的编号
  502. LoginUser userInfo = tokenService.getLoginUser();
  503. SysUser use = userInfo.getSysUser();
  504. Map<String,String> map = new HashMap<>();
  505. //获取企业
  506. String companyId = use.getCompanyId();
  507. map.put("zfsqCompanyId", companyId);
  508. //授信额度编号
  509. map.put("zfsqId",zfsqId);
  510. List<Map> creditLineList = ownCreditService.selectSupplierCreditLineList(map);
  511. for(int i = 0 ; i < creditLineList.size();i++){
  512. Map<String,String> mmp = creditLineList.get(i);
  513. //获取授信编号
  514. String sxId = mmp.get("zfsqId");
  515. //查询供应商的授信额度
  516. LambdaQueryWrapper<ZcFinanceSupplierQuota> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  517. //公司
  518. lambdaQueryWrapper.eq(ZcFinanceSupplierQuota::getZfsqCompanyId,companyId);
  519. //授信编号
  520. lambdaQueryWrapper.eq(ZcFinanceSupplierQuota::getZfsqId,sxId);
  521. //授信额度
  522. String amount = "";
  523. List<ZcFinanceSupplierQuota> list = financeSupplierQuotaService.findZcFinanceSupplierQuotas(lambdaQueryWrapper);
  524. if(list.size() < 1){
  525. return AjaxResult.error("获取授信额度信息失败");
  526. }
  527. amount = list.get(0).getZfsqAmount();
  528. //获取已用的授信额度
  529. Map m = new HashMap();
  530. m.put("zfsqId",sxId);
  531. m.put("companyId",companyId);
  532. String userdBalance = ownCreditService.getSupplierUsedBalance(m);
  533. //获取剩余额度
  534. String remaining = AmtUtil.subtract(amount,userdBalance,2);
  535. mmp.put("remaining",remaining);
  536. }
  537. return AjaxResult.success(creditLineList);
  538. }
  539. /**
  540. * 融信开立
  541. * @param map
  542. * @return
  543. * @throws Exception
  544. */
  545. @PreAuthorize(hasPermi = "credit:credit:add")
  546. @Log(title = "融信开立", businessType = BusinessType.INSERT)
  547. @Transactional(rollbackFor = Exception.class)
  548. @PostMapping
  549. public AjaxResult add(@RequestBody Map<String,Object> map)throws Exception
  550. {
  551. //获取收付款
  552. List<Map<String,String>> ticketList = (List<Map<String, String>>) map.get("ticketList");
  553. //获取融信的类型
  554. String type = CommonUtil.objToString(map.get("type"));
  555. //获取此操作员
  556. LoginUser userInfo = tokenService.getLoginUser();
  557. SysUser user = userInfo.getSysUser();
  558. //获取用户编号
  559. String userId = user.getUserId()+"";
  560. //获取企业
  561. String companyId = user.getCompanyId();
  562. //主键
  563. String id = IdUtils.fastSimpleUUID();
  564. //获取创建时间
  565. Date createTime = DateUtils.getNowDate();
  566. //获取当前时间
  567. String currentTime = DateUtils.parseDateToStr("yyyyMMddHHmmss",createTime);
  568. //获取产品是否可拆分
  569. String zfpSplit = CommonUtil.objToString(map.get("zfpSplit"));
  570. //获取放款方式
  571. String zfpcrLoanType = CommonUtil.objToString(map.get("zfpcrLoanType"));
  572. //融信编号
  573. String str = "";
  574. //判断类型
  575. //开立
  576. if("1".equals(type) || "2".equals(type)){
  577. str = "CM";
  578. }else if("0".equals(type)){
  579. //申请
  580. str = "SM";
  581. }
  582. //产品不可拆分
  583. if("0".equals(zfpSplit)){
  584. str += "D";
  585. }else if("1".equals(zfpSplit)){
  586. //可拆分
  587. str += "R";
  588. }
  589. //放款方式--供应商
  590. if("0".equals(zfpcrLoanType)){
  591. str += "P";
  592. }else if("1".equals(zfpcrLoanType)){
  593. //平台电子记账
  594. str += "E";
  595. }
  596. str = str + currentTime;
  597. ZcFinanceInf inf = new ZcFinanceInf();
  598. //主键
  599. inf.setZfiId(id);
  600. //融信编号--申请
  601. if("0".equals(type)){
  602. inf.setZfiNumber(currentTime);
  603. }else{//开立
  604. inf.setZfiNumber(str);
  605. }
  606. //创建类型-- 0供应商申请 1核心开立 2供应商开立
  607. inf.setZfiCreateType(type);
  608. //还款函编号
  609. //随机生成8位字母
  610. String zfiPaymentNumber = getRandomNickname(8)+currentTime;
  611. inf.setZfiPaymentNumber(zfiPaymentNumber);
  612. //获取申请金额
  613. String zfiAmount = CommonUtil.objToString(map.get("zfiAmount"));
  614. if(CommonUtil.isEmpty(zfiAmount)){
  615. throw new Exception("请输入申请金额");
  616. }
  617. if(!AmtUtil.isMoney(zfiAmount)){
  618. throw new Exception("请输入正确的申请金额");
  619. }
  620. //非供应商申请
  621. if(!"0".equals(type)){
  622. //获取可用额度
  623. String availableAmt = CommonUtil.objToString(map.get("availableAmt"));
  624. if(CommonUtil.compare(zfiAmount,availableAmt) == 1){
  625. throw new Exception("签发金额不可大于可用额度");
  626. }
  627. //承诺付款日
  628. String zfiExpireDate = CommonUtil.objToString(map.get("zfiExpireDate"));
  629. //签发有效期
  630. String zfiEffectiveDate = CommonUtil.objToString(map.get("zfiEffectiveDate"));
  631. if(CommonUtil.isEmpty(zfiEffectiveDate)){
  632. throw new Exception("请选择签发有效期");
  633. }
  634. if(CommonUtil.isEmpty(zfiExpireDate)){
  635. throw new Exception("请选择承诺付款日");
  636. }
  637. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  638. Date date = simpleDateFormat.parse(zfiEffectiveDate);
  639. inf.setZfiEffectiveDate(date);
  640. Date signDate = simpleDateFormat.parse(zfiExpireDate);
  641. inf.setZfiExpireDate(signDate);
  642. }
  643. //创建人
  644. inf.setCreateBy(userId);
  645. //创建时间
  646. inf.setCreateTime(createTime);
  647. //获取产品
  648. String productId = CommonUtil.objToString(map.get("zfpId"));
  649. inf.setZfiProductId(productId);
  650. //利率
  651. String zfiRate = CommonUtil.objToString(map.get("zfiRate"));
  652. inf.setZfiRate(zfiRate);
  653. //核心开立
  654. if("1".equals(type)){
  655. //根据有无审批流做判断
  656. Map<String,Object> pp = new HashMap<>();
  657. pp.put("menuId","1000000000");
  658. pp.put("companyId",companyId);
  659. Map<String,Object> mmp = flowableService.selectApproval(pp);
  660. //不等于200
  661. if(CommonUtil.compare(CommonUtil.objToString(mmp.get("code")),"200") != 0){
  662. throw new Exception("查询审批流程失败");
  663. }
  664. List<Map<String,Object>> list = (List<Map<String, Object>>) mmp.get("data");
  665. //未开启流程审批
  666. if(list.size() < 1){
  667. //通过
  668. inf.setZfiCoreStatus("01");
  669. }else{
  670. //核心企业状态--暂存
  671. inf.setZfiCoreStatus("03");
  672. }
  673. //接收企业
  674. String zfiSupplierId = CommonUtil.objToString(map.get("zfiSupplierId"));
  675. inf.setZfiSupplierId(zfiSupplierId);
  676. //开立企业
  677. inf.setZfiCoreId(companyId);
  678. //核心企业授信额度
  679. String zfiCoreQuotaId = CommonUtil.objToString(map.get("zfiCoreQuotaId"));
  680. inf.setZfiCoreQuotaId(zfiCoreQuotaId);
  681. //选择
  682. if(ticketList.size() > 1){
  683. //获取第一个应收企业
  684. String receiveName = ticketList.get(0).get("receiveName");
  685. //获取预计还款日期
  686. String zbiPayDate = ticketList.get(0).get("zbiPayDate");
  687. for(int i = 0 ; i < ticketList.size();i++){
  688. if(!receiveName.equals(ticketList.get(i).get("receiveName"))){
  689. throw new Exception("请选择应收企业相同的应付账款");
  690. }
  691. if(!zbiPayDate.equals(ticketList.get(i).get("zbiPayDate"))){
  692. throw new Exception("请选择预计还款日期相同的应付账款");
  693. }
  694. }
  695. }
  696. }else if("0".equals(type) || "2".equals(type)){//供应商开立/申请
  697. // 根据有无审批流做判断
  698. //获取合计金额
  699. String checkTotalAmt = CommonUtil.objToString(map.get("checkTotalAmt"));
  700. //供应商开立
  701. if("2".equals(type)){
  702. //根据有无审批流做判断
  703. Map<String,Object> pp = new HashMap<>();
  704. pp.put("menuId","1000000001");
  705. pp.put("companyId",companyId);
  706. Map<String,Object> mmp = flowableService.selectApproval(pp);
  707. //不等于200
  708. if(CommonUtil.compare(CommonUtil.objToString(mmp.get("code")),"200") != 0){
  709. throw new Exception("查询审批流程失败");
  710. }
  711. List<Map<String,Object>> list = (List<Map<String, Object>>) mmp.get("data");
  712. //未开启流程审批
  713. if(list.size() < 1){
  714. //通过
  715. inf.setZfiSupplierStatus("01");
  716. }else{
  717. //供应商企业状态--暂存
  718. inf.setZfiSupplierStatus("03");
  719. }
  720. //供应商企业授信额度
  721. String zfiSupplierQuotaId = CommonUtil.objToString(map.get("zfiSupplierQuotaId"));
  722. inf.setZfiSupplierQuotaId(zfiSupplierQuotaId);
  723. //获取供应商对应的核心授信额度
  724. ZcFinanceSupplierQuota supplierQuota = financeSupplierQuotaService.getById(zfiSupplierQuotaId);
  725. if(supplierQuota == null){
  726. throw new Exception("获取供应商授信额度失败");
  727. }
  728. String zfsqCoreQuotaId = supplierQuota.getZfsqCoreQuotaId();
  729. //核心授信额度
  730. inf.setZfiCoreQuotaId(zfsqCoreQuotaId);
  731. //获取收款账号
  732. /*String zfiCollectionAccount = CommonUtil.objToString(map.get("zfiCollectionAccount"));
  733. //获取放款方式--供应商指定的话为收款账号必输
  734. if("1".equals(zfpcrLoanType)){
  735. if(CommonUtil.isEmpty(zfiCollectionAccount)){getFile
  736. throw new Exception("请输入收款账号");
  737. }
  738. }
  739. if(!"0".equals(zfpcrLoanType)){
  740. inf.setZfiCollectionAccount(zfiCollectionAccount);
  741. }*/
  742. }else if("0".equals(type)){//供应商申请
  743. //根据有无审批流做判断
  744. Map<String,Object> pp = new HashMap<>();
  745. pp.put("menuId","1000000002");
  746. pp.put("companyId",companyId);
  747. Map<String,Object> mmp = flowableService.selectApproval(pp);
  748. //不等于200
  749. if(CommonUtil.compare(CommonUtil.objToString(mmp.get("code")),"200") != 0){
  750. throw new Exception("查询审批流程失败");
  751. }
  752. List<Map<String,Object>> list = (List<Map<String, Object>>) mmp.get("data");
  753. //未开启流程审批
  754. if(list.size() < 1){
  755. //通过
  756. inf.setZfiSupplierStatus("01");
  757. }else{
  758. //供应商企业状态--暂存
  759. inf.setZfiSupplierStatus("03");
  760. }
  761. }
  762. if(CommonUtil.compare(zfiAmount,checkTotalAmt) == 1){
  763. throw new Exception("签发金额不可大于合计金额");
  764. }
  765. if(ticketList.size() < 1){
  766. throw new Exception("请选择应收账款");
  767. }else if(ticketList.size() > 1){
  768. //获取第一个应付企业
  769. String payName = ticketList.get(0).get("payName");
  770. //获取预计还款日期
  771. String zbiPayDate = ticketList.get(0).get("zbiPayDate");
  772. for(int i = 0 ; i < ticketList.size();i++){
  773. if(!payName.equals(ticketList.get(i).get("payName"))){
  774. throw new Exception("请选择应付企业相同的应收账款");
  775. }
  776. if(!zbiPayDate.equals(ticketList.get(i).get("zbiPayDate"))){
  777. throw new Exception("请选择预计还款日期相同的应收账款");
  778. }
  779. }
  780. }
  781. //开立方==应付企业
  782. inf.setZfiCoreId(ticketList.get(0).get("zbiPayerId"));
  783. //接收方 ==本公司
  784. inf.setZfiSupplierId(companyId);
  785. }
  786. //插入融信和应收付款的关系
  787. for(int i = 0 ; i < ticketList.size();i++){
  788. //获取收付款编号
  789. String billId = ticketList.get(i).get("zbiId");
  790. ZcFinanceBillRel rel = new ZcFinanceBillRel();
  791. rel.setZfbrFinanceId(id);
  792. rel.setZfbrBillId(billId);
  793. financeBillRelService.createZcFinanceBillRel(rel);
  794. }
  795. inf.setZfiAmount(zfiAmount);
  796. //插入数据
  797. financeInfService.createZcFinanceInf(inf);
  798. //核心开立
  799. if("1".equals(type)){
  800. map.put("zfiId",id);
  801. map.put("zfiCoreId",companyId);
  802. //调用核心开立审批流
  803. approvalService.coreApproval(CommonUtil.entityToMap(inf));
  804. }
  805. return AjaxResult.success();
  806. }
  807. /**
  808. * 获取核心开立接收方
  809. * @param zfiSupplierId
  810. * @return
  811. */
  812. @GetMapping("/getReceiverList")
  813. public AjaxResult getReceiverList(@RequestParam(required=false) String zfiSupplierId, QueryRequest request)
  814. {
  815. //获取当前企业的编号
  816. LoginUser userInfo = tokenService.getLoginUser();
  817. SysUser use = userInfo.getSysUser();
  818. //获取当前公司
  819. String companyId = use.getCompanyId();
  820. Map<String,String> map = new HashMap<>();
  821. map.put("companyId",companyId);
  822. map.put("zfiSupplierId",zfiSupplierId);
  823. IPage<Map> companyList = ownCreditService.getReceiverList(map,request);
  824. return AjaxResult.success(companyList);
  825. }
  826. /**
  827. * 核心开立查询应付账款
  828. * @return
  829. */
  830. @GetMapping("/getAccountsPay")
  831. public AjaxResult getAccountsPay(@RequestParam(required=false) String zbiName,
  832. @RequestParam(required=false) String receiveName,
  833. QueryRequest request) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
  834. //获取当前企业的编号
  835. LoginUser userInfo = tokenService.getLoginUser();
  836. SysUser use = userInfo.getSysUser();
  837. Map<String,String> map = new HashMap<>();
  838. //查询非失效的融信
  839. LambdaQueryWrapper<ZcFinanceInf> financeInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
  840. financeInfLambdaQueryWrapper.ne(ZcFinanceInf::getZfiStatus,"03");
  841. List<ZcFinanceInf> financeInfsList = financeInfService.findZcFinanceInfs(financeInfLambdaQueryWrapper);
  842. if(financeInfsList.size() > 0){
  843. //提取融信编号
  844. List<String> financeIdList = CommonUtil.getIdFromList(financeInfsList,"zfiId");
  845. //查询融信已关联应付账款
  846. LambdaQueryWrapper<ZcFinanceBillRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  847. lambdaQueryWrapper.in(ZcFinanceBillRel::getZfbrFinanceId,financeIdList);
  848. List<ZcFinanceBillRel> relList = financeBillRelService.findZcFinanceBillRels(lambdaQueryWrapper);
  849. if(relList.size() > 0){
  850. List<String> billIdList = CommonUtil.getIdFromList(relList,"zfbrBillId");
  851. map.put("billIdList",CommonUtil.listToStr4InSql(billIdList));
  852. }
  853. }
  854. //获取公司编号
  855. String companyId = use.getCompanyId();
  856. map.put("zbiPayerId",companyId);
  857. //账款名称
  858. map.put("zbiName",zbiName);
  859. //应收企业
  860. map.put("receiveName",receiveName);
  861. IPage<Map> payList = ownCreditService.getAccountsPay(map,request);
  862. return AjaxResult.success(payList);
  863. }
  864. /**
  865. *
  866. *融资开立查询应收账款
  867. * @param zbiName
  868. * @param payName
  869. * @param request
  870. * @return
  871. */
  872. @GetMapping("/getAccountsCollection")
  873. public AjaxResult getAccountsCollection(@RequestParam(required=false) String zbiName,
  874. @RequestParam(required=false) String payName,
  875. @RequestParam(required=false) String payId,
  876. @RequestParam(required=false) String zfiSupplierId,
  877. QueryRequest request) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
  878. //获取当前企业的编号
  879. LoginUser userInfo = tokenService.getLoginUser();
  880. SysUser use = userInfo.getSysUser();
  881. //获取公司编号
  882. String companyId = use.getCompanyId();
  883. Map<String,String> map = new HashMap<>();
  884. //查询非失效的融信
  885. LambdaQueryWrapper<ZcFinanceInf> financeInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
  886. financeInfLambdaQueryWrapper.ne(ZcFinanceInf::getZfiStatus,"03");
  887. List<ZcFinanceInf> financeInfsList = financeInfService.findZcFinanceInfs(financeInfLambdaQueryWrapper);
  888. if(financeInfsList.size() > 0){
  889. //提取融信编号
  890. List<String> financeIdList = CommonUtil.getIdFromList(financeInfsList,"zfiId");
  891. //查询融信已关联应付账款
  892. LambdaQueryWrapper<ZcFinanceBillRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  893. lambdaQueryWrapper.in(ZcFinanceBillRel::getZfbrFinanceId,financeIdList);
  894. List<ZcFinanceBillRel> relList = financeBillRelService.findZcFinanceBillRels(lambdaQueryWrapper);
  895. if(relList.size() > 0){
  896. List<String> billIdList = CommonUtil.getIdFromList(relList,"zfbrBillId");
  897. map.put("billIdList",CommonUtil.listToStr4InSql(billIdList));
  898. }
  899. }
  900. //接收方
  901. if(!CommonUtil.isEmpty(zfiSupplierId)){
  902. //应收企业
  903. map.put("zbiPayeeId",zfiSupplierId);
  904. }else{
  905. //应收企业
  906. map.put("zbiPayeeId",companyId);
  907. }
  908. //账款名称
  909. map.put("zbiName",zbiName);
  910. //应付企业
  911. map.put("payName",payName);
  912. //应付企业编号
  913. map.put("payId",payId);
  914. IPage<Map> collectionList = ownCreditService.getAccountsCollection(map,request);
  915. return AjaxResult.success(collectionList);
  916. }
  917. /**
  918. * 核心开立获取可用余额
  919. * @param zfpcrId
  920. * @return
  921. */
  922. @GetMapping("/getAvailableBalance")
  923. public AjaxResult getAvailableBalance(@RequestParam(required=false) String zfpcrId)
  924. {
  925. //获取当前企业的编号
  926. LoginUser userInfo = tokenService.getLoginUser();
  927. SysUser use = userInfo.getSysUser();
  928. //获取公司编号
  929. String companyId = use.getCompanyId();
  930. LambdaQueryWrapper<ZcFinanceProComRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  931. //公司
  932. lambdaQueryWrapper.eq(ZcFinanceProComRel::getZfpcrCompanyId,companyId);
  933. //授信编号
  934. lambdaQueryWrapper.eq(ZcFinanceProComRel::getZfpcrId,zfpcrId);
  935. //授信额度
  936. String amount = "";
  937. List<ZcFinanceProComRel> list = financeProComRelService.findZcFinanceProComRels(lambdaQueryWrapper);
  938. if(list.size() < 1){
  939. return AjaxResult.error("获取授信额度信息失败");
  940. }
  941. amount = list.get(0).getZfpcrAmount();
  942. //获取已用的授信额度
  943. Map m = new HashMap();
  944. m.put("zfpcrId",zfpcrId);
  945. m.put("companyId",companyId);
  946. String userdBalance = ownCreditService.getUsedBalance(m);
  947. //获取剩余额度
  948. String remaining = AmtUtil.subtract(amount,userdBalance,2);
  949. Map map = new HashMap();
  950. map.put("remaining",remaining);
  951. return AjaxResult.success(map);
  952. }
  953. /**
  954. * 获取供应商开立可用额度
  955. * @param zfsqId
  956. * @return
  957. */
  958. @GetMapping("/getSupplierAvailableBalance")
  959. public AjaxResult getSupplierAvailableBalance(@RequestParam(required=false) String zfsqId)
  960. {
  961. //获取当前企业的编号
  962. LoginUser userInfo = tokenService.getLoginUser();
  963. SysUser use = userInfo.getSysUser();
  964. //获取公司编号
  965. String companyId = use.getCompanyId();
  966. //查询供应商的授信额度
  967. LambdaQueryWrapper<ZcFinanceSupplierQuota> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  968. //公司
  969. lambdaQueryWrapper.eq(ZcFinanceSupplierQuota::getZfsqCompanyId,companyId);
  970. //授信编号
  971. lambdaQueryWrapper.eq(ZcFinanceSupplierQuota::getZfsqId,zfsqId);
  972. //授信额度
  973. String amount = "";
  974. List<ZcFinanceSupplierQuota> list = financeSupplierQuotaService.findZcFinanceSupplierQuotas(lambdaQueryWrapper);
  975. if(list.size() < 1){
  976. return AjaxResult.error("获取授信额度信息失败");
  977. }
  978. amount = list.get(0).getZfsqAmount();
  979. //获取已用的授信额度
  980. Map m = new HashMap();
  981. m.put("zfsqId",zfsqId);
  982. m.put("companyId",companyId);
  983. String userdBalance = ownCreditService.getSupplierUsedBalance(m);
  984. //获取剩余额度
  985. String remaining = AmtUtil.subtract(amount,userdBalance,2);
  986. Map map = new HashMap();
  987. map.put("remaining",remaining);
  988. return AjaxResult.success(map);
  989. }
  990. /**
  991. * 获取收付款下的附件信息
  992. * @param m
  993. * @return
  994. */
  995. @PostMapping("/getFile")
  996. public AjaxResult getFile(@RequestBody Map<String, Object> m) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
  997. //发票文件
  998. List<PubFileInf> invoiceFileList = new ArrayList<>();
  999. //收付款的合同类型的文件
  1000. List<PubFileInf> contractFileList = new ArrayList<>();
  1001. //收付款的其他文件
  1002. List<PubFileInf> otherFileList = new ArrayList<>();
  1003. Map map = new HashMap();
  1004. //获取传过来的收付款信息
  1005. List<Map<String,String>> ticketList = (List<Map<String, String>>) m.get("ticketList");
  1006. if (ticketList.size() < 1){
  1007. //发票
  1008. map.put("invoiceFileList",invoiceFileList);
  1009. //合同
  1010. map.put("contractFileList",contractFileList);
  1011. //其他类型
  1012. map.put("otherFileList",otherFileList);
  1013. return AjaxResult.success(map);
  1014. }
  1015. //提取收付款编号
  1016. List<String> zbiIdList = CommonUtil.getIdFromList(ticketList,"zbiId");
  1017. //发票与收付款相关
  1018. LambdaQueryWrapper<ZcBillInvoiceRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  1019. lambdaQueryWrapper.in(ZcBillInvoiceRel::getZbirBillId,zbiIdList);
  1020. List<ZcBillInvoiceRel> relList = billInvoiceRelService.findZcBillInvoiceRels(lambdaQueryWrapper);
  1021. //有关联的发票
  1022. if(relList.size() > 0 ){
  1023. List<String> invoiceIdList = CommonUtil.getIdFromList(relList,"zbirInvoiceId");
  1024. //查询发票
  1025. LambdaQueryWrapper<ZcInvoiceInf> invoiceInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
  1026. invoiceInfLambdaQueryWrapper.in(ZcInvoiceInf::getZiiId,invoiceIdList);
  1027. invoiceInfLambdaQueryWrapper.eq(ZcInvoiceInf::getZiiStatus,"00");
  1028. List<ZcInvoiceInf> invoiceInfList = invoiceInfService.findZcInvoiceInfs(invoiceInfLambdaQueryWrapper);
  1029. //发票信息不为空
  1030. if(invoiceInfList.size() > 0){
  1031. //提取出文件信息
  1032. List<String> fileIdList = CommonUtil.getIdFromList(invoiceInfList,"ziiFile");
  1033. LambdaQueryWrapper<PubFileInf> fileInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
  1034. fileInfLambdaQueryWrapper.in(PubFileInf::getPfiFileId,fileIdList);
  1035. fileInfLambdaQueryWrapper.eq(PubFileInf::getPfiIsDel,"00");
  1036. //查询文件
  1037. invoiceFileList = fileInfService.findPubFileInfs(fileInfLambdaQueryWrapper);
  1038. }
  1039. }
  1040. map.put("invoiceFileList",invoiceFileList);
  1041. //查询文件关系表
  1042. LambdaQueryWrapper<ZcBillFileRel> billFileRelLambdaQueryWrapper = new LambdaQueryWrapper<>();
  1043. billFileRelLambdaQueryWrapper.in(ZcBillFileRel::getZbfrBillId,zbiIdList);
  1044. billFileRelLambdaQueryWrapper.eq(ZcBillFileRel::getZbfrType,"0");
  1045. List<ZcBillFileRel> billFileRelList = billFileRelService.findZcBillFileRels(billFileRelLambdaQueryWrapper);
  1046. //不为空
  1047. if(billFileRelList.size() > 0){
  1048. //提取文件编号
  1049. List<String> idList = CommonUtil.getIdFromList(billFileRelList,"zbfrFileId");
  1050. LambdaQueryWrapper<PubFileInf> fileInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
  1051. fileInfLambdaQueryWrapper.in(PubFileInf::getPfiFileId,idList);
  1052. fileInfLambdaQueryWrapper.eq(PubFileInf::getPfiIsDel,"00");
  1053. contractFileList = fileInfService.findPubFileInfs(fileInfLambdaQueryWrapper);
  1054. }
  1055. map.put("contractFileList",contractFileList);
  1056. //查询文件关系表
  1057. LambdaQueryWrapper<ZcBillFileRel> fileRelLambdaQueryWrapper = new LambdaQueryWrapper<>();
  1058. fileRelLambdaQueryWrapper.in(ZcBillFileRel::getZbfrBillId,zbiIdList);
  1059. fileRelLambdaQueryWrapper.eq(ZcBillFileRel::getZbfrType,"2");
  1060. List<ZcBillFileRel> relFileList = billFileRelService.findZcBillFileRels(fileRelLambdaQueryWrapper);
  1061. //不为空
  1062. if(relFileList.size() > 0){
  1063. //提取文件编号
  1064. List<String> idList = CommonUtil.getIdFromList(relFileList,"zbfrFileId");
  1065. LambdaQueryWrapper<PubFileInf> fileInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
  1066. fileInfLambdaQueryWrapper.in(PubFileInf::getPfiFileId,idList);
  1067. fileInfLambdaQueryWrapper.eq(PubFileInf::getPfiIsDel,"00");
  1068. otherFileList = fileInfService.findPubFileInfs(fileInfLambdaQueryWrapper);
  1069. }
  1070. map.put("otherFileList",otherFileList);
  1071. return AjaxResult.success(map);
  1072. }
  1073. /**
  1074. * 随机生成length个字母
  1075. * @param length
  1076. * @return
  1077. */
  1078. public static String getRandomNickname(int length) {
  1079. String val = "";
  1080. Random random = new Random();
  1081. for (int i = 0; i < length; i++) {
  1082. // 字符串
  1083. // 取得大写字母还是小写字母
  1084. int choice = random.nextInt(2) % 2 == 0 ? 65 : 97;
  1085. val += (char) (choice + random.nextInt(26));
  1086. }
  1087. return val;
  1088. }
  1089. /**
  1090. * 获取当前操作员
  1091. * @return
  1092. * @throws Exception
  1093. */
  1094. @GetMapping("/getUser")
  1095. public R getUser()throws Exception {
  1096. //获取当前操作员
  1097. LoginUser user = tokenService.getLoginUser();
  1098. String companyId = user.getSysUser().getCompanyId();
  1099. return R.ok(companyId);
  1100. }
  1101. }