ZQN
2024-08-14 f6a1bf1d9b19dd8b3750034048f3876d086db1f1
project-admin/src/main/java/com/project/admin/controller/system/SysCompanyController.java
@@ -1,30 +1,36 @@
package com.project.admin.controller.system;
import java.util.List;
import java.util.Arrays;
import com.project.common.annotation.RepeatSubmit;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.hutool.core.convert.Convert;
import com.project.common.annotation.Log;
import com.project.common.annotation.RepeatSubmit;
import com.project.common.config.ProjectConfig;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.core.page.TableDataInfo;
import com.project.common.enums.BusinessType;
import com.project.system.domain.vo.SysCompanyVo;
import com.project.common.utils.StringUtils;
import com.project.common.utils.file.ImageUtils;
import com.project.common.utils.poi.ExcelUtil;
import com.project.common.utils.zip.ZipUtils;
import com.project.system.domain.SysCompany;
import com.project.system.domain.bo.editBo.SysCompanyBo;
import com.project.system.domain.bo.queryBo.SysCompanyQueryBo;
import com.project.system.domain.vo.SysCompanyResultVo;
import com.project.system.domain.vo.SysCompanyVo;
import com.project.system.service.ISysCompanyService;
import com.project.common.utils.poi.ExcelUtil;
import com.project.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
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.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
 * 企业信息Controller
@@ -40,6 +46,7 @@
    private final ISysCompanyService iSysCompanyService;
    @ApiOperation("查询企业信息列表")
    @GetMapping("/list")
    public TableDataInfo list(SysCompanyQueryBo bo)
@@ -50,6 +57,22 @@
    }
    @ApiOperation("下载二维码")
    @GetMapping("/downloadQrcode")
    public void downloadQrcode(SysCompanyQueryBo bo, HttpServletResponse response)
    {
        List<SysCompanyVo> list = iSysCompanyService.queryList(bo);
        list.forEach(e->{
            if (StringUtils.isEmpty(e.getQrcodeImg())){
                String qrcode = ImageUtils.createQrcode(e.getCompanyCode(), e.getCompanyName(), "2");
                e.setQrcodeImg(qrcode);
                iSysCompanyService.updateById(Convert.convert(SysCompany.class, e));
            }
        });
        List<String> collect = list.stream().map(SysCompanyVo::getQrcodeImg).collect(Collectors.toList());
        ZipUtils.downloadToZip(collect, response);
    }
    @ApiOperation("导出企业信息列表")
    //@PreAuthorize("@ss.hasPermi('system:company:export')")
@@ -58,7 +81,12 @@
    @RepeatSubmit
    public AjaxResult export(SysCompanyQueryBo bo)
    {
        List<SysCompanyVo> list = iSysCompanyService.queryList(bo);
        List<SysCompanyVo> list;
        if (bo==null){
            list = new ArrayList<>();
        } else {
            list = iSysCompanyService.queryList(bo);
        }
        ExcelUtil<SysCompanyVo> util = new ExcelUtil<>(SysCompanyVo.class);
        return util.exportExcel(list, "企业信息");
    }
@@ -94,6 +122,17 @@
    }
    @ApiOperation("企业信息状态开关")
    //@PreAuthorize("@ss.hasPermi('system:company:edit')")
    @Log(title = "企业信息状态开关", businessType = BusinessType.UPDATE)
    @PostMapping("/updStatus")
    @RepeatSubmit
    public AjaxResult updStatus(@RequestBody SysCompanyBo bo)
    {
        return toAjax(iSysCompanyService.updStatus(bo) ? 1 : 0);
    }
    @ApiOperation("删除企业信息")
    //@PreAuthorize("@ss.hasPermi('system:company:remove')")
    @Log(title = "企业信息" , businessType = BusinessType.DELETE)
@@ -103,4 +142,44 @@
    {
        return toAjax(iSysCompanyService.deleteByIds(Arrays.asList(companyIds)) ? 1 : 0);
    }
    @ApiOperation("企业信息模板下载")
    @GetMapping("/exportTemplate")
    public AjaxResult exportTemplate()
    {
        ExcelUtil<SysCompanyVo> util = new ExcelUtil<>(SysCompanyVo.class);
        return util.exportExcel(null, "企业信息模板");
    }
    @ApiOperation(value = "处理导入信息")
    @Log(title = "导入企业信息处理" , businessType = BusinessType.OTHER)
    @ApiImplicitParam(value = "企业信息", name = "file", dataType = "file", dataTypeClass = MultipartFile.class)
    @PostMapping("/doImport")
    public AjaxResult doImport(@RequestPart(value = "file") MultipartFile file) throws Exception
    {
        ExcelUtil<SysCompanyVo> util = new ExcelUtil<>(SysCompanyVo.class);
        List<SysCompanyVo> list = util.importExcel(file.getInputStream());
        return AjaxResult.success(iSysCompanyService.doImport(list));
    }
    @ApiOperation(value = "校验导入信息")
    @Log(title = "导入企业信息校验" , businessType = BusinessType.OTHER)
    @PostMapping("/checkImport")
    public AjaxResult checkImport(@RequestBody SysCompanyResultVo resultVo)
    {
        return AjaxResult.success(iSysCompanyService.checkImport(resultVo));
    }
    @ApiOperation(value = "保存导入信息")
    @Log(title = "导入企业信息保存" , businessType = BusinessType.IMPORT)
    @RepeatSubmit
    @PostMapping("/saveImport")
    public AjaxResult saveImport(@RequestBody SysCompanyResultVo resultVo)
    {
        return toAjax(iSysCompanyService.saveImport(resultVo) ? 1 : 0);
    }
}