实现了新建项目和相关的数据库类

master
白封羽 2022-06-30 21:48:36 +08:00
parent 0677f9a81d
commit fa5ddab6b4
8 changed files with 105 additions and 7 deletions

View File

@ -55,4 +55,11 @@ public class ProjectController {
projectServiceImpl.setProjectCompleted(token, targetProjectId); projectServiceImpl.setProjectCompleted(token, targetProjectId);
return ResponseMap.ofSuccess("操作成功"); return ResponseMap.ofSuccess("操作成功");
} }
@SneakyThrows
@PostMapping("/create")
public ResponseMap createProject(@RequestHeader("Token") String token,@RequestBody Project project){
projectServiceImpl.createProject(token, project);
return ResponseMap.ofSuccess("操作成功");
}
} }

View File

@ -5,8 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic; import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
import org.apache.poi.hpsf.Decimal;
import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
/** /**
@ -36,8 +36,8 @@ public class Project {
private String projectCompany; private String projectCompany;
private String projectDescription; private String projectDescription;
private Boolean IsCompleted; private Boolean IsCompleted;
private BigDecimal projectManMonth;
@TableLogic @TableLogic
private Boolean isDeleted; private Boolean isDeleted;
private Integer projectCreator; private Integer projectCreator;
private Decimal projectManMonth;
} }

View File

@ -0,0 +1,17 @@
package cn.edu.hfut.rmdjzz.projectmanagement.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
/**
* @author
* created at 2022/6/30 21:31
*/
@Data
public class ProjectGroup {
@TableId(type = IdType.AUTO)
Integer staffId;
Integer projectId;
String projectStaffPosition;
}

View File

@ -0,0 +1,13 @@
package cn.edu.hfut.rmdjzz.projectmanagement.mapper;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Project;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author
* created at 2022/6/30 21:34
*/
public interface ProjectGroupMapper extends BaseMapper<ProjectGroup> {
}

View File

@ -0,0 +1,14 @@
package cn.edu.hfut.rmdjzz.projectmanagement.service;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Project;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @author
* created at 2022/6/30 21:36
*/
public interface IProjectGroupService extends IService<ProjectGroup>{
public Boolean addCreator(Integer projectId,Integer staffId);
}

View File

@ -22,5 +22,5 @@ public interface IProjectService extends IService<Project> {
Boolean setProjectCompleted(String token, Integer projectId) throws TokenException, BadRequestException; Boolean setProjectCompleted(String token, Integer projectId) throws TokenException, BadRequestException;
Boolean makeANewProject(Project project) throws TokenException; Boolean createProject(String token,Project project) throws TokenException, BadRequestException;
} }

View File

@ -0,0 +1,24 @@
package cn.edu.hfut.rmdjzz.projectmanagement.service.impl;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectGroup;
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.ProjectGroupMapper;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* @author
* created at 2022/6/30 21:38
*/
@Service
public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, ProjectGroup> implements IProjectGroupService {
public Boolean addCreator(Integer projectId,Integer staffId){
if(projectId==null||staffId==null)
return false;
ProjectGroup projectGroup=new ProjectGroup();
projectGroup.setProjectId(projectId);
projectGroup.setStaffId(staffId);
projectGroup.setProjectStaffPosition("负责人");
return baseMapper.insert(projectGroup) == 1;
}
}

View File

@ -1,6 +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.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;
@ -13,6 +14,7 @@ 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 io.swagger.models.auth.In;
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 org.springframework.web.servlet.config.annotation.InterceptorRegistry;
@ -26,7 +28,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
private ProjectGroupServiceImpl projectGroupServiceImpl;
@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);
@ -66,8 +69,28 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
} }
@Override @Override
public Boolean makeANewProject(Project project) throws TokenException { public Boolean createProject(String token,Project project) throws TokenException, BadRequestException {
project.setProjectId(null);
return null; project.setIsCompleted(false);
project.setProjectCreator(TokenUtils.getStaffId(token));
project.setProjectCloseTime(null);
if(project.getExpectedCompletion()==null){
project.setExpectedCompletion((short) 100);
}
else if(project.getExpectedCompletion()<0||project.getExpectedCompletion()>100||
project.getProjectStartTime()==null||project.getProjectEndTime()==null||
project.getProjectStartTime().isAfter(project.getProjectEndTime())
){
throw new BadRequestException("参数错误");
}
try{
if(baseMapper.insert(project)==1){
return projectGroupServiceImpl.addCreator(project.getProjectId(),TokenUtils.getStaffId(token));
}
}catch(Exception e){
System.out.println(e);
throw new BadRequestException("新建失败");
}
return false;
} }
} }