WebFinanceInfoController.java 12.4 KB
package com.lhcredit.project.webbusiness.controller;

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

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lhcredit.common.utils.DateUtils;
import com.lhcredit.common.utils.ReportErrorUtils;
import com.lhcredit.common.utils.StringUtils;
import com.lhcredit.common.utils.security.ShiroUtils;
import com.lhcredit.framework.aspectj.lang.annotation.ReportCount;
import com.lhcredit.framework.aspectj.lang.enums.OperatorType;
import com.lhcredit.project.business.bCreditReport.domain.BCreditReport;
import com.lhcredit.project.business.bCreditReport.mapper.BCreditReportMapper;
import com.lhcredit.project.business.bCreditReport.service.IBCreditReportService;
import com.lhcredit.project.business.frontDept.service.IFrontDeptService;
import com.lhcredit.project.business.frontUser.domain.FrontUser;
import com.lhcredit.project.business.frontUser.domain.FrontUserMon;
import com.lhcredit.project.business.frontUser.service.IFrontUserService;
import com.lhcredit.project.business.reportFinanceData.domain.ReportFinanceData;
import com.lhcredit.project.business.reportFinanceData.service.IReportFinanceDataService;
import com.lhcredit.project.business.reportMake.finance.FinanceDataService;
import com.lhcredit.project.business.statisticsFinancePageselect.domain.StatisticsFinancePageselect;
import com.lhcredit.project.business.statisticsFinancePageselect.service.IStatisticsFinancePageselectService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
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.financeInfo.domain.FinanceInfo;
import com.lhcredit.project.business.financeInfo.service.IFinanceInfoService;
import com.lhcredit.framework.web.controller.BaseController;
import com.lhcredit.framework.web.domain.AjaxResult;

import static com.lhcredit.common.utils.JsonPathUtils.jsonPathString;


/**
 * 财务数据信息对外接口
 *
 * @author lhcredit
 * @date 2024-06-11
 */
@RestController
@RequestMapping("/web/financeInfo")
public class WebFinanceInfoController extends BaseController {
    @Autowired
    private IFinanceInfoService financeInfoService;
    @Autowired
    private IBCreditReportService ibCreditReportService;
    @Autowired
    private IFrontUserService frontUserService;
    @Autowired
    private IReportFinanceDataService reportFinanceDataService;
    @Autowired
    private FinanceDataService financeDataService;
    @Autowired
    private BCreditReportMapper bCreditReportMapper;
    @Autowired
    private IFrontDeptService frontDeptService;
    @Autowired
    private IStatisticsFinancePageselectService financePageselectService;
    public static String sourceType="2023";//作为页面调取财务数据使用的标识  目前还没有考虑  如何更新2024数据  目前最新就是2023






    @ReportCount(reportType = "financeInfo")
    @RequestMapping("reflushedFinance")
    public AjaxResult reflushedFinance(String name ){

        FrontUserMon userInfo = getUserInfo();
        List<ReportFinanceData> list=new ArrayList<>();
        String url = "http://cw.lhdna.com/queryDataController/queryData?name=" +name;
        String str = HttpRequest.get(url).execute().body();
        JSONObject jsonObject = JSONObject.parseObject(str);
        JSONArray data = jsonObject.getJSONArray("data");
        list= org.apache.commons.collections.CollectionUtils.isEmpty(data)?new ArrayList<>():data.toJavaList(ReportFinanceData.class);
        list.forEach(v->{v.setReportTemplate("ds");v.setLastUpdataTime(new Date());});
        //走查询就是记录查询记录了
        StatisticsFinancePageselect statisticsFinancePageselect=new StatisticsFinancePageselect();
        statisticsFinancePageselect.setUserId(userInfo.getId());
        statisticsFinancePageselect.setOrgId(frontDeptService.getParentDept(userInfo.getOrgId()).getId());
        statisticsFinancePageselect.setUserName(userInfo.getUserName());
        statisticsFinancePageselect.setEname(name);
        statisticsFinancePageselect.setDataType("工商大数");
        statisticsFinancePageselect.setCreditTime(new Date());
        statisticsFinancePageselect.setCountStatus(1);
        if (org.apache.commons.collections.CollectionUtils.isEmpty(list)) {
            statisticsFinancePageselect.setCountStatus(0);
            statisticsFinancePageselect.setResultRemark("无财务");
            financePageselectService.insertStatisticsFinancePageselect(statisticsFinancePageselect);
            return  AjaxResult.success(new JSONObject(){{put("status",4);}});//status=4 刷新无财务数据
        }else{
            reportFinanceDataService.saveList(list);
        }
        List<ReportFinanceData> ds = reportFinanceDataService.selectReportFinanceDataList(ReportFinanceData.builder().ename(name)
                .reportTemplate("ds").build());
        ds=ds.stream().sorted(Comparator.comparing(ReportFinanceData::getYear).reversed()).collect(Collectors.toList());
        if (ds.size()>3){
            ds=ds.subList(0,3);
        }
        JSONObject financeData =financeDataService.webTablePageFinanceCompute(ds);


        statisticsFinancePageselect.setCountStatus(1);
            statisticsFinancePageselect.setResultRemark(ds.stream().map(m->m.getYear()+"年")
                    .collect(Collectors.joining(","))+"财务数据");
            financePageselectService.insertStatisticsFinancePageselect(statisticsFinancePageselect);
        financeData.put("status",1);
        return  AjaxResult.success(financeData);//status=1 用户1年内做过报告数据
    }


    @RequestMapping("getWebFinanceShowData")
    public AjaxResult getWebFinanceShowData(String name,String search){
        FrontUserMon userInfo = getUserInfo();
        FrontUser frontUser = frontUserService.selectFrontUserById(userInfo.getId());
        BCreditReport bCreditReport=new BCreditReport();
        if (null==userInfo.getOrgId())return AjaxResult.error("未找到机构信息");
        bCreditReport.setOrgId(userInfo.getOrgId());
        bCreditReport.setEnterpriseName(name);
        List<String> bCreditReports = bCreditReportMapper.selectCountByFinanceStatistics(userInfo.getOrgId(),name);
        List<Object>  list2=financePageselectService.selectCountByFinanceStatistics(userInfo.getOrgId(),name);
        if (CollectionUtils.isEmpty(bCreditReports)&& CollectionUtils.isEmpty(list2)){
            return  AjaxResult.success(new JSONObject(){{put("status",0);}});//status=0 用户无报告数据
        }
        //下单xc据也查ds
        List<ReportFinanceData> ds = reportFinanceDataService.selectReportFinanceDataList(ReportFinanceData.builder().ename(name)
                .reportTemplate("ds").build());
        StatisticsFinancePageselect st=new StatisticsFinancePageselect();
        st.setUserId(userInfo.getId());
        //4个字段处理
        if (CollectionUtils.isEmpty(ds)){
            return AjaxResult.success(new JSONObject(){{put("status",3);}});//status=3 无财务数据
        }
        ds=ds.stream().sorted(Comparator.comparing(ReportFinanceData::getYear).reversed()).collect(Collectors.toList());
        if (ds.size()>3){
            ds=ds.subList(0,3);
        }
        JSONObject financeData =financeDataService.webTablePageFinanceCompute(ds);
        financeData.put("status",1);
        return  AjaxResult.success(financeData);//status=1 用户1年内做过报告数据
    }



    @ReportCount(reportType = "financeInfo")
    @RequestMapping("getReportSysData")
    public AjaxResult  getReportSysData(String ename,String orgCode){
        FrontUserMon userInfo = getUserInfo();
        List<FinanceInfo> oldList = financeInfoService.selectFinanceInfoList(FinanceInfo.builder().ename(ename).source(sourceType).build());
        if (CollectionUtils.isEmpty(oldList)){
            List<FinanceInfo> list=financeInfoService.getReportSystemApiData(ename,orgCode,userInfo.getId(),userInfo.getOrgId());
            for (FinanceInfo financeInfo : list) {
                financeInfo.setEname(ename);
                financeInfo.setSource(sourceType);
                financeInfoService.insertFinanceInfo(financeInfo);
            }

            //记录查询日志
            StatisticsFinancePageselect statisticsFinancePageselect=new StatisticsFinancePageselect();
            statisticsFinancePageselect.setUserId(userInfo.getId());
            statisticsFinancePageselect.setOrgId(userInfo.getOrgId());
            statisticsFinancePageselect.setUserName(userInfo.getUserName());
            statisticsFinancePageselect.setEname(ename);
            statisticsFinancePageselect.setDataType("工商大数");
            statisticsFinancePageselect.setCreditTime(new Date());
            if(list!=null&&list.size()>0){
                statisticsFinancePageselect.setCountStatus(1);
                statisticsFinancePageselect.setResultRemark(list.stream().map(m->m.getYear()+"年")
                        .collect(Collectors.joining(","))+"财务数据");
            }else {
                statisticsFinancePageselect.setCountStatus(0);
                statisticsFinancePageselect.setResultRemark("无财务");
            }
            financePageselectService.insertStatisticsFinancePageselect(statisticsFinancePageselect);
            oldList=list;
        }
        return AjaxResult.success(oldList);
    }
    /**
     * 查询财务数据列表接口
     */
    @ApiOperation("查询财务数据列表")
    @Log(title = "财务数据", businessType = BusinessType.LIST, operatorType = OperatorType.WEB)
    @GetMapping
    public AjaxResult list(FinanceInfo financeInfo) {
        startPage();
        financeInfo.setDelFlag("0");
        List<FinanceInfo> list = financeInfoService.changeModel(financeInfoService.selectFinanceInfoList(financeInfo));
        return toAjax(list);
    }
    /**
     * 查询财务数据详情接口
     */
    @ApiOperation("查询财务数据详情")
    @ApiImplicitParam(name = "id", value = "主键", required = true, dataType = "int", paramType = "path")
    @Log(title = "财务数据", businessType = BusinessType.DETAIL, operatorType = OperatorType.WEB)
    @GetMapping("/{id}")
    public AjaxResult detail(@PathVariable Long id) {
        FinanceInfo financeInfo =financeInfoService.changeModel(financeInfoService.selectFinanceInfoById(id));
        if (StringUtils.isNull(financeInfo)) {
            return AjaxResult.error("该信息不存在");
        }
        return toAjax(financeInfo);
    }
    /**
     * 新增保存财务数据接口
     */
    @ApiOperation("新增财务数据")
    @ApiImplicitParam(name = "financeInfo", value = "财务数据", dataType = "FinanceInfo")
    @Log(title = "财务数据", businessType = BusinessType.INSERT, operatorType = OperatorType.WEB)
    @PostMapping
    public AjaxResult addSave(FinanceInfo financeInfo) {
        financeInfo.setCreateBy(ShiroUtils.getLoginName());
        financeInfo.setCreateTime(new Date());
        financeInfo.setUpdateBy(ShiroUtils.getLoginName());
        financeInfo.setUpdateTime(new Date());
        return toAjax(financeInfoService.insertFinanceInfo(financeInfo));
    }

    /**
     * 修改保存财务数据接口
     */
    @ApiOperation("修改财务数据")
    @ApiImplicitParam(name = "financeInfo", value = "财务数据", dataType = "FinanceInfo")
    @Log(title = "财务数据", businessType = BusinessType.UPDATE, operatorType = OperatorType.WEB)
    @PutMapping
    public AjaxResult update(FinanceInfo financeInfo) {
        if (StringUtils.isNull(financeInfo) || StringUtils.isNull(financeInfo.getId())){
            return AjaxResult.error("主键id不能为空");
        }
        financeInfo.setUpdateBy(ShiroUtils.getLoginName());
        financeInfo.setUpdateTime(new Date());
        return toAjax(financeInfoService.updateFinanceInfo(financeInfo));
    }

    /**
     * 删除财务数据接口
     */
    @ApiOperation("删除财务数据")
    @ApiImplicitParam(name = "ids", value = "主键id,多条以英文逗号分隔", required = true, dataType = "String", paramType = "path")
    @Log(title = "财务数据", businessType = BusinessType.DELETE, operatorType = OperatorType.WEB)
    @DeleteMapping("/{ids}")
    public AjaxResult delete(@PathVariable String ids) {
        return toAjax(financeInfoService.deleteFinanceInfoByIds(ids));
    }

}