IntelligentRecognition/ah-jjsp-service/.svn/pristine/fc/fc66ad79e5d9b9285de52e821e6...

198 lines
8.0 KiB
Plaintext

package com.sercurityControl.proteam.controller;
import com.alibaba.fastjson2.JSONObject;
import com.securityControl.common.log.annotation.Log;
import com.securityControl.common.log.enums.BusinessType;
import com.securityControl.common.log.enums.OperationType;
import com.sercurityControl.proteam.domain.dto.RiskDelParamDto;
import com.sercurityControl.proteam.util.ImportExcelUtils;
import com.securityControl.common.core.web.controller.BaseController;
import com.securityControl.common.core.web.page.TableDataInfo;
import com.sercurityControl.proteam.domain.TRiskPressDropRate;
import com.sercurityControl.proteam.service.TRiskPressDropRateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.util.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import com.securityControl.common.core.web.domain.AjaxResult;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.*;
/**
* 风险压降率表(TRiskPressDropRate)控制层
*
* @author roof
* @since 2022-12-06 11:05:42
*/
@Api(tags = "压降率计算")
@Slf4j
@RestController
@RequestMapping("/pot/TRiskPressDropRate")
public class TRiskPressDropRateController extends BaseController {
@Autowired
private TRiskPressDropRateService tRiskPressDropRateService;
@Value("${file.upload_path}")
private String UPLOAD_PATH;
@Value("${file.download_path}")
private String DOWNLOAD_PATH;
/**
* 导入数据
*
* @param file 文件
* @throws IOException 异常
*/
@ApiOperation(value = "数据导入")
@PostMapping("/importExcel")
//@Log(title = "压降率计算", businessType = BusinessType.IMPORT, details = "数据导入")
public AjaxResult importExcel(MultipartFile file, HttpServletRequest request) throws Exception {
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
MultipartHttpServletRequest multiReq = multipartResolver.resolveMultipart(request);
// 地市、图片存储根目录
String cityName = multiReq.getParameter("cityName");
List<JSONObject> objectList = ImportExcelUtils.readExcel(file, TRiskPressDropRate.class, UPLOAD_PATH);
if (CollectionUtils.isEmpty(objectList)) {
return error("请勿导入空表格");
}
String message = tRiskPressDropRateService.importData(objectList, cityName, DOWNLOAD_PATH);
return success(message);
}
/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@GetMapping("/{id}")
@Log(title = "压降率计算", menu = "压降率计算", businessType = BusinessType.QUERY, details = "通过主键查询单条数据")
public AjaxResult queryById(@PathVariable("id") String id) {
return success(tRiskPressDropRateService.queryById(id));
}
@ApiOperation("模板下载")
@GetMapping("/downloadExcel")
@Log(title = "压降率计算", menu = "压降率计算", businessType = BusinessType.QUERY, details = "模板下载", grade = OperationType.DOWNLOAD_BUSINESS)
public void downloadExcel(HttpServletRequest request, HttpServletResponse response) {
InputStream inputStream = null;
ServletOutputStream servletOutputStream = null;
try {
String path = "download/" + "数据模板.xlsx";
inputStream = this.getClass().getClassLoader().getResourceAsStream(path);
response.setContentType("application/vnd.ms-excel");
response.addHeader("Cache-Control", "no-cache, no-store, must-revalidate");
response.addHeader("charset", "utf-8");
response.addHeader("Pragma", "no-cache");
String encodeName = URLEncoder.encode("数据模板.xlsx", StandardCharsets.UTF_8.toString());
response.setHeader("Content-Disposition", "attachment; filename=\"" + encodeName + "\"; filename*=utf-8''" + encodeName);
servletOutputStream = response.getOutputStream();
IOUtils.copy(inputStream, servletOutputStream);
response.flushBuffer();
//log.info("文件下载成功!!");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (servletOutputStream != null) {
servletOutputStream.close();
}
if (inputStream != null) {
inputStream.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* 删除数据
*
* @param id 主键
* @return 删除是否成功
*/
@DeleteMapping("/id")
@Log(title = "压降率计算", menu = "压降率计算", businessType = BusinessType.DELETE, details = "删除数据", grade = OperationType.DELETE_BUSINESS)
public AjaxResult deleteById(String id) {
tRiskPressDropRateService.deleteById(id);
return success();
}
/**
* @return com.securityControl.common.core.web.domain.AjaxResult
* @Author roof
* @Description 获取风险压降率的工程
* @Date 15:17 2022/4/27
* @Param []
*/
@ApiOperation(value = "获取风险压降率的工程")
@GetMapping("/getProNameList")
@Log(title = "压降率计算", menu = "压降率计算", businessType = BusinessType.QUERY, details = "获取风险压降率的工程")
public AjaxResult getProNameList(@RequestParam("cityName") String cityName) {
return AjaxResult.success(tRiskPressDropRateService.getProNameList(cityName));
}
/**
* @return com.securityControl.common.core.web.domain.AjaxResult
* @Author roof
* @Description 根据地市、或者工程来删除数据
* @Date 15:45 2022/4/27
* @Param [type, name]
*/
@ApiOperation(value = "根据地市、或者工程来删除数据")
@PostMapping("/delProList")
@Log(title = "压降率计算", menu = "压降率计算", businessType = BusinessType.QUERY, details = "根据地市、或者工程来删除数据", grade = OperationType.DELETE_BUSINESS)
public AjaxResult delProList(RiskDelParamDto paramDto) {
tRiskPressDropRateService.delProList(paramDto);
return success();
}
/**
* @return java.util.List<com.bonus.ahsbs.riskBloodPressure.entity.TRiskPressDropRate>
* @Author roof
* @Description 获取风险压降率数据
* @Date 16:40 2022/4/27
* @Param [o]
*/
@ApiOperation(value = "获取风险压降率数据")
@PostMapping("/getRiskBloodList")
@Log(title = "压降率计算", menu = "压降率计算", businessType = BusinessType.QUERY, details = "获取风险压降率数据")
public TableDataInfo getRiskBloodList(TRiskPressDropRate tRiskPressDropRate) {
startPage();
return getDataTable(tRiskPressDropRateService.getRiskBloodList(tRiskPressDropRate));
}
/**
* @return com.securityControl.common.core.web.domain.AjaxResult
* @Author roof
* @Description 风险压降率计算
* @Date 13:54 2022/4/28
* @Param [o]
*/
@ApiOperation(value = "风险压降率计算")
@PostMapping("/getRiskDropRate")
@Log(title = "压降率计算", menu = "压降率计算", businessType = BusinessType.QUERY, details = "风险压降率计算")
public AjaxResult getRiskDropRate(TRiskPressDropRate pressDropRate) {
return AjaxResult.success(tRiskPressDropRateService.getRiskDropRate(pressDropRate));
}
}