为WrapperUtils中的方法增加了防空处理;规范了代码
parent
f9804ef791
commit
fc99117637
|
@ -31,18 +31,6 @@ public class WebConfig implements WebMvcConfigurer {
|
||||||
.excludePathPatterns("/staff/login")
|
.excludePathPatterns("/staff/login")
|
||||||
.excludePathPatterns("/hello")
|
.excludePathPatterns("/hello")
|
||||||
.excludePathPatterns("/error")
|
.excludePathPatterns("/error")
|
||||||
.excludePathPatterns("/staff/timetest");
|
.excludePathPatterns("/swagger-ui/**");
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
@Override
|
|
||||||
public void addCorsMappings(CorsRegistry registry) {
|
|
||||||
registry.addMapping("/**")
|
|
||||||
.allowedOriginPatterns("*")
|
|
||||||
.allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
|
|
||||||
.allowedHeaders("token")
|
|
||||||
.allowCredentials(true)
|
|
||||||
.maxAge(3600)
|
|
||||||
.allowedHeaders("*");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
|
@ -1,17 +1,13 @@
|
||||||
package cn.edu.hfut.rmdjzz.projectmanagement.controller;
|
package cn.edu.hfut.rmdjzz.projectmanagement.controller;
|
||||||
|
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Project;
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Project;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectType;
|
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ResultProject;
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ResultProject;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectService;
|
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectService;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.impl.ProjectServiceImpl;
|
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.response.ResponseList;
|
import cn.edu.hfut.rmdjzz.projectmanagement.utils.response.ResponseList;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.response.ResponseMap;
|
import cn.edu.hfut.rmdjzz.projectmanagement.utils.response.ResponseMap;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -26,7 +22,7 @@ import java.util.Map;
|
||||||
public class ProjectController {
|
public class ProjectController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IProjectService projectServiceImpl;
|
private IProjectService projectService;
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@GetMapping
|
@GetMapping
|
||||||
|
@ -36,7 +32,7 @@ public class ProjectController {
|
||||||
@RequestParam("pageSize") Integer pageSize,
|
@RequestParam("pageSize") Integer pageSize,
|
||||||
Map<String, Object> paramMap
|
Map<String, Object> paramMap
|
||||||
) {
|
) {
|
||||||
Page<ResultProject> page = projectServiceImpl.getOnePageProject(token, pageCurrent, pageSize, paramMap);
|
Page<ResultProject> page = projectService.getOnePageProject(token, pageCurrent, pageSize, paramMap);
|
||||||
return ResponseList.ofSuccess("成功返回列表", page);
|
return ResponseList.ofSuccess("成功返回列表", page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,22 +40,34 @@ public class ProjectController {
|
||||||
@GetMapping("/total")
|
@GetMapping("/total")
|
||||||
public ResponseMap getProjectNumOfStaff(@RequestHeader("Token") String token) {
|
public ResponseMap getProjectNumOfStaff(@RequestHeader("Token") String token) {
|
||||||
Map<String, Long> res = new HashMap<>();
|
Map<String, Long> res = new HashMap<>();
|
||||||
res.put("totalNum", projectServiceImpl.getAllProjectOfStaff(token));
|
res.put("totalNum", projectService.getAllProjectOfStaff(token));
|
||||||
return ResponseMap.ofSuccess("获得参与项目总数", res);
|
return ResponseMap.ofSuccess("获得参与项目总数", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@PostMapping("/complete")
|
@PostMapping("/complete")
|
||||||
public ResponseMap completeProject(@RequestHeader("Token") String token,@RequestBody Map<String,Object> map){
|
public ResponseMap completeProject(@RequestHeader("Token") String token, @RequestBody Map<String, Object> map) {
|
||||||
Integer targetProjectId=(Integer)map.get("projectId");
|
Integer targetProjectId = (Integer) map.get("projectId");
|
||||||
projectServiceImpl.setProjectCompleted(token, targetProjectId);
|
projectService.setProjectCompleted(token, targetProjectId);
|
||||||
return ResponseMap.ofSuccess("操作成功");
|
return ResponseMap.ofSuccess("操作成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@PostMapping("/create")
|
@PostMapping
|
||||||
public ResponseMap createProject(@RequestHeader("Token") String token,@RequestBody Project project){
|
public ResponseMap createProject(@RequestHeader("Token") String token, @RequestBody Project project) {
|
||||||
projectServiceImpl.createProject(token, project);
|
projectService.createProject(token, project);
|
||||||
|
return ResponseMap.ofSuccess("操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@PutMapping("/{projectId}")
|
||||||
|
public ResponseMap updateProject(
|
||||||
|
@RequestHeader("Token") String token,
|
||||||
|
@PathVariable Integer projectId,
|
||||||
|
@RequestBody Project project
|
||||||
|
) {
|
||||||
|
project.setProjectId(projectId);
|
||||||
|
projectService.updateById(project);
|
||||||
return ResponseMap.ofSuccess("操作成功");
|
return ResponseMap.ofSuccess("操作成功");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package cn.edu.hfut.rmdjzz.projectmanagement.controller;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectType;
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectType;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectTypeService;
|
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectTypeService;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.response.ResponseList;
|
import cn.edu.hfut.rmdjzz.projectmanagement.utils.response.ResponseList;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.response.ResponseMap;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
@ -16,7 +15,7 @@ import java.util.List;
|
||||||
* @since 2022/6/30 16:36
|
* @since 2022/6/30 16:36
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/projectType")
|
@RequestMapping("/project/type")
|
||||||
public class ProjectTypeController {
|
public class ProjectTypeController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private IProjectTypeService projectTypeServiceImpl;
|
private IProjectTypeService projectTypeServiceImpl;
|
||||||
|
|
|
@ -2,14 +2,12 @@ package cn.edu.hfut.rmdjzz.projectmanagement.controller;
|
||||||
|
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Staff;
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Staff;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
|
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.impl.StaffServiceImpl;
|
import cn.edu.hfut.rmdjzz.projectmanagement.service.IStaffService;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.response.ResponseMap;
|
import cn.edu.hfut.rmdjzz.projectmanagement.utils.response.ResponseMap;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 张韬
|
* @author 张韬
|
||||||
* created at 2022/6/28 21:59
|
* created at 2022/6/28 21:59
|
||||||
|
@ -18,26 +16,21 @@ import java.time.LocalDateTime;
|
||||||
@RequestMapping("/staff")
|
@RequestMapping("/staff")
|
||||||
public class StaffController {
|
public class StaffController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private StaffServiceImpl staffServiceImpl;
|
private IStaffService staffService;
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
public ResponseMap login(@RequestBody Staff staff) {
|
public ResponseMap login(@RequestBody Staff staff) {
|
||||||
return staffServiceImpl.login(staff.getStaffUsername(), staff.getStaffPassword());
|
return staffService.login(staff.getStaffUsername(), staff.getStaffPassword());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@PostMapping("/logout")
|
@PostMapping("/logout")
|
||||||
public ResponseMap logout(@RequestHeader("Token") String token) {
|
public ResponseMap logout(@RequestHeader("Token") String token) {
|
||||||
if (staffServiceImpl.logout(token))
|
if (staffService.logout(token))
|
||||||
return ResponseMap.ofSuccess("操作成功");
|
return ResponseMap.ofSuccess("操作成功");
|
||||||
else {
|
else {
|
||||||
throw new TokenException("操作失败");
|
throw new TokenException("操作失败");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/timetest")
|
|
||||||
public LocalDateTime timeTest() {
|
|
||||||
return LocalDateTime.now();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,10 +35,11 @@ public class Project {
|
||||||
private String projectArea;
|
private String projectArea;
|
||||||
private String projectCompany;
|
private String projectCompany;
|
||||||
private String projectDescription;
|
private String projectDescription;
|
||||||
|
private BigDecimal projectManMonth;
|
||||||
@TableField("is_completed")
|
@TableField("is_completed")
|
||||||
private Boolean completed;
|
private Boolean completed;
|
||||||
@TableField("is_deleted")
|
@TableField("is_deleted")
|
||||||
@TableLogic
|
@TableLogic
|
||||||
private Boolean isDeleted;
|
private Boolean deleted;
|
||||||
private Integer projectCreator;
|
private Integer projectCreator;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
package cn.edu.hfut.rmdjzz.projectmanagement.entity;
|
package cn.edu.hfut.rmdjzz.projectmanagement.entity;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
@ -22,14 +19,15 @@ public class ResultProject {
|
||||||
String projectImportance;
|
String projectImportance;
|
||||||
String projectClassName;
|
String projectClassName;
|
||||||
String projectSubclassName;
|
String projectSubclassName;
|
||||||
Boolean IsDeleted;
|
Boolean deleted;
|
||||||
Boolean IsCompleted;
|
Boolean completed;
|
||||||
LocalDate projectCloseTime;
|
LocalDate projectCloseTime;
|
||||||
Integer CompleteNum;
|
Integer completeNum;
|
||||||
Integer TotalNum;
|
Integer totalNum;
|
||||||
|
|
||||||
ResultProject() {
|
ResultProject() {
|
||||||
CompleteNum = 50;
|
completeNum = 50;
|
||||||
TotalNum = 100;
|
totalNum = 100;
|
||||||
}
|
}
|
||||||
// 带加的进度 Double projectProcess;
|
// 带加的进度 Double projectProcess;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package cn.edu.hfut.rmdjzz.projectmanagement.mapper;
|
package cn.edu.hfut.rmdjzz.projectmanagement.mapper;
|
||||||
|
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Project;
|
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,10 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.apache.ibatis.annotations.*;
|
import org.apache.ibatis.annotations.Result;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.apache.ibatis.annotations.Results;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 阳勇权
|
* @author 阳勇权
|
||||||
|
@ -19,9 +18,9 @@ import java.util.List;
|
||||||
public interface ProjectMapper extends BaseMapper<Project> {
|
public interface ProjectMapper extends BaseMapper<Project> {
|
||||||
|
|
||||||
@Select("""
|
@Select("""
|
||||||
SELECT COUNT(*) FROM project WHERE project_id IN
|
SELECT COUNT(*) FROM project WHERE project_id IN
|
||||||
(SELECT DISTINCT project_id FROM project_group WHERE staff_id = #{id})
|
(SELECT DISTINCT project_id FROM project_group WHERE staff_id = #{id})
|
||||||
""")
|
""")
|
||||||
Long findProjectCount(@Param("id") Integer staffId);
|
Long findProjectCount(@Param("id") Integer staffId);
|
||||||
|
|
||||||
@Select("""
|
@Select("""
|
||||||
|
@ -49,8 +48,8 @@ public interface ProjectMapper extends BaseMapper<Project> {
|
||||||
@Result(column = "project_class_name", property = "projectClassName"),
|
@Result(column = "project_class_name", property = "projectClassName"),
|
||||||
@Result(column = "project_subclass_name", property = "projectSubclassName"),
|
@Result(column = "project_subclass_name", property = "projectSubclassName"),
|
||||||
@Result(column = "project_class_name", property = "projectClassName"),
|
@Result(column = "project_class_name", property = "projectClassName"),
|
||||||
@Result(column = "is_completed", property = "IsCompleted"),
|
@Result(column = "is_completed", property = "completed"),
|
||||||
@Result(column = "is_deleted", property = "IsDeleted"),
|
@Result(column = "is_deleted", property = "deleted"),
|
||||||
@Result(column = "project_close_time", property = "projectCloseTime"),
|
@Result(column = "project_close_time", property = "projectCloseTime"),
|
||||||
@Result(column = "project_creator", property = "projectCreator")
|
@Result(column = "project_creator", property = "projectCreator")
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package cn.edu.hfut.rmdjzz.projectmanagement.service;
|
package cn.edu.hfut.rmdjzz.projectmanagement.service;
|
||||||
|
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Project;
|
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
@ -8,7 +7,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
* @author 张韬
|
* @author 张韬
|
||||||
* created at 2022/6/30 21:36
|
* created at 2022/6/30 21:36
|
||||||
*/
|
*/
|
||||||
public interface IProjectGroupService extends IService<ProjectGroup>{
|
public interface IProjectGroupService extends IService<ProjectGroup> {
|
||||||
public Boolean addCreator(Integer projectId,Integer staffId);
|
Boolean addCreator(Integer projectId, Integer staffId);
|
||||||
|
|
||||||
}
|
}
|
|
@ -4,7 +4,6 @@ import cn.edu.hfut.rmdjzz.projectmanagement.entity.Project;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ResultProject;
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ResultProject;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
|
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
|
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
@ -18,9 +17,9 @@ public interface IProjectService extends IService<Project> {
|
||||||
|
|
||||||
Long getAllProjectOfStaff(String token) throws TokenException;
|
Long getAllProjectOfStaff(String token) throws TokenException;
|
||||||
|
|
||||||
Page<ResultProject> getOnePageProject(String token, Integer pageCurrent, Integer pageSize, Map<String,Object> params) throws TokenException;
|
Page<ResultProject> getOnePageProject(String token, Integer pageCurrent, Integer pageSize, Map<String, Object> params) throws TokenException;
|
||||||
|
|
||||||
Boolean setProjectCompleted(String token, Integer projectId) throws TokenException, BadRequestException;
|
Boolean setProjectCompleted(String token, Integer projectId) throws TokenException, BadRequestException;
|
||||||
|
|
||||||
Boolean createProject(String token,Project project) throws TokenException, BadRequestException;
|
Boolean createProject(String token, Project project) throws TokenException, BadRequestException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,10 @@ import org.springframework.stereotype.Service;
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, ProjectGroup> implements IProjectGroupService {
|
public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, ProjectGroup> implements IProjectGroupService {
|
||||||
public Boolean addCreator(Integer projectId,Integer staffId){
|
public Boolean addCreator(Integer projectId, Integer staffId) {
|
||||||
if(projectId==null||staffId==null)
|
if (projectId == null || staffId == null)
|
||||||
return false;
|
return false;
|
||||||
ProjectGroup projectGroup=new ProjectGroup();
|
ProjectGroup projectGroup = new ProjectGroup();
|
||||||
projectGroup.setProjectId(projectId);
|
projectGroup.setProjectId(projectId);
|
||||||
projectGroup.setStaffId(staffId);
|
projectGroup.setStaffId(staffId);
|
||||||
projectGroup.setProjectStaffPosition("负责人");
|
projectGroup.setProjectStaffPosition("负责人");
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package cn.edu.hfut.rmdjzz.projectmanagement.service.impl;
|
package cn.edu.hfut.rmdjzz.projectmanagement.service.impl;
|
||||||
|
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Project;
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Project;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
|
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ResultProject;
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ResultProject;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
|
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
|
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.ProjectMapper;
|
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.ProjectMapper;
|
||||||
|
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectService;
|
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectService;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
|
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.WrapperUtils;
|
import cn.edu.hfut.rmdjzz.projectmanagement.utils.WrapperUtils;
|
||||||
|
@ -13,10 +13,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import io.swagger.models.auth.In;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -29,7 +27,8 @@ import java.util.Objects;
|
||||||
@Service
|
@Service
|
||||||
public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> implements IProjectService {
|
public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> implements IProjectService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ProjectGroupServiceImpl projectGroupServiceImpl;
|
private IProjectGroupService projectGroupService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getAllProjectOfStaff(String token) throws TokenException {
|
public Long getAllProjectOfStaff(String token) throws TokenException {
|
||||||
Integer staffId = TokenUtils.getStaffId(token);
|
Integer staffId = TokenUtils.getStaffId(token);
|
||||||
|
@ -45,51 +44,51 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
||||||
) throws TokenException {
|
) throws TokenException {
|
||||||
Integer staffId = TokenUtils.getStaffId(token);
|
Integer staffId = TokenUtils.getStaffId(token);
|
||||||
IPage<ResultProject> page = new Page<>(pageCurrent, pageSize);
|
IPage<ResultProject> page = new Page<>(pageCurrent, pageSize);
|
||||||
IPage<ResultProject> userPage = baseMapper.findMyProject(page, staffId, WrapperUtils.allEqAndTimeIntervalQueryWrapper(params, false));
|
IPage<ResultProject> userPage = baseMapper.findMyProject(page, staffId, WrapperUtils.allEqAndTimeIntervalQueryWrapper(params));
|
||||||
return (Page<ResultProject>) userPage;
|
return (Page<ResultProject>) userPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean setProjectCompleted(String token, Integer projectId) throws TokenException, BadRequestException {
|
public Boolean setProjectCompleted(String token, Integer projectId) throws TokenException, BadRequestException {
|
||||||
Integer staffId = TokenUtils.getStaffId(token);
|
Integer staffId = TokenUtils.getStaffId(token);
|
||||||
Project project=new Project();
|
Project project = new Project();
|
||||||
project.setProjectId(projectId);
|
project.setProjectId(projectId);
|
||||||
Project targetProject = baseMapper.selectOne(Wrappers.<Project>lambdaQuery().eq(Project::getProjectId, project.getProjectId()));
|
Project targetProject = baseMapper.selectOne(Wrappers.<Project>lambdaQuery().eq(Project::getProjectId, project.getProjectId()));
|
||||||
if(targetProject==null)
|
if (targetProject == null)
|
||||||
throw new BadRequestException("项目不存在");
|
throw new BadRequestException("项目不存在");
|
||||||
if(!Objects.equals(staffId, targetProject.getProjectCreator()))
|
if (!Objects.equals(staffId, targetProject.getProjectCreator()))
|
||||||
throw new BadRequestException("用户请求非法");
|
throw new BadRequestException("用户请求非法");
|
||||||
if(targetProject.getIsCompleted())
|
if (targetProject.getCompleted())
|
||||||
throw new BadRequestException("该项目已结项");
|
throw new BadRequestException("该项目已结项");
|
||||||
targetProject.setIsCompleted(true);
|
targetProject.setCompleted(true);
|
||||||
targetProject.setProjectCloseTime(LocalDate.now());
|
targetProject.setProjectCloseTime(LocalDate.now());
|
||||||
if(baseMapper.updateById(targetProject)==1)
|
if (baseMapper.updateById(targetProject) == 1)
|
||||||
return true;
|
return true;
|
||||||
throw new BadRequestException("操作失败");
|
throw new BadRequestException("操作失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean createProject(String token,Project project) throws TokenException, BadRequestException {
|
public Boolean createProject(String token, Project project) throws TokenException, BadRequestException {
|
||||||
project.setProjectId(null);
|
project.setProjectId(null);
|
||||||
project.setIsCompleted(false);
|
project.setCompleted(false);
|
||||||
project.setProjectCreator(TokenUtils.getStaffId(token));
|
project.setProjectCreator(TokenUtils.getStaffId(token));
|
||||||
project.setProjectCloseTime(null);
|
project.setProjectCloseTime(null);
|
||||||
if(project.getExpectedCompletion()==null){
|
if (project.getExpectedCompletion() == null) {
|
||||||
project.setExpectedCompletion((short) 100);
|
project.setExpectedCompletion((short) 100);
|
||||||
}
|
} else if (project.getExpectedCompletion() < 0 || project.getExpectedCompletion() > 100 ||
|
||||||
else if(project.getExpectedCompletion()<0||project.getExpectedCompletion()>100||
|
project.getProjectStartTime() == null || project.getProjectEndTime() == null ||
|
||||||
project.getProjectStartTime()==null||project.getProjectEndTime()==null||
|
|
||||||
project.getProjectStartTime().isAfter(project.getProjectEndTime())
|
project.getProjectStartTime().isAfter(project.getProjectEndTime())
|
||||||
){
|
) {
|
||||||
throw new BadRequestException("参数错误");
|
throw new BadRequestException("参数错误");
|
||||||
}
|
}
|
||||||
try{
|
|
||||||
if(baseMapper.insert(project)==1){
|
try {
|
||||||
return projectGroupServiceImpl.addCreator(project.getProjectId(),TokenUtils.getStaffId(token));
|
if (baseMapper.insert(project) == 1) {
|
||||||
|
return projectGroupService.addCreator(project.getProjectId(), TokenUtils.getStaffId(token));
|
||||||
}
|
}
|
||||||
}catch(Exception e){
|
} catch (Exception e) {
|
||||||
System.out.println(e);
|
System.out.println(e);
|
||||||
throw new BadRequestException("新建失败");
|
throw new BadRequestException("新建失败");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
package cn.edu.hfut.rmdjzz.projectmanagement.service.impl;
|
package cn.edu.hfut.rmdjzz.projectmanagement.service.impl;
|
||||||
|
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Project;
|
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectType;
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectType;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.ProjectMapper;
|
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.ProjectTypeMapper;
|
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.ProjectTypeMapper;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectService;
|
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectTypeService;
|
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectTypeService;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
@ -17,7 +14,7 @@ import java.util.List;
|
||||||
* @since 2022/6/30 16:28
|
* @since 2022/6/30 16:28
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class ProjectTypeServiceImpl extends ServiceImpl<ProjectTypeMapper, ProjectType> implements IProjectTypeService {
|
public class ProjectTypeServiceImpl extends ServiceImpl<ProjectTypeMapper, ProjectType> implements IProjectTypeService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ProjectType> findAllProjectType() {
|
public List<ProjectType> findAllProjectType() {
|
||||||
|
|
|
@ -23,14 +23,17 @@ public class WrapperUtils {
|
||||||
* - 对于时间类({@link LocalDateTime}或{@link LocalDate}或{@link LocalTime}),
|
* - 对于时间类({@link LocalDateTime}或{@link LocalDate}或{@link LocalTime}),
|
||||||
* 会按照key的后缀处理,若为Start则处理为column >= value,End则处理为column <= value
|
* 会按照key的后缀处理,若为Start则处理为column >= value,End则处理为column <= value
|
||||||
*
|
*
|
||||||
* @param camel2Underline 若为真,则将key的小驼峰命名转为下划线命名风格
|
* @param camel2Underline 若为真,则将key的小驼峰命名转为下划线命名风格
|
||||||
* @param boolLeftAppendIs 若为真,则将value为boolean型的变量的key前添加IS
|
* @param boolLeftAppendIs 若为真,则将value为boolean型的变量的key前添加IS
|
||||||
* @param null2IsNull 若为真,将value为null的值在SQL中生成为IS NULL;否则值为null的参数不会在SQL中生成
|
* @param null2IsNull 若为真,将value为null的值在SQL中生成为IS NULL;否则值为null的参数不会在SQL中生成
|
||||||
*/
|
*/
|
||||||
public static <T> QueryWrapper<T> allEqAndTimeIntervalQueryWrapper(
|
public static <T> QueryWrapper<T> allEqAndTimeIntervalQueryWrapper(
|
||||||
Map<String, Object> paramMap, boolean camel2Underline, boolean boolLeftAppendIs, boolean null2IsNull
|
Map<String, Object> paramMap, boolean camel2Underline, boolean boolLeftAppendIs, boolean null2IsNull
|
||||||
) {
|
) {
|
||||||
QueryWrapper<T> wrapper = new QueryWrapper<>();
|
QueryWrapper<T> wrapper = new QueryWrapper<>();
|
||||||
|
if (paramMap == null || paramMap.isEmpty()) {
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
paramMap.forEach((key, value) -> {
|
paramMap.forEach((key, value) -> {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
if (null2IsNull) {
|
if (null2IsNull) {
|
||||||
|
|
|
@ -4,8 +4,10 @@ import cn.edu.hfut.rmdjzz.projectmanagement.entity.Project;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Staff;
|
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Staff;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectService;
|
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectService;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.IStaffService;
|
import cn.edu.hfut.rmdjzz.projectmanagement.service.IStaffService;
|
||||||
|
import cn.edu.hfut.rmdjzz.projectmanagement.service.impl.ProjectServiceImpl;
|
||||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.WrapperUtils;
|
import cn.edu.hfut.rmdjzz.projectmanagement.utils.WrapperUtils;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
|
@ -63,4 +65,11 @@ public class MybatisPlusTests {
|
||||||
List<Project> projects = projectService.list();
|
List<Project> projects = projectService.list();
|
||||||
System.out.println(objectMapper.writeValueAsString(projects));
|
System.out.println(objectMapper.writeValueAsString(projects));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@Test
|
||||||
|
public void resultProjectTest() {
|
||||||
|
System.out.println(objectMapper.writeValueAsString(((ProjectServiceImpl) projectService).getBaseMapper()
|
||||||
|
.findMyProject(new Page<>(1, 5), 1, Wrappers.query())));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue