提交 f4b91a89 authored 作者: 马晨俊's avatar 马晨俊

mcj:代码结构优化,新增http异常处理

上级 b90b187d
package com.zjty.inspect.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
/**
* @author Mcj
* @date 2020-03-16 10:33
*/
@ControllerAdvice
@Slf4j
public class ExceptionHandlerConfig {
@ExceptionHandler(value = HttpMessageNotReadableException.class)
public ResponseEntity defaultErrorHandler(Exception e) {
log.error("异常{}",e);
return ResponseEntity.badRequest().build();
}
@ExceptionHandler(value = IOException.class)
public ResponseEntity defaultIOHandler(Exception e) {
log.error("IO异常{}",e);
return ResponseEntity.status(500).build();
}
}
...@@ -45,9 +45,6 @@ public class InspectController { ...@@ -45,9 +45,6 @@ public class InspectController {
@Autowired @Autowired
private TechnologyService technologyService; private TechnologyService technologyService;
@Autowired
private ParameterService parameterService;
@Autowired @Autowired
private ReportService reportService; private ReportService reportService;
...@@ -135,7 +132,7 @@ public class InspectController { ...@@ -135,7 +132,7 @@ public class InspectController {
} }
@PostMapping("/rapidAssessment") @PostMapping("/rapidAssessment")
public ResponseEntity rapidAssessment(@RequestBody Reform reform){ public ResponseEntity rapidAssessment(@RequestBody Reform reform) throws IOException {
//输入参数 //输入参数
String in = JSON.toJSONString(reform); String in = JSON.toJSONString(reform);
Evaluation evaluation=new Evaluation(); Evaluation evaluation=new Evaluation();
......
...@@ -35,7 +35,7 @@ public class InspectParameter { ...@@ -35,7 +35,7 @@ public class InspectParameter {
private Double proportion; private Double proportion;
/** /**
* 利率 * 利率
*/ */
private Double moneyRate; private Double moneyRate;
......
...@@ -13,30 +13,18 @@ public enum Language { ...@@ -13,30 +13,18 @@ public enum Language {
*/ */
JAVA("java",1), JAVA("java",1),
VUE("js",2),
PYTHON("python",3), PYTHON("python",3),
ASP("asp",4),
/**
* js
*/
JAVASCRIPT("js",5), JAVASCRIPT("js",5),
/**
* go
*/
GO("go",6), GO("go",6),
/**
* html
*/
HTML("html",7), HTML("html",7),
C("c#",8), C("c#",8),
C("c++",9), C("c++",9),
UNKNOW("unknowun",10); UNKNOW("unknowun",10);
...@@ -56,9 +44,4 @@ public enum Language { ...@@ -56,9 +44,4 @@ public enum Language {
public Integer getStatus() { public Integer getStatus() {
return status; return status;
} }
public static void main(String[] args) {
Language language = Language.valueOf("VUE");
System.out.println(language.name);
}
} }
...@@ -4,6 +4,7 @@ import com.zjty.inspect.entity.InspectParameter; ...@@ -4,6 +4,7 @@ import com.zjty.inspect.entity.InspectParameter;
import com.zjty.inspect.entity.Report; import com.zjty.inspect.entity.Report;
import com.zjty.inspect.entity.ReportVo; import com.zjty.inspect.entity.ReportVo;
import java.io.IOException;
import java.util.Map; import java.util.Map;
public interface InspectService { public interface InspectService {
...@@ -12,7 +13,7 @@ public interface InspectService { ...@@ -12,7 +13,7 @@ public interface InspectService {
* @param inspectParameter * @param inspectParameter
* @return * @return
*/ */
ReportVo inspect(ReportVo reportVo,InspectParameter inspectParameter); ReportVo inspect(ReportVo reportVo,InspectParameter inspectParameter) throws IOException;
String generateHtml(String templateContent, Map model ); String generateHtml(String templateContent, Map model );
......
...@@ -21,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -21,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -45,7 +46,7 @@ public class InspectServiceImpl implements InspectService { ...@@ -45,7 +46,7 @@ public class InspectServiceImpl implements InspectService {
@Transactional @Transactional
@Override @Override
public ReportVo inspect(ReportVo reportVo,InspectParameter inspectParameter) { public ReportVo inspect(ReportVo reportVo,InspectParameter inspectParameter) throws IOException {
//统计文件后缀数量 //统计文件后缀数量
Map<String, Language> suffixLanguageMapping = new HashMap<>(); Map<String, Language> suffixLanguageMapping = new HashMap<>();
suffixLanguageMapping.put("java", Language.JAVA); suffixLanguageMapping.put("java", Language.JAVA);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论