WebBReportTableController.java 10.5 KB
package com.lhcredit.project.webbusiness.controller;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.lhcredit.common.utils.StringUtils;
import com.lhcredit.common.utils.security.ShiroUtils;
import com.lhcredit.framework.aspectj.lang.annotation.CheckToken;
import com.lhcredit.framework.aspectj.lang.annotation.OrderCountCheck;
import com.lhcredit.framework.aspectj.lang.enums.OperatorType;
import com.lhcredit.project.business.contractBusinessType.service.IContractBusinessTypeService;
import com.lhcredit.project.business.contractReportBusinessType.service.IContractReportBusinessTypeService;
import com.lhcredit.project.business.frontUser.domain.FrontUserMon;
import com.lhcredit.project.business.frontUser.service.FrontUserServiceImpl;
import com.lhcredit.project.business.templateConfiguration.domain.TemplateConfiguration;
import com.lhcredit.project.business.templateConfiguration.service.TemplateConfigurationServiceImpl;
import com.lhcredit.project.business.templateConfigurationParameters.domain.TemplateConfigurationParameters;
import com.lhcredit.project.business.templateConfigurationParameters.service.TemplateConfigurationParametersServiceImpl;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.lhcredit.framework.aspectj.lang.annotation.Log;
import com.lhcredit.framework.aspectj.lang.enums.BusinessType;
import com.lhcredit.project.business.bReportTable.domain.BReportTable;
import com.lhcredit.project.business.bReportTable.service.IBReportTableService;
import com.lhcredit.framework.web.controller.BaseController;
import com.lhcredit.framework.web.domain.AjaxResult;


/**
 * 报告样式信息对外接口
 *
 * @author lhcredit
 * @date 2024-05-31
 */
@RestController
@RequestMapping("/web/bReportTable")
public class WebBReportTableController extends BaseController {
    @Autowired
    private IBReportTableService bReportTableService;

    @Autowired
    private IContractReportBusinessTypeService contractReportBusinessTypeService;

    @Autowired
    private FrontUserServiceImpl frontUserService;

    @Autowired
    private TemplateConfigurationServiceImpl templateConfigurationService;
    @Autowired
    private TemplateConfigurationParametersServiceImpl templateConfigurationParametersService;

    /**
     * 查询报告样式列表接口
     */
    @ApiOperation("查询报告样式列表")
    @Log(title = "报告样式", businessType = BusinessType.LIST, operatorType = OperatorType.WEB)
    @GetMapping("/list")
//    @CheckToken
    public AjaxResult list(BReportTable bReportTable) {
        startPage();
        bReportTable.setIsDel(1);
        List<BReportTable> list = bReportTableService.changeModel(bReportTableService.selectBReportTableList(bReportTable));
        //转成map
        Map<Long, BReportTable> breportTableMap = list.stream().collect(Collectors.toMap(BReportTable::getBizType, Function.identity()));
        FrontUserMon userInfo = getUserInfo();

//        FrontUserMon userInfo = new FrontUserMon();
//        userInfo.setBizTypes("-2,60");
        if(userInfo!=null){

            //通过orgId 查询 当前公司所能下单的报告模板类型
            TemplateConfiguration tc = new TemplateConfiguration();
            tc.setOrgId(userInfo.getOrgId());
            TemplateConfiguration conf = frontUserService.getTemplateConfiguration(userInfo.getOrgId());
            if (conf == null){
                for (BReportTable r : list) {
                    //设置 其无下单权限
                    r.setHasPermiss("0");
                }
                return toAjax(list);

            }
            String bizTypes = conf.getTypeId();
//            String bizTypes = userInfo.getBizTypes();

            List<String> stringList = Arrays.asList(bizTypes.split(","));
            for (BReportTable reportTable : list) {
                Long bizType = reportTable.getBizType();
                reportTable.setHasPermiss("0");
                if(stringList.contains(bizType.toString())){
                    reportTable.setHasPermiss("1");
                }
            }

            //处理  企业信用报告(标准版)
//            if (stringList.contains("-4")){
//                BReportTable source = breportTableMap.get(-4L);
//                BReportTable table = new BReportTable();
//                BeanUtils.copyProperties(source, table);
//                table.setBizType(-4L);
//                table.setHasPermiss("1");
//                table.setId("-1");
//                list.add(table);
//                list=list.stream().filter(f->!f.getBizType().toString().equals("-4")&&f.getHasPermiss().equals("1")).collect(Collectors.toList());
//            }
            if(stringList.contains("-2")){
                BReportTable source = breportTableMap.get(-4L);
                BReportTable table = new BReportTable();
                BeanUtils.copyProperties(source, table);
                table.setBizType(-2L);
                table.setHasPermiss("1");
                table.setId("-1");
                list.add(table);
                list=list.stream().filter(f->!f.getBizType().toString().equals("-4")).collect(Collectors.toList());
            }
            if(stringList.contains("-9")){
                BReportTable source = breportTableMap.get(-4L);
                BReportTable table = new BReportTable();
                BeanUtils.copyProperties(source, table);
                table.setBizType(-9L);
                table.setHasPermiss("1");
                table.setId("-1");
                list.add(table);
                list=list.stream().filter(f->!f.getBizType().toString().equals("-4")).collect(Collectors.toList());
            }
            if(stringList.contains("-15")){
                BReportTable source = breportTableMap.get(-4L);
                BReportTable table = new BReportTable();
                BeanUtils.copyProperties(source, table);
                table.setBizType(-15L);
                table.setHasPermiss("1");
                table.setId("-1");
                list.add(table);
                list=list.stream().filter(f->!f.getBizType().toString().equals("-4")).collect(Collectors.toList());
            }

//            if(stringList.contains("-3")){
//                BReportTable source = breportTableMap.get(-3L);
//                BReportTable table = new BReportTable();
//                BeanUtils.copyProperties(source, table);
//                table.setBizType(-3L);
//                table.setHasPermiss("1");
//                table.setId("-2");
//                list.add(table);
//                list=list.stream().collect(Collectors.toList());
//            }
             if(stringList.contains("-5")){
                BReportTable source = breportTableMap.get(-3L);
                BReportTable table = new BReportTable();
                BeanUtils.copyProperties(source, table);
                table.setBizType(-5L);
                table.setHasPermiss("1");
                table.setId("-2");
                list.add(table);
                 list=list.stream().filter(f->!f.getBizType().toString().equals("-3")).collect(Collectors.toList());
            }
             if(stringList.contains("-8")){
                BReportTable source = breportTableMap.get(-3L);
                BReportTable table = new BReportTable();
                BeanUtils.copyProperties(source, table);
                table.setBizType(-8L);
                table.setHasPermiss("1");
                table.setId("-2");
                list.add(table);
                 list=list.stream().filter(f->!f.getBizType().toString().equals("-3")).collect(Collectors.toList());
            }
//            if(stringList.contains("-11")){
//                BReportTable source = breportTableMap.get(-11L);
//                BReportTable table = new BReportTable();
//                BeanUtils.copyProperties(source, table);
//                table.setBizType(-11L);
//                table.setHasPermiss("1");
//                table.setId("-3");
//                list.add(table);
//                list=list.stream().collect(Collectors.toList());
//            }
             if(stringList.contains("-12")){
                BReportTable source = breportTableMap.get(-11L);
                BReportTable table = new BReportTable();
                BeanUtils.copyProperties(source, table);
                table.setBizType(-12L);
                table.setHasPermiss("1");
                table.setId("-3");
                list.add(table);
                list=list.stream().filter(f->!f.getBizType().toString().equals("-11")).collect(Collectors.toList());
            }

        }
        if (CollectionUtils.isNotEmpty(list)){
            List<BReportTable> collect1 = list.stream().filter(f ->StringUtils.isNotEmpty(f.getHasPermiss()) &&f.getHasPermiss().equals("1")).collect(Collectors.toList());
            List<BReportTable> collect2 = list.stream().filter(f ->StringUtils.isNotEmpty(f.getHasPermiss()) && !f.getHasPermiss().equals("1")).collect(Collectors.toList());
            List<BReportTable> collect3= list.stream().filter(f ->StringUtils.isEmpty(f.getHasPermiss())).collect(Collectors.toList());
            collect1.addAll(collect2);
            collect1.addAll(collect3);
            return toAjax(collect1);
        }
        return toAjax(list);
    }

    @GetMapping("/test")
    public AjaxResult t(String  id){
        return  success(contractReportBusinessTypeService.getFromCrm(id));
    }

    @CheckToken
    @GetMapping("/clientType")
    public  AjaxResult BussinessType(){
        FrontUserMon userInfo = getUserInfo();
//        FrontUserMon userInfo = new FrontUserMon();
//        userInfo.setOrgId(24l);
        if(userInfo!=null){
            /*Long contractId = userInfo.getContractId();
            JSONObject obj = contractBusinessTypeService.findByCId(contractId);
            return success(obj);*/
            Long orgId = userInfo.getOrgId();
            List<TemplateConfigurationParameters> params = templateConfigurationParametersService.getTempConfParamsByOrg(orgId,"report_type");
            if (CollectionUtils.isEmpty(params))
                return AjaxResult.success("暂无数据");
            return AjaxResult.success(params);
        }
        return null;
    }


}