package com.moral.api.controller;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
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.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
import java.io.IOException;
|
import java.text.ParseException;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import com.moral.api.pojo.bo.ExcelBO;
|
import com.moral.api.pojo.vo.excel.ExcelVo;
|
import com.moral.api.pojo.vo.excel.HnExcelVo;
|
import com.moral.api.pojo.vo.excel.SyExcelVo;
|
import com.moral.api.service.ExcelService;
|
import com.moral.api.service.HnExcelService;
|
import com.moral.constant.ResponseCodeEnum;
|
import com.moral.constant.ResultMessage;
|
import com.moral.util.WebUtils;
|
|
@Slf4j
|
@RestController
|
@RequestMapping("/excel")
|
public class ExcelController {
|
|
@Autowired
|
private ExcelService excelService;
|
|
|
@Autowired
|
private HnExcelService hnExcelService;
|
|
/**
|
* 高新区导入
|
* @param request
|
* @return
|
* @throws IOException
|
*/
|
@PostMapping("excelImport")
|
public ResultMessage excelImport(HttpServletRequest request) throws IOException {
|
Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
|
if (!params.containsKey("time") || !params.containsKey("code") || params.containsKey("data")){
|
return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
|
}
|
List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("files");
|
ExcelBO excelBO = excelService.importTemplate(files, params);
|
return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),excelBO);
|
}
|
|
|
/**
|
* 高新区导出
|
* @param id
|
* @return
|
*/
|
@GetMapping("/excelExport")
|
public ResultMessage excelExport(Integer id){
|
if (id==null){
|
return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
|
}
|
ExcelVo export = excelService.export(id);
|
if (export==null){
|
return ResultMessage.fail(ResponseCodeEnum.TARGET_IS_NULL.getCode(), ResponseCodeEnum.TARGET_IS_NULL.getMsg());
|
}
|
|
return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),export);
|
}
|
|
/**
|
* 查询
|
* @param startTime
|
* @param code
|
* @param endTime
|
* @return
|
*/
|
@GetMapping("/selectExcel")
|
public ResultMessage selectExcel(String startTime,String code, String endTime){
|
if (startTime == null || code==null || endTime==null){
|
return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
|
}
|
List<ExcelBO> excelBOS = excelService.excelSelect(startTime, code, endTime);
|
if (excelBOS==null){
|
return ResultMessage.fail(ResponseCodeEnum.TARGET_IS_NULL.getCode(), ResponseCodeEnum.TARGET_IS_NULL.getMsg());
|
}
|
return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),excelBOS);
|
}
|
|
|
/**
|
* 浑南区模板导入
|
* @param request
|
* @return
|
* @throws IOException
|
*/
|
@PostMapping("syExcelImport")
|
public ResultMessage syExcelImport(HttpServletRequest request) throws IOException, ParseException {
|
Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
|
if (!params.containsKey("time") || !params.containsKey("code") || params.containsKey("data")){
|
return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
|
}
|
List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("files");
|
ExcelBO excelImport = hnExcelService.getExcelImport(files, params);
|
return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),excelImport);
|
}
|
|
/**
|
* 浑南区导出
|
* @param id
|
* @return
|
*/
|
@GetMapping("/syExcelExport")
|
public ResultMessage syExcelExport(Integer id){
|
if (id==null){
|
return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
|
}
|
|
SyExcelVo syExcelVo = hnExcelService.SyExport(id);
|
if (syExcelVo==null){
|
return ResultMessage.fail(ResponseCodeEnum.TARGET_IS_NULL.getCode(), ResponseCodeEnum.TARGET_IS_NULL.getMsg());
|
}
|
return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),syExcelVo);
|
}
|
|
|
/**
|
* 浑南区质量报告导出
|
* @param id
|
* @return
|
*/
|
@GetMapping("/hnExcelExport")
|
public ResultMessage hnExcelExport(Integer id) throws ParseException {
|
if (id==null){
|
return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
|
}
|
|
HnExcelVo hnExcelVo = hnExcelService.hnExport(id);
|
if (hnExcelVo==null){
|
return ResultMessage.fail(ResponseCodeEnum.TARGET_IS_NULL.getCode(), ResponseCodeEnum.TARGET_IS_NULL.getMsg());
|
}
|
return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),hnExcelVo);
|
}
|
|
|
}
|