提交 cb52746d authored 作者: 孙洁清's avatar 孙洁清

解决内存溢出

上级 4a40e206
......@@ -3,17 +3,14 @@ package com.zjty.inspect.controller;
import com.alibaba.fastjson.JSON;
import com.zjty.inspect.aop.AuthAnnotation;
import com.zjty.inspect.entity.*;
import com.zjty.inspect.service.EvaReportService;
import com.zjty.inspect.service.EvaluationService;
import com.zjty.inspect.utils.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
......@@ -22,7 +19,6 @@ import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author mcj
......@@ -32,9 +28,11 @@ import java.util.Set;
@Api(value = "评估报告管理接口", description = "评估报告管理接口,提供页面的增、删、改、查")
public class EvaluationController {
private final EvaluationService evaluationService;
private final EvaReportService evaReportService;
public EvaluationController(EvaluationService evaluationService) {
public EvaluationController(EvaluationService evaluationService, EvaReportService evaReportService) {
this.evaluationService = evaluationService;
this.evaReportService = evaReportService;
}
......@@ -145,9 +143,9 @@ public class EvaluationController {
@ApiImplicitParam(name = "size", value = "每页记录数", required = true, paramType = "path", dataType = "int")
})
@RequestMapping(value = "/search/{page}/{size}", method = RequestMethod.POST)
@AuthAnnotation(code = {"000800"})
public ServerResponse<PageResult<Evaluation>> findSearch(@RequestBody Map<String,String> searchMap, @PathVariable int page, @PathVariable int size) {
Page<Evaluation> pageList = evaluationService.findSearch(searchMap, page, size);
// @AuthAnnotation(code = {"000800"})
public ServerResponse<PageResult<EvaReport>> findSearch(@RequestBody Map<String,String> searchMap, @PathVariable int page, @PathVariable int size) {
Page<EvaReport> pageList = evaReportService.findSearch(searchMap, page, size);
return ServerResponse.ok(new PageResult<>(pageList.getTotalElements(), pageList.getContent()));
}
......
......@@ -11,6 +11,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
......@@ -38,6 +39,8 @@ public class InspectController {
private InspectService inspectService;
@Autowired
private EvaluationService evaluationService;
@Autowired
private EvaReportService evaReportService;
@Autowired
private TechnologyService technologyService;
......@@ -380,10 +383,17 @@ public class InspectController {
evaluation.setUsername(reform.getUsername());
evaluation.setProjectName(reform.getProjectName());
evaluation.setAuthority(reform.getAuthority());
evaluation.setDel(0);
Evaluation save = evaluationService.save(evaluation);
EvaReport evaReport=new EvaReport();
BeanUtils.copyProperties(save,evaReport);
evaReport.setEva_id(save.getId());
evaReportService.save(evaReport);
if(save==null){
return ServerResponse.badRequest();
}
return ServerResponse.ok(save.getId());
}
......
package com.zjty.inspect.dao;
import com.zjty.inspect.entity.EvaReport;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
public interface EvaReportDao extends JpaRepository<EvaReport,String>, JpaSpecificationExecutor<EvaReport> {
}
......@@ -11,4 +11,6 @@ public interface EvaluationDao extends JpaRepository<Evaluation,String>, JpaSpec
@Query(value = "SELECT * FROM evaluation WHERE username=:username AND create_time = (SELECT MAX(create_time) FROM evaluation WHERE username=:username)",nativeQuery = true)
Evaluation findByUsernameAndMaxCreateDate(String username);
}
package com.zjty.inspect.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
@Entity
@Table(name = "master_eva_report")
@NoArgsConstructor
@AllArgsConstructor
@Data
@ApiModel(description = "评估报告管理类")
public class EvaReport {
@Id
@Column( length = 48)
private String id;
private String username;
/**
* 0:用户
* 1: 管理员
*/
private Integer authority;
/**
* 1是删除
* 0正常
*/
private Integer del;
private String projectName;
/**
* 数据创建时间
*/
@Column(name="create_time",columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP",insertable = false,updatable = false)
@CreatedDate
private Date createDate;
/**
* 数据更新时间
*/
@Column(name="update_time",columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",insertable = false)
@LastModifiedDate
private Date updateDate;
private String eva_id;
}
......@@ -33,6 +33,11 @@ public class Evaluation {
* 1: 管理员
*/
private Integer authority;
/**
* 1是删除
* 0正常
*/
private Integer del;
private String projectName;
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@Column(columnDefinition = "TEXT")
......
package com.zjty.inspect.service;
import com.zjty.inspect.entity.EvaReport;
import com.zjty.inspect.entity.Evaluation;
import org.springframework.data.domain.Page;
import java.util.Map;
public interface EvaReportService {
Page<EvaReport> findSearch(Map<String,String> searchMap, int page, int size);
void save(EvaReport evaReport);
}
package com.zjty.inspect.service.impl;
import com.zjty.inspect.dao.EvaReportDao;
import com.zjty.inspect.entity.EvaReport;
import com.zjty.inspect.entity.Evaluation;
import com.zjty.inspect.service.EvaReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Service
public class EvaReportServiceImpl implements EvaReportService {
@Autowired
private EvaReportDao evaReportDao;
@Override
public Page<EvaReport> findSearch(Map<String, String> searchMap, int page, int size) {
Specification<EvaReport> specification = createSpecification(searchMap);
PageRequest pageRequest = PageRequest.of(page - 1, size, Sort.Direction.DESC, "createDate");
return evaReportDao.findAll(specification, pageRequest);
}
@Override
public void save(EvaReport evaReport) {
evaReportDao.save(evaReport);
}
private Specification<EvaReport> createSpecification(Map searchMap) {
return new Specification<EvaReport>() {
@Override
public Predicate toPredicate(Root<EvaReport> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicateList = new ArrayList<Predicate>();
if (searchMap.get("username") != null && !"".equals(searchMap.get("username"))) {
predicateList.add(cb.like(root.get("username").as(String.class), "%" + (String) searchMap.get("username") + "%"));
}
if (searchMap.get("projectName") != null && !"".equals(searchMap.get("projectName"))) {
predicateList.add(cb.like(root.get("projectName").as(String.class), "%" + (String) searchMap.get("projectName") + "%"));
}
cb.equal(root.get("del").as(Integer.class),0);
return cb.and(predicateList.toArray(new Predicate[predicateList.size()]));
}
};
}
}
package com.zjty.inspect.service.impl;
import com.zjty.inspect.dao.EvaReportDao;
import com.zjty.inspect.dao.EvaluationDao;
import com.zjty.inspect.entity.EvaReport;
import com.zjty.inspect.entity.Evaluation;
import com.zjty.inspect.service.EvaluationService;
import com.zjty.inspect.utils.UUIDUtil;
......@@ -28,6 +30,8 @@ import java.util.Optional;
@Service
@Transactional(rollbackFor = Exception.class)
public class EvaluationServiceImpl implements EvaluationService {
@Autowired
private EvaReportDao evaReportDao;
@Autowired
private EvaluationDao evaluationDao;
......@@ -69,7 +73,19 @@ public class EvaluationServiceImpl implements EvaluationService {
@Override
public void delete(String id) {
evaluationDao.deleteById(id);
Optional<Evaluation> optional = evaluationDao.findById(id);
Optional<EvaReport> byId = evaReportDao.findById(id);
if(optional.isPresent()){
Evaluation evaluation = optional.get();
evaluation.setDel(1);
evaluationDao.save(evaluation);
}
if(byId.isPresent()){
EvaReport evaReport = byId.get();
evaReport.setDel(1);
evaReportDao.save(evaReport);
}
}
@Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论