| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159 |
- package com.huyi.service.credit.controller;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.huyi.service.base.entity.*;
- import com.huyi.service.base.service.*;
- import com.huyi.service.common.flowable.service.ApprovalService;
- import com.huyi.service.credit.service.OwnCreditService;
- import com.huyi.service.util.FlowableService;
- import com.keao.tianhu.starter.mybatis.plus.entity.QueryRequest;
- import com.tianhu.common.core.domain.R;
- import com.tianhu.common.core.utils.AmtUtil;
- import com.tianhu.common.core.utils.CommonUtil;
- import com.tianhu.common.core.utils.DateUtils;
- import com.tianhu.common.core.utils.IdUtils;
- import com.tianhu.common.core.web.controller.BaseController;
- import com.tianhu.common.core.web.domain.AjaxResult;
- import com.tianhu.common.log.annotation.Log;
- import com.tianhu.common.log.enums.BusinessType;
- import com.tianhu.common.security.annotation.PreAuthorize;
- import com.tianhu.common.security.service.TokenService;
- import com.tianhu.system.api.domain.SysUser;
- import com.tianhu.system.api.model.LoginUser;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.web.bind.annotation.*;
- import java.lang.reflect.InvocationTargetException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * 融信信息
- * xuefy
- * 2021-08-17
- */
- @RestController
- @RequestMapping("/ownCredit")
- public class OwnCreditController extends BaseController {
- @Autowired
- private TokenService tokenService;
- //自写融信服务类
- @Autowired
- private OwnCreditService ownCreditService;
- //核心授信服务类
- @Autowired
- private IZcFinanceProComRelService financeProComRelService;
- //融信应收付关系的服务类
- @Autowired
- private IZcFinanceBillRelService financeBillRelService;
- //融信应收付关系的服务类
- @Autowired
- private IZcFinanceInfService financeInfService;
- //供应商授信服务类
- @Autowired
- private IZcFinanceSupplierQuotaService financeSupplierQuotaService;
- //用户服务类
- @Autowired
- private ISysUserService sysUserService;
- //公司服务类
- @Autowired
- private ISysCompanyService companyService;
- //产品服务类
- @Autowired
- private IZcFinanceProductService productService;
- //收付款与发票关系表
- @Autowired
- private IZcBillInvoiceRelService billInvoiceRelService;
- //发票服务
- @Autowired
- private IZcInvoiceInfService invoiceInfService;
- //文件服务类
- @Autowired
- private IPubFileInfService fileInfService;
- //收付款和文件的关系表服务类
- @Autowired
- private IZcBillFileRelService billFileRelService;
- @Autowired
- private FlowableService flowableService;
- //审批服务类
- @Autowired
- private ApprovalService approvalService;
- /**
- * 查询融信信息
- * @param zfiNumber
- * @param zfiStatus
- * @param openCompany
- * @param receiveCompany
- * @param zfpName
- * @param zfiSignDate
- * @param zfiExpireDate
- * @param zfiRate
- * @param request
- * @return
- */
- @PreAuthorize(hasPermi = "credit:credit:list")
- @GetMapping("/list")
- public R list(
- @RequestParam(required=false) String zfiNumber,
- @RequestParam(required=false) String zfiStatus,
- @RequestParam(required=false) String openCompany,
- @RequestParam(required=false) String receiveCompany,
- @RequestParam(required=false) String zfpName,
- @RequestParam(required=false) String startAmt,
- @RequestParam(required=false) String endAmt,
- @RequestParam(required=false) Map zfiSignDate,
- @RequestParam(required=false) Map zfiExpireDate,
- @RequestParam(required=false) String zfiRate,
- QueryRequest request) {
- //查询当前操作员
- LoginUser userInfo = tokenService.getLoginUser();
- SysUser use = userInfo.getSysUser();
- //获取企业
- String companyId = use.getCompanyId();
- Map map = new HashMap();
- /*if (!SalaryConstants.OPEX.equals(companyId)) {
- map.put("ziiCompanyId", companyId);
- }*/
- //融信编号
- map.put("zfiNumber", zfiNumber);
- //状态
- if(!CommonUtil.isEmpty(zfiStatus)){
- List<String> stateList = new ArrayList<>();
- if(!zfiStatus.contains(",")){
- stateList.add(zfiStatus);
- }else{
- String arr [] = zfiStatus.split(",");
- for(int i = 0 ; i < arr.length;i++){
- if(!CommonUtil.isEmpty(arr[i])){
- stateList.add(arr[i]);
- }
- }
- }
- map.put("stateList",CommonUtil.listToStr4InSql(stateList));
- }
- //开立企业
- map.put("openCompany", openCompany);
- //接收企业
- map.put("receiveCompany", receiveCompany);
- //融资产品
- map.put("zfpName",zfpName);
- //利率
- map.put("zfiRate",CommonUtil.objToBigDecimal(zfiRate));
- //签收日期
- map.put("startTime",zfiSignDate.get("zfiSignDate[0]"));
- map.put("endTime",zfiSignDate.get("zfiSignDate[1]"));
- //承诺还款日
- map.put("zfiExpireDateStart",zfiExpireDate.get("zfiExpireDate[0]"));
- map.put("zfiExpireDateEnd",zfiExpireDate.get("zfiExpireDate[1]"));
- if(!CommonUtil.isEmpty(startAmt)){
- if(!AmtUtil.isMoney(startAmt)){
- return R.fail("请输入正确的融信金额开始范围值");
- }
- if(CommonUtil.isEmpty(endAmt)){
- return R.fail("请输入融信金额的结束范围值");
- }
- }
- if(!CommonUtil.isEmpty(endAmt)){
- if(CommonUtil.isEmpty(startAmt)){
- map.put("startAmt","0");
- }
- }
- //合同金额结束范围
- if(!CommonUtil.isEmpty(endAmt)){
- if(!AmtUtil.isMoney(endAmt)){
- return R.fail("请输入正确的融信金额结束范围值");
- }
- }
- if(!CommonUtil.isEmpty(startAmt) && !CommonUtil.isEmpty(endAmt)){
- if(CommonUtil.compare(startAmt,endAmt) == 1){
- return R.fail("融信金额范围输入有误");
- }
- }
- map.put("startAmt",CommonUtil.objToBigDecimal(startAmt));
- map.put("endAmt",CommonUtil.objToBigDecimal(endAmt));
- //获取企业类型
- String companyType = use.getCompanyType();
- map.put("companyType",companyType);
- map.put("companyId",companyId);
- IPage<Map> list = ownCreditService.selectCreditList(map,request);
- return R.ok(list);
- }
- /**
- * 获取融信详情
- * @param zfiId
- * @return
- */
- @PreAuthorize(hasPermi = "credit:credit:query")
- @GetMapping(value = "/{zfiId}")
- public AjaxResult getInfo(@PathVariable("zfiId") String zfiId,QueryRequest request) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- //查询融信详情
- ZcFinanceInf financeInf = financeInfService.getById(zfiId);
- if(financeInf == null){
- return AjaxResult.error("获取融信信息失败");
- }
- //查询创建人
- String userId = financeInf.getCreateBy();
- com.huyi.service.base.entity.SysUser user = sysUserService.getById(userId);
- String createName = "";
- Map map = new HashMap();
- if(user != null){
- createName = user.getNickName();
- }
- //创建人
- map.put("createName",createName);
- //融信
- map.put("financeInf",financeInf);
- //接收方
- String zfiSupplierId = financeInf.getZfiSupplierId();
- SysCompany company = companyService.getById(zfiSupplierId);
- String receiveName = "";
- if(company != null){
- receiveName = company.getScyName();
- }
- map.put("receiveName",receiveName);
- //开立方
- String zfiCoreId = financeInf.getZfiCoreId();
- SysCompany coreCompany = companyService.getById(zfiCoreId);
- String openName = "";
- if(coreCompany != null){
- openName = coreCompany.getScyName();
- }
- map.put("openName",openName);
- //产品
- String productId = financeInf.getZfiProductId();
- ZcFinanceProduct product = productService.getById(productId);
- String zfpName = "";
- //意愿类型
- String zfpAuthType = "";
- if(product != null){
- zfpName = product.getZfpName();
- zfpAuthType = product.getZfpAuthType();
- }
- map.put("zfpName",zfpName);
- map.put("zfpAuthType",zfpAuthType);
- //获取核心授信额度信息
- String zfiCoreQuotaId = financeInf.getZfiCoreQuotaId();
- ZcFinanceProComRel proComRel = financeProComRelService.getById(zfiCoreQuotaId);
- map.put("proComRel",proComRel);
- //查询该融信下关联的应收付款
- LambdaQueryWrapper<ZcFinanceBillRel> relLambdaQueryWrapper = new LambdaQueryWrapper<>();
- relLambdaQueryWrapper.eq(ZcFinanceBillRel::getZfbrFinanceId,zfiId);
- List<ZcFinanceBillRel> relList = financeBillRelService.findZcFinanceBillRels(relLambdaQueryWrapper);
- if(relList.size() > 0 ){
- //提取应收付款的编号
- List<String> payIdList = CommonUtil.getIdFromList(relList,"zfbrBillId");
- Map p = new HashMap();
- p.put("payIdList",CommonUtil.listToStr4InSql(payIdList));
- IPage<Map> payList = ownCreditService.getAccountsPay(p,request);
- map.put("payList",payList);
- }
- return AjaxResult.success(map);
- }
- /**
- * 修改融信
- * @param map
- * @return
- * @throws Exception
- */
- @PreAuthorize(hasPermi = "credit:credit:update")
- @Log(title = "融信管理", businessType = BusinessType.UPDATE)
- @Transactional(rollbackFor = Exception.class)
- @PutMapping
- public AjaxResult edit(@RequestBody Map<String, Object> map) throws Exception{
- //获取此操作员
- LoginUser userInfo = tokenService.getLoginUser();
- SysUser user = userInfo.getSysUser();
- //获取用户编号
- String userId = user.getUserId()+"";
- //获取融信编号
- String id = CommonUtil.objToString(map.get("zfiId"));
- //获取融信的类型
- String type = CommonUtil.objToString(map.get("type"));
- //获取产品是否可拆分
- String zfpSplit = CommonUtil.objToString(map.get("zfpSplit"));
- //获取放款方式
- String zfpcrLoanType = CommonUtil.objToString(map.get("zfpcrLoanType"));
- //融信编号
- String str = "";
- //判断类型
- //开立
- if("1".equals(type) || "2".equals(type)){
- str = "CM";
- }else if("0".equals(type)){
- //申请
- str = "SM";
- }
- //产品不可拆分
- if("0".equals(zfpSplit)){
- str += "D";
- }else if("1".equals(zfpSplit)){
- //可拆分
- str += "R";
- }
- //放款方式--供应商
- if("0".equals(zfpcrLoanType)){
- str += "P";
- }else if("1".equals(zfpcrLoanType)){
- //平台电子记账
- str += "E";
- }
- ZcFinanceInf inf = new ZcFinanceInf();
- //主键
- inf.setZfiId(id);
- //非开立
- if(!"0".equals(type)){
- //获取之前的融信编号
- String zfiNumber = CommonUtil.objToString(map.get("zfiNumber"));
- //获取之前融信编号的时间戳
- String time = zfiNumber.substring(zfiNumber.length() - 14,zfiNumber.length());
- str += time;
- //融信编号
- inf.setZfiNumber(str);
- }
- //获取申请金额
- String zfiAmount = CommonUtil.objToString(map.get("zfiAmount"));
- if(CommonUtil.isEmpty(zfiAmount)){
- throw new Exception("请输入申请金额");
- }
- if(!AmtUtil.isMoney(zfiAmount)){
- throw new Exception("请输入正确的申请金额");
- }
- //非供应商申请
- if(!"0".equals(type)){
- //获取可用额度
- String availableAmt = CommonUtil.objToString(map.get("availableAmt"));
- if(CommonUtil.compare(zfiAmount,availableAmt) == 1){
- throw new Exception("签发金额不可大于可用额度");
- }
- //承诺付款日
- String zfiExpireDate = CommonUtil.objToString(map.get("zfiExpireDate"));
- //签发有效期
- String zfiEffectiveDate = CommonUtil.objToString(map.get("zfiEffectiveDate"));
- if(CommonUtil.isEmpty(zfiEffectiveDate)){
- throw new Exception("请选择签发有效期");
- }
- if(CommonUtil.isEmpty(zfiExpireDate)){
- throw new Exception("请选择承诺付款日");
- }
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
- Date date = simpleDateFormat.parse(zfiEffectiveDate);
- inf.setZfiEffectiveDate(date);
- Date signDate = simpleDateFormat.parse(zfiExpireDate);
- inf.setZfiExpireDate(signDate);
- }
- //修改人
- inf.setUpdateBy(userId);
- //修改时间
- inf.setUpdateTime(DateUtils.getNowDate());
- //获取产品
- String productId = CommonUtil.objToString(map.get("zfpId"));
- inf.setZfiProductId(productId);
- //获取收付款
- List<Map<String,String>> ticketList = (List<Map<String, String>>) map.get("ticketList");
- if("1".equals(type)){
- //核心企业授信额度
- String zfiCoreQuotaId = CommonUtil.objToString(map.get("zfiCoreQuotaId"));
- inf.setZfiCoreQuotaId(zfiCoreQuotaId);
- //接收企业
- String zfiSupplierId = CommonUtil.objToString(map.get("zfiSupplierId"));
- inf.setZfiSupplierId(zfiSupplierId);
- //选择
- if(ticketList.size() > 1){
- //获取第一个应收企业
- String receiveName = ticketList.get(0).get("receiveName");
- //获取预计还款日期
- String zbiPayDate = ticketList.get(0).get("zbiPayDate");
- for(int i = 0 ; i < ticketList.size();i++){
- if(!receiveName.equals(ticketList.get(i).get("receiveName"))){
- throw new Exception("请选择应收企业相同的应付账款");
- }
- if(!zbiPayDate.equals(ticketList.get(i).get("zbiPayDate"))){
- throw new Exception("请选择预计还款日期相同的应付账款");
- }
- }
- }
- }else if("0".equals(type) || "2".equals(type)){//供应商开立/申请
- //获取合计金额
- String checkTotalAmt = CommonUtil.objToString(map.get("checkTotalAmt"));
- //供应商开立
- if("2".equals(type)){
- //供应商企业授信额度
- String zfiSupplierQuotaId = CommonUtil.objToString(map.get("zfiSupplierQuotaId"));
- inf.setZfiSupplierQuotaId(zfiSupplierQuotaId);
- //获取供应商对应的核心授信额度
- ZcFinanceSupplierQuota supplierQuota = financeSupplierQuotaService.getById(zfiSupplierQuotaId);
- if(supplierQuota == null){
- throw new Exception("获取供应商授信额度失败");
- }
- String zfsqCoreQuotaId = supplierQuota.getZfsqCoreQuotaId();
- //核心授信额度
- inf.setZfiCoreQuotaId(zfsqCoreQuotaId);
- //获取收款账号
- /* String zfiCollectionAccount = CommonUtil.objToString(map.get("zfiCollectionAccount"));
- //获取放款方式--供应商指定的话为收款账号必输
- if("1".equals(zfpcrLoanType)){
- if(CommonUtil.isEmpty(zfiCollectionAccount)){
- throw new Exception("请输入收款账号");
- }
- }
- if(!"0".equals(zfpcrLoanType)){
- inf.setZfiCollectionAccount(zfiCollectionAccount);
- }*/
- }
- if(CommonUtil.compare(zfiAmount,checkTotalAmt) == 1){
- throw new Exception("签发金额不可大于合计金额");
- }
- if(ticketList.size() < 1){
- throw new Exception("请选择应收账款");
- }else if(ticketList.size() > 1){
- //获取第一个应付企业
- String payName = ticketList.get(0).get("payName");
- //获取预计还款日期
- String zbiPayDate = ticketList.get(0).get("zbiPayDate");
- for(int i = 0 ; i < ticketList.size();i++){
- if(!payName.equals(ticketList.get(i).get("payName"))){
- throw new Exception("请选择应付企业相同的应收账款");
- }
- if(!zbiPayDate.equals(ticketList.get(i).get("zbiPayDate"))){
- throw new Exception("请选择预计还款日期相同的应收账款");
- }
- }
- }
- //开立方==应付企业
- inf.setZfiCoreId(ticketList.get(0).get("zbiPayerId"));
- }
- //利率
- String zfiRate = CommonUtil.objToString(map.get("zfiRate"));
- inf.setZfiRate(zfiRate);
- //先删除该融信与应收付款的关系
- LambdaQueryWrapper<ZcFinanceBillRel> relLambdaQueryWrapper = new LambdaQueryWrapper<>();
- relLambdaQueryWrapper.eq(ZcFinanceBillRel::getZfbrFinanceId,id);
- financeBillRelService.deleteZcFinanceBillRel(relLambdaQueryWrapper);
- //插入融信和应收付款的关系
- for(int i = 0 ; i < ticketList.size();i++){
- //获取收付款编号
- String billId = ticketList.get(i).get("zbiId");
- ZcFinanceBillRel rel = new ZcFinanceBillRel();
- rel.setZfbrFinanceId(id);
- rel.setZfbrBillId(billId);
- financeBillRelService.createZcFinanceBillRel(rel);
- }
- inf.setZfiAmount(zfiAmount);
- //修改数据
- financeInfService.updateById(inf);
- return AjaxResult.success();
- }
- /**
- * 查询核心开立授信额度
- * @param zfpcrId
- * @return
- */
- @GetMapping("/getCreditLineList")
- public AjaxResult getCreditLineList(@RequestParam(required=false) String zfpcrId,
- @RequestParam(required=false) String type)
- {
- //获取当前企业的编号
- LoginUser userInfo = tokenService.getLoginUser();
- SysUser use = userInfo.getSysUser();
- Map<String,String> map = new HashMap<>();
- //获取企业
- String companyId = use.getCompanyId();
- map.put("zfpcrCompanyId", companyId);
- //授信额度编号
- map.put("zfpcrId",zfpcrId);
- //类型--1查询反向产品 0 查询正向产品
- map.put("type",type);
- List<Map> creditLineList = ownCreditService.selectCreditLineList(map);
- for(int i = 0 ; i < creditLineList.size();i++){
- Map<String,String> mmp = creditLineList.get(i);
- //获取授信额度编号
- String sxId = mmp.get("zfpcrId");
- LambdaQueryWrapper<ZcFinanceProComRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
- //公司
- lambdaQueryWrapper.eq(ZcFinanceProComRel::getZfpcrCompanyId,companyId);
- //授信编号
- lambdaQueryWrapper.eq(ZcFinanceProComRel::getZfpcrId,sxId);
- //授信额度
- String amount = "";
- List<ZcFinanceProComRel> list = financeProComRelService.findZcFinanceProComRels(lambdaQueryWrapper);
- if(list.size() < 1){
- return AjaxResult.error("获取授信额度信息失败");
- }
- amount = list.get(0).getZfpcrAmount();
- //获取已用的授信额度
- Map m = new HashMap();
- m.put("zfpcrId",sxId);
- m.put("companyId",companyId);
- String userdBalance = ownCreditService.getUsedBalance(m);
- //获取剩余额度
- String remaining = AmtUtil.subtract(amount,userdBalance,2);
- mmp.put("remaining",remaining);
- }
- return AjaxResult.success(creditLineList);
- }
- /**
- * 获取供应商授信额度
- * @param zfsqId
- * @return
- */
- @GetMapping("/getSupplierCreditLineList")
- public AjaxResult getSupplierCreditLineList(@RequestParam(required=false) String zfsqId)
- {
- //获取当前企业的编号
- LoginUser userInfo = tokenService.getLoginUser();
- SysUser use = userInfo.getSysUser();
- Map<String,String> map = new HashMap<>();
- //获取企业
- String companyId = use.getCompanyId();
- map.put("zfsqCompanyId", companyId);
- //授信额度编号
- map.put("zfsqId",zfsqId);
- List<Map> creditLineList = ownCreditService.selectSupplierCreditLineList(map);
- for(int i = 0 ; i < creditLineList.size();i++){
- Map<String,String> mmp = creditLineList.get(i);
- //获取授信编号
- String sxId = mmp.get("zfsqId");
- //查询供应商的授信额度
- LambdaQueryWrapper<ZcFinanceSupplierQuota> lambdaQueryWrapper = new LambdaQueryWrapper<>();
- //公司
- lambdaQueryWrapper.eq(ZcFinanceSupplierQuota::getZfsqCompanyId,companyId);
- //授信编号
- lambdaQueryWrapper.eq(ZcFinanceSupplierQuota::getZfsqId,sxId);
- //授信额度
- String amount = "";
- List<ZcFinanceSupplierQuota> list = financeSupplierQuotaService.findZcFinanceSupplierQuotas(lambdaQueryWrapper);
- if(list.size() < 1){
- return AjaxResult.error("获取授信额度信息失败");
- }
- amount = list.get(0).getZfsqAmount();
- //获取已用的授信额度
- Map m = new HashMap();
- m.put("zfsqId",sxId);
- m.put("companyId",companyId);
- String userdBalance = ownCreditService.getSupplierUsedBalance(m);
- //获取剩余额度
- String remaining = AmtUtil.subtract(amount,userdBalance,2);
- mmp.put("remaining",remaining);
- }
- return AjaxResult.success(creditLineList);
- }
- /**
- * 融信开立
- * @param map
- * @return
- * @throws Exception
- */
- @PreAuthorize(hasPermi = "credit:credit:add")
- @Log(title = "融信开立", businessType = BusinessType.INSERT)
- @Transactional(rollbackFor = Exception.class)
- @PostMapping
- public AjaxResult add(@RequestBody Map<String,Object> map)throws Exception
- {
- //获取收付款
- List<Map<String,String>> ticketList = (List<Map<String, String>>) map.get("ticketList");
- //获取融信的类型
- String type = CommonUtil.objToString(map.get("type"));
- //获取此操作员
- LoginUser userInfo = tokenService.getLoginUser();
- SysUser user = userInfo.getSysUser();
- //获取用户编号
- String userId = user.getUserId()+"";
- //获取企业
- String companyId = user.getCompanyId();
- //主键
- String id = IdUtils.fastSimpleUUID();
- //获取创建时间
- Date createTime = DateUtils.getNowDate();
- //获取当前时间
- String currentTime = DateUtils.parseDateToStr("yyyyMMddHHmmss",createTime);
- //获取产品是否可拆分
- String zfpSplit = CommonUtil.objToString(map.get("zfpSplit"));
- //获取放款方式
- String zfpcrLoanType = CommonUtil.objToString(map.get("zfpcrLoanType"));
- //融信编号
- String str = "";
- //判断类型
- //开立
- if("1".equals(type) || "2".equals(type)){
- str = "CM";
- }else if("0".equals(type)){
- //申请
- str = "SM";
- }
- //产品不可拆分
- if("0".equals(zfpSplit)){
- str += "D";
- }else if("1".equals(zfpSplit)){
- //可拆分
- str += "R";
- }
- //放款方式--供应商
- if("0".equals(zfpcrLoanType)){
- str += "P";
- }else if("1".equals(zfpcrLoanType)){
- //平台电子记账
- str += "E";
- }
- str = str + currentTime;
- ZcFinanceInf inf = new ZcFinanceInf();
- //主键
- inf.setZfiId(id);
- //融信编号--申请
- if("0".equals(type)){
- inf.setZfiNumber(currentTime);
- }else{//开立
- inf.setZfiNumber(str);
- }
- //创建类型-- 0供应商申请 1核心开立 2供应商开立
- inf.setZfiCreateType(type);
- //还款函编号
- //随机生成8位字母
- String zfiPaymentNumber = getRandomNickname(8)+currentTime;
- inf.setZfiPaymentNumber(zfiPaymentNumber);
- //获取申请金额
- String zfiAmount = CommonUtil.objToString(map.get("zfiAmount"));
- if(CommonUtil.isEmpty(zfiAmount)){
- throw new Exception("请输入申请金额");
- }
- if(!AmtUtil.isMoney(zfiAmount)){
- throw new Exception("请输入正确的申请金额");
- }
- //非供应商申请
- if(!"0".equals(type)){
- //获取可用额度
- String availableAmt = CommonUtil.objToString(map.get("availableAmt"));
- if(CommonUtil.compare(zfiAmount,availableAmt) == 1){
- throw new Exception("签发金额不可大于可用额度");
- }
- //承诺付款日
- String zfiExpireDate = CommonUtil.objToString(map.get("zfiExpireDate"));
- //签发有效期
- String zfiEffectiveDate = CommonUtil.objToString(map.get("zfiEffectiveDate"));
- if(CommonUtil.isEmpty(zfiEffectiveDate)){
- throw new Exception("请选择签发有效期");
- }
- if(CommonUtil.isEmpty(zfiExpireDate)){
- throw new Exception("请选择承诺付款日");
- }
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
- Date date = simpleDateFormat.parse(zfiEffectiveDate);
- inf.setZfiEffectiveDate(date);
- Date signDate = simpleDateFormat.parse(zfiExpireDate);
- inf.setZfiExpireDate(signDate);
- }
- //创建人
- inf.setCreateBy(userId);
- //创建时间
- inf.setCreateTime(createTime);
- //获取产品
- String productId = CommonUtil.objToString(map.get("zfpId"));
- inf.setZfiProductId(productId);
- //利率
- String zfiRate = CommonUtil.objToString(map.get("zfiRate"));
- inf.setZfiRate(zfiRate);
- //核心开立
- if("1".equals(type)){
- //根据有无审批流做判断
- Map<String,Object> pp = new HashMap<>();
- pp.put("menuId","1000000000");
- pp.put("companyId",companyId);
- Map<String,Object> mmp = flowableService.selectApproval(pp);
- //不等于200
- if(CommonUtil.compare(CommonUtil.objToString(mmp.get("code")),"200") != 0){
- throw new Exception("查询审批流程失败");
- }
- List<Map<String,Object>> list = (List<Map<String, Object>>) mmp.get("data");
- //未开启流程审批
- if(list.size() < 1){
- //通过
- inf.setZfiCoreStatus("01");
- }else{
- //核心企业状态--暂存
- inf.setZfiCoreStatus("03");
- }
- //接收企业
- String zfiSupplierId = CommonUtil.objToString(map.get("zfiSupplierId"));
- inf.setZfiSupplierId(zfiSupplierId);
- //开立企业
- inf.setZfiCoreId(companyId);
- //核心企业授信额度
- String zfiCoreQuotaId = CommonUtil.objToString(map.get("zfiCoreQuotaId"));
- inf.setZfiCoreQuotaId(zfiCoreQuotaId);
- //选择
- if(ticketList.size() > 1){
- //获取第一个应收企业
- String receiveName = ticketList.get(0).get("receiveName");
- //获取预计还款日期
- String zbiPayDate = ticketList.get(0).get("zbiPayDate");
- for(int i = 0 ; i < ticketList.size();i++){
- if(!receiveName.equals(ticketList.get(i).get("receiveName"))){
- throw new Exception("请选择应收企业相同的应付账款");
- }
- if(!zbiPayDate.equals(ticketList.get(i).get("zbiPayDate"))){
- throw new Exception("请选择预计还款日期相同的应付账款");
- }
- }
- }
- }else if("0".equals(type) || "2".equals(type)){//供应商开立/申请
- // 根据有无审批流做判断
- //获取合计金额
- String checkTotalAmt = CommonUtil.objToString(map.get("checkTotalAmt"));
- //供应商开立
- if("2".equals(type)){
- //根据有无审批流做判断
- Map<String,Object> pp = new HashMap<>();
- pp.put("menuId","1000000001");
- pp.put("companyId",companyId);
- Map<String,Object> mmp = flowableService.selectApproval(pp);
- //不等于200
- if(CommonUtil.compare(CommonUtil.objToString(mmp.get("code")),"200") != 0){
- throw new Exception("查询审批流程失败");
- }
- List<Map<String,Object>> list = (List<Map<String, Object>>) mmp.get("data");
- //未开启流程审批
- if(list.size() < 1){
- //通过
- inf.setZfiSupplierStatus("01");
- }else{
- //供应商企业状态--暂存
- inf.setZfiSupplierStatus("03");
- }
- //供应商企业授信额度
- String zfiSupplierQuotaId = CommonUtil.objToString(map.get("zfiSupplierQuotaId"));
- inf.setZfiSupplierQuotaId(zfiSupplierQuotaId);
- //获取供应商对应的核心授信额度
- ZcFinanceSupplierQuota supplierQuota = financeSupplierQuotaService.getById(zfiSupplierQuotaId);
- if(supplierQuota == null){
- throw new Exception("获取供应商授信额度失败");
- }
- String zfsqCoreQuotaId = supplierQuota.getZfsqCoreQuotaId();
- //核心授信额度
- inf.setZfiCoreQuotaId(zfsqCoreQuotaId);
- //获取收款账号
- /*String zfiCollectionAccount = CommonUtil.objToString(map.get("zfiCollectionAccount"));
- //获取放款方式--供应商指定的话为收款账号必输
- if("1".equals(zfpcrLoanType)){
- if(CommonUtil.isEmpty(zfiCollectionAccount)){getFile
- throw new Exception("请输入收款账号");
- }
- }
- if(!"0".equals(zfpcrLoanType)){
- inf.setZfiCollectionAccount(zfiCollectionAccount);
- }*/
- }else if("0".equals(type)){//供应商申请
- //根据有无审批流做判断
- Map<String,Object> pp = new HashMap<>();
- pp.put("menuId","1000000002");
- pp.put("companyId",companyId);
- Map<String,Object> mmp = flowableService.selectApproval(pp);
- //不等于200
- if(CommonUtil.compare(CommonUtil.objToString(mmp.get("code")),"200") != 0){
- throw new Exception("查询审批流程失败");
- }
- List<Map<String,Object>> list = (List<Map<String, Object>>) mmp.get("data");
- //未开启流程审批
- if(list.size() < 1){
- //通过
- inf.setZfiSupplierStatus("01");
- }else{
- //供应商企业状态--暂存
- inf.setZfiSupplierStatus("03");
- }
- }
- if(CommonUtil.compare(zfiAmount,checkTotalAmt) == 1){
- throw new Exception("签发金额不可大于合计金额");
- }
- if(ticketList.size() < 1){
- throw new Exception("请选择应收账款");
- }else if(ticketList.size() > 1){
- //获取第一个应付企业
- String payName = ticketList.get(0).get("payName");
- //获取预计还款日期
- String zbiPayDate = ticketList.get(0).get("zbiPayDate");
- for(int i = 0 ; i < ticketList.size();i++){
- if(!payName.equals(ticketList.get(i).get("payName"))){
- throw new Exception("请选择应付企业相同的应收账款");
- }
- if(!zbiPayDate.equals(ticketList.get(i).get("zbiPayDate"))){
- throw new Exception("请选择预计还款日期相同的应收账款");
- }
- }
- }
- //开立方==应付企业
- inf.setZfiCoreId(ticketList.get(0).get("zbiPayerId"));
- //接收方 ==本公司
- inf.setZfiSupplierId(companyId);
- }
- //插入融信和应收付款的关系
- for(int i = 0 ; i < ticketList.size();i++){
- //获取收付款编号
- String billId = ticketList.get(i).get("zbiId");
- ZcFinanceBillRel rel = new ZcFinanceBillRel();
- rel.setZfbrFinanceId(id);
- rel.setZfbrBillId(billId);
- financeBillRelService.createZcFinanceBillRel(rel);
- }
- inf.setZfiAmount(zfiAmount);
- //插入数据
- financeInfService.createZcFinanceInf(inf);
- //核心开立
- if("1".equals(type)){
- map.put("zfiId",id);
- map.put("zfiCoreId",companyId);
- //调用核心开立审批流
- approvalService.coreApproval(CommonUtil.entityToMap(inf));
- }
- return AjaxResult.success();
- }
- /**
- * 获取核心开立接收方
- * @param zfiSupplierId
- * @return
- */
- @GetMapping("/getReceiverList")
- public AjaxResult getReceiverList(@RequestParam(required=false) String zfiSupplierId, QueryRequest request)
- {
- //获取当前企业的编号
- LoginUser userInfo = tokenService.getLoginUser();
- SysUser use = userInfo.getSysUser();
- //获取当前公司
- String companyId = use.getCompanyId();
- Map<String,String> map = new HashMap<>();
- map.put("companyId",companyId);
- map.put("zfiSupplierId",zfiSupplierId);
- IPage<Map> companyList = ownCreditService.getReceiverList(map,request);
- return AjaxResult.success(companyList);
- }
- /**
- * 核心开立查询应付账款
- * @return
- */
- @GetMapping("/getAccountsPay")
- public AjaxResult getAccountsPay(@RequestParam(required=false) String zbiName,
- @RequestParam(required=false) String receiveName,
- QueryRequest request) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- //获取当前企业的编号
- LoginUser userInfo = tokenService.getLoginUser();
- SysUser use = userInfo.getSysUser();
- Map<String,String> map = new HashMap<>();
- //查询非失效的融信
- LambdaQueryWrapper<ZcFinanceInf> financeInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
- financeInfLambdaQueryWrapper.ne(ZcFinanceInf::getZfiStatus,"03");
- List<ZcFinanceInf> financeInfsList = financeInfService.findZcFinanceInfs(financeInfLambdaQueryWrapper);
- if(financeInfsList.size() > 0){
- //提取融信编号
- List<String> financeIdList = CommonUtil.getIdFromList(financeInfsList,"zfiId");
- //查询融信已关联应付账款
- LambdaQueryWrapper<ZcFinanceBillRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
- lambdaQueryWrapper.in(ZcFinanceBillRel::getZfbrFinanceId,financeIdList);
- List<ZcFinanceBillRel> relList = financeBillRelService.findZcFinanceBillRels(lambdaQueryWrapper);
- if(relList.size() > 0){
- List<String> billIdList = CommonUtil.getIdFromList(relList,"zfbrBillId");
- map.put("billIdList",CommonUtil.listToStr4InSql(billIdList));
- }
- }
- //获取公司编号
- String companyId = use.getCompanyId();
- map.put("zbiPayerId",companyId);
- //账款名称
- map.put("zbiName",zbiName);
- //应收企业
- map.put("receiveName",receiveName);
- IPage<Map> payList = ownCreditService.getAccountsPay(map,request);
- return AjaxResult.success(payList);
- }
- /**
- *
- *融资开立查询应收账款
- * @param zbiName
- * @param payName
- * @param request
- * @return
- */
- @GetMapping("/getAccountsCollection")
- public AjaxResult getAccountsCollection(@RequestParam(required=false) String zbiName,
- @RequestParam(required=false) String payName,
- @RequestParam(required=false) String payId,
- @RequestParam(required=false) String zfiSupplierId,
- QueryRequest request) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- //获取当前企业的编号
- LoginUser userInfo = tokenService.getLoginUser();
- SysUser use = userInfo.getSysUser();
- //获取公司编号
- String companyId = use.getCompanyId();
- Map<String,String> map = new HashMap<>();
- //查询非失效的融信
- LambdaQueryWrapper<ZcFinanceInf> financeInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
- financeInfLambdaQueryWrapper.ne(ZcFinanceInf::getZfiStatus,"03");
- List<ZcFinanceInf> financeInfsList = financeInfService.findZcFinanceInfs(financeInfLambdaQueryWrapper);
- if(financeInfsList.size() > 0){
- //提取融信编号
- List<String> financeIdList = CommonUtil.getIdFromList(financeInfsList,"zfiId");
- //查询融信已关联应付账款
- LambdaQueryWrapper<ZcFinanceBillRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
- lambdaQueryWrapper.in(ZcFinanceBillRel::getZfbrFinanceId,financeIdList);
- List<ZcFinanceBillRel> relList = financeBillRelService.findZcFinanceBillRels(lambdaQueryWrapper);
- if(relList.size() > 0){
- List<String> billIdList = CommonUtil.getIdFromList(relList,"zfbrBillId");
- map.put("billIdList",CommonUtil.listToStr4InSql(billIdList));
- }
- }
- //接收方
- if(!CommonUtil.isEmpty(zfiSupplierId)){
- //应收企业
- map.put("zbiPayeeId",zfiSupplierId);
- }else{
- //应收企业
- map.put("zbiPayeeId",companyId);
- }
- //账款名称
- map.put("zbiName",zbiName);
- //应付企业
- map.put("payName",payName);
- //应付企业编号
- map.put("payId",payId);
- IPage<Map> collectionList = ownCreditService.getAccountsCollection(map,request);
- return AjaxResult.success(collectionList);
- }
- /**
- * 核心开立获取可用余额
- * @param zfpcrId
- * @return
- */
- @GetMapping("/getAvailableBalance")
- public AjaxResult getAvailableBalance(@RequestParam(required=false) String zfpcrId)
- {
- //获取当前企业的编号
- LoginUser userInfo = tokenService.getLoginUser();
- SysUser use = userInfo.getSysUser();
- //获取公司编号
- String companyId = use.getCompanyId();
- LambdaQueryWrapper<ZcFinanceProComRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
- //公司
- lambdaQueryWrapper.eq(ZcFinanceProComRel::getZfpcrCompanyId,companyId);
- //授信编号
- lambdaQueryWrapper.eq(ZcFinanceProComRel::getZfpcrId,zfpcrId);
- //授信额度
- String amount = "";
- List<ZcFinanceProComRel> list = financeProComRelService.findZcFinanceProComRels(lambdaQueryWrapper);
- if(list.size() < 1){
- return AjaxResult.error("获取授信额度信息失败");
- }
- amount = list.get(0).getZfpcrAmount();
- //获取已用的授信额度
- Map m = new HashMap();
- m.put("zfpcrId",zfpcrId);
- m.put("companyId",companyId);
- String userdBalance = ownCreditService.getUsedBalance(m);
- //获取剩余额度
- String remaining = AmtUtil.subtract(amount,userdBalance,2);
- Map map = new HashMap();
- map.put("remaining",remaining);
- return AjaxResult.success(map);
- }
- /**
- * 获取供应商开立可用额度
- * @param zfsqId
- * @return
- */
- @GetMapping("/getSupplierAvailableBalance")
- public AjaxResult getSupplierAvailableBalance(@RequestParam(required=false) String zfsqId)
- {
- //获取当前企业的编号
- LoginUser userInfo = tokenService.getLoginUser();
- SysUser use = userInfo.getSysUser();
- //获取公司编号
- String companyId = use.getCompanyId();
- //查询供应商的授信额度
- LambdaQueryWrapper<ZcFinanceSupplierQuota> lambdaQueryWrapper = new LambdaQueryWrapper<>();
- //公司
- lambdaQueryWrapper.eq(ZcFinanceSupplierQuota::getZfsqCompanyId,companyId);
- //授信编号
- lambdaQueryWrapper.eq(ZcFinanceSupplierQuota::getZfsqId,zfsqId);
- //授信额度
- String amount = "";
- List<ZcFinanceSupplierQuota> list = financeSupplierQuotaService.findZcFinanceSupplierQuotas(lambdaQueryWrapper);
- if(list.size() < 1){
- return AjaxResult.error("获取授信额度信息失败");
- }
- amount = list.get(0).getZfsqAmount();
- //获取已用的授信额度
- Map m = new HashMap();
- m.put("zfsqId",zfsqId);
- m.put("companyId",companyId);
- String userdBalance = ownCreditService.getSupplierUsedBalance(m);
- //获取剩余额度
- String remaining = AmtUtil.subtract(amount,userdBalance,2);
- Map map = new HashMap();
- map.put("remaining",remaining);
- return AjaxResult.success(map);
- }
- /**
- * 获取收付款下的附件信息
- * @param m
- * @return
- */
- @PostMapping("/getFile")
- public AjaxResult getFile(@RequestBody Map<String, Object> m) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- //发票文件
- List<PubFileInf> invoiceFileList = new ArrayList<>();
- //收付款的合同类型的文件
- List<PubFileInf> contractFileList = new ArrayList<>();
- //收付款的其他文件
- List<PubFileInf> otherFileList = new ArrayList<>();
- Map map = new HashMap();
- //获取传过来的收付款信息
- List<Map<String,String>> ticketList = (List<Map<String, String>>) m.get("ticketList");
- if (ticketList.size() < 1){
- //发票
- map.put("invoiceFileList",invoiceFileList);
- //合同
- map.put("contractFileList",contractFileList);
- //其他类型
- map.put("otherFileList",otherFileList);
- return AjaxResult.success(map);
- }
- //提取收付款编号
- List<String> zbiIdList = CommonUtil.getIdFromList(ticketList,"zbiId");
- //发票与收付款相关
- LambdaQueryWrapper<ZcBillInvoiceRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
- lambdaQueryWrapper.in(ZcBillInvoiceRel::getZbirBillId,zbiIdList);
- List<ZcBillInvoiceRel> relList = billInvoiceRelService.findZcBillInvoiceRels(lambdaQueryWrapper);
- //有关联的发票
- if(relList.size() > 0 ){
- List<String> invoiceIdList = CommonUtil.getIdFromList(relList,"zbirInvoiceId");
- //查询发票
- LambdaQueryWrapper<ZcInvoiceInf> invoiceInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
- invoiceInfLambdaQueryWrapper.in(ZcInvoiceInf::getZiiId,invoiceIdList);
- invoiceInfLambdaQueryWrapper.eq(ZcInvoiceInf::getZiiStatus,"00");
- List<ZcInvoiceInf> invoiceInfList = invoiceInfService.findZcInvoiceInfs(invoiceInfLambdaQueryWrapper);
- //发票信息不为空
- if(invoiceInfList.size() > 0){
- //提取出文件信息
- List<String> fileIdList = CommonUtil.getIdFromList(invoiceInfList,"ziiFile");
- LambdaQueryWrapper<PubFileInf> fileInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
- fileInfLambdaQueryWrapper.in(PubFileInf::getPfiFileId,fileIdList);
- fileInfLambdaQueryWrapper.eq(PubFileInf::getPfiIsDel,"00");
- //查询文件
- invoiceFileList = fileInfService.findPubFileInfs(fileInfLambdaQueryWrapper);
- }
- }
- map.put("invoiceFileList",invoiceFileList);
- //查询文件关系表
- LambdaQueryWrapper<ZcBillFileRel> billFileRelLambdaQueryWrapper = new LambdaQueryWrapper<>();
- billFileRelLambdaQueryWrapper.in(ZcBillFileRel::getZbfrBillId,zbiIdList);
- billFileRelLambdaQueryWrapper.eq(ZcBillFileRel::getZbfrType,"0");
- List<ZcBillFileRel> billFileRelList = billFileRelService.findZcBillFileRels(billFileRelLambdaQueryWrapper);
- //不为空
- if(billFileRelList.size() > 0){
- //提取文件编号
- List<String> idList = CommonUtil.getIdFromList(billFileRelList,"zbfrFileId");
- LambdaQueryWrapper<PubFileInf> fileInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
- fileInfLambdaQueryWrapper.in(PubFileInf::getPfiFileId,idList);
- fileInfLambdaQueryWrapper.eq(PubFileInf::getPfiIsDel,"00");
- contractFileList = fileInfService.findPubFileInfs(fileInfLambdaQueryWrapper);
- }
- map.put("contractFileList",contractFileList);
- //查询文件关系表
- LambdaQueryWrapper<ZcBillFileRel> fileRelLambdaQueryWrapper = new LambdaQueryWrapper<>();
- fileRelLambdaQueryWrapper.in(ZcBillFileRel::getZbfrBillId,zbiIdList);
- fileRelLambdaQueryWrapper.eq(ZcBillFileRel::getZbfrType,"2");
- List<ZcBillFileRel> relFileList = billFileRelService.findZcBillFileRels(fileRelLambdaQueryWrapper);
- //不为空
- if(relFileList.size() > 0){
- //提取文件编号
- List<String> idList = CommonUtil.getIdFromList(relFileList,"zbfrFileId");
- LambdaQueryWrapper<PubFileInf> fileInfLambdaQueryWrapper = new LambdaQueryWrapper<>();
- fileInfLambdaQueryWrapper.in(PubFileInf::getPfiFileId,idList);
- fileInfLambdaQueryWrapper.eq(PubFileInf::getPfiIsDel,"00");
- otherFileList = fileInfService.findPubFileInfs(fileInfLambdaQueryWrapper);
- }
- map.put("otherFileList",otherFileList);
- return AjaxResult.success(map);
- }
- /**
- * 随机生成length个字母
- * @param length
- * @return
- */
- public static String getRandomNickname(int length) {
- String val = "";
- Random random = new Random();
- for (int i = 0; i < length; i++) {
- // 字符串
- // 取得大写字母还是小写字母
- int choice = random.nextInt(2) % 2 == 0 ? 65 : 97;
- val += (char) (choice + random.nextInt(26));
- }
- return val;
- }
- /**
- * 获取当前操作员
- * @return
- * @throws Exception
- */
- @GetMapping("/getUser")
- public R getUser()throws Exception {
- //获取当前操作员
- LoginUser user = tokenService.getLoginUser();
- String companyId = user.getSysUser().getCompanyId();
- return R.ok(companyId);
- }
- }
|