WebReportTableController.java 3.76 KB
package com.lhcredit.project.webbusiness.controller;

import cn.hutool.core.util.ObjectUtil;
import com.github.pagehelper.PageHelper;
import com.lhcredit.common.utils.StringUtils;
import com.lhcredit.framework.aspectj.lang.annotation.Log;
import com.lhcredit.framework.aspectj.lang.enums.BusinessType;
import com.lhcredit.framework.aspectj.lang.enums.OperatorType;
import com.lhcredit.framework.web.controller.BaseController;
import com.lhcredit.framework.web.domain.AjaxResult;
import com.lhcredit.framework.web.service.FastDFSClient;
import com.lhcredit.framework.web.service.FdfsService;
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.frontUser.service.RedisTokenManager;
import com.lhcredit.project.business.reportTable.domain.ReportTable;
import com.lhcredit.project.business.reportTable.service.ReportTableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

@Api(tags = "企业信用报告")
@RestController
@RequestMapping("/web/reportTable")
@RequiredArgsConstructor
public class WebReportTableController extends BaseController {

    @Autowired
    private ReportTableService reportTableService;
    @Autowired
    private RedisTokenManager redisTokenManager;
    @Autowired
    private FastDFSClient fastDFSClient;
    @Autowired
    private IFrontUserService frontUserService;

    @ResponseBody
    @ApiOperation(value = "企业信用报告列表")
    @Log(title = "企业信用报告列表", businessType = BusinessType.LIST, operatorType = OperatorType.WEB)
    @GetMapping("/list")
    public AjaxResult list() {
        PageHelper.startPage(1, 10);
        String isDel = null;
        List<ReportTable> list = reportTableService.findAllReportTable(isDel);
        return toAjax(list);
    }
    
    

    @ApiOperation(value = "修改企业信用报告列表")
    @PostMapping("/updateReport")
    public AjaxResult upLoad(ReportTable reportTable , @RequestParam("file") MultipartFile file) throws Exception {
        try {
            if (!ObjectUtil.isEmpty(file)){
            //通过名称判断图片是那种类型的并存入库中
            String fileName = file.getOriginalFilename();
            String suffix = null;
            Integer id = null;
            int lastIndex = fileName.lastIndexOf('.');
            if (lastIndex != -1) {
                suffix = fileName.substring(0, lastIndex);
                if (suffix.equals("标注版")){
                    id = 378;
                }
                if (suffix.equals("实地调查")){
                    id = 380;
                }
                if (suffix.equals("招投标")){
                    id = 381;
                }
                if (suffix.equals("企业债")){
                    id = 382;
                }
                if (suffix.equals("尽职调查报告")){
                    id = 383;
                }
                if (suffix.equals("海外报告")){
                    id = 384;
                }
            }
            String s = fastDFSClient.uploadFile(file);
            reportTable.setId(id);
            reportTable.setImageUrl(s);
            }
            reportTableService.updateReport(reportTable);
        } catch (IOException e) {
            e.printStackTrace();
            return AjaxResult.error();
        }
        return AjaxResult.success();
    }
}