You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1064 lines
43 KiB

5 years ago
package com.yipin.liuwanr.service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yipin.liuwanr.entity.*;
4 years ago
import com.yipin.liuwanr.helper.UserUtil;
import com.yipin.liuwanr.mapper.ProjectManagementMapper;
import com.yipin.liuwanr.mapper.ScoreIndexMapper;
5 years ago
import org.apache.commons.lang3.StringUtils;
import org.jboss.logging.Logger;
import org.springframework.beans.BeanUtils;
5 years ago
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
4 years ago
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
5 years ago
@Service
public class ProjectManagementService {
5 years ago
private static Logger logger = Logger.getLogger(ProjectManagementService.class);
5 years ago
@Autowired
private ProjectManagementMapper mapper;
5 years ago
@Autowired
private ScoreIndexMapper indexMapper;
/**
* 查询用户角色
*
* @param userId
* @return
*/
public HashMap<String, Object> queryRole(Integer userId) {
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
Integer roleId = mapper.queryRoleId(userId);
if (null != roleId) {
//角色为教师
if (roleId == 3) {
resp.put("retvalue", 1);
}
//角色为管理员
else if (roleId == 1 || roleId == 2) {
resp.put("retvalue", 0);
} else if (roleId == 4) {
resp.put("retcode", 300);
resp.put("retvalue", "Role does not meet the requirements");
return resp;
}
resp.put("retcode", 200);
} else {
resp.put("retcode", 300);
resp.put("retvalue", "user does not exist");
}
} catch (Exception e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "Inquiry Failed");
return resp;
}
return resp;
}
/**
* 条件查询
5 years ago
*
* @param vo
* @return
*/
public HashMap<String, Object> queryManagements(ProjectManagement vo, Integer pageNo, Integer pageSize) {
5 years ago
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
4 years ago
//获取用户的角色信息
Integer roleId = mapper.queryRoleId(vo.getUserId());
if (null != roleId) {
//角色不对(学生没有权限)
if (roleId == 4) {
resp.put("retcode", 300);
resp.put("retvalue", "抱歉,您的权限不能访问该地址!");
return resp;
}
//角色等于管理员或者超级管理员
else if (roleId == 1 ) {
vo.setUserId(null);
}
}
5 years ago
PageHelper.startPage(pageNo, pageSize);
//条件查询
4 years ago
List<ProjectManagement> list = mapper.queryManagementsExportTest(vo);
PageInfo<ProjectManagement> info = new PageInfo<ProjectManagement>(list);
5 years ago
resp.put("retvalue", new PageResult(info.getTotal(), list));
resp.put("retcode", 200);
} catch (Exception e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "Inquiry Failed");
return resp;
}
return resp;
}
/**
* 分页查询+条件查询
*
* @param vo
* @return
*/
public HashMap<String, Object> queryAllManagements(ProjectManagement vo) {
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
//获取用户的角色信息
4 years ago
Integer roleId = mapper.queryRoleId(vo.getUserId());
if (null != roleId) {
//角色不对(学生没有权限)
if (roleId == 4) {
resp.put("retcode", 300);
resp.put("retvalue", "抱歉,您的权限不能访问该地址!");
return resp;
}
//角色等于管理员或者超级管理员
else if (roleId == 1 ) {
vo.setUserId(null);
}
}
//分页
PageHelper.startPage(vo.getPageNo(), vo.getPageSize());
//条件查询
List<ProjectManagement> list = mapper.queryManagements(vo);
//管理员权限id
String adminId = "13";
if (adminId.equals(vo.getFounder())){
//查完管理员,再查管理员+教师权限的 13,14
ProjectManagement vo1 = new ProjectManagement();
BeanUtils.copyProperties(vo,vo1);
vo1.setFounder("13,14");
List<ProjectManagement> list1 = mapper.queryManagements(vo1);
list.addAll(list1);
}
resp.put("retvalue",list);
resp.put("retcode", 200);
} catch (Exception e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "Inquiry Failed");
return resp;
}
return resp;
}
5 years ago
/**
* 批量删除
*
* @param projectId项目管理id
5 years ago
* @return
*/
@Transactional
public HashMap<String, Object> deleteProjectManagement(List<Integer> projectId) {
5 years ago
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
for (Integer po : projectId) {
5 years ago
//判分点
4 years ago
List<JudgmentPoints> points = mapper.queryProjectIds(po);
5 years ago
for (int i = 0; i < points.size(); i++) {
//判分点
4 years ago
JudgmentPoints pos = points.get(i);
5 years ago
Integer pointId = pos.getJudgmentPointsId();//判分点id
String projectIds = pos.getProjectId();//项目id
//判分点中删除项目
if (!StringUtils.isEmpty(projectIds)) {
List<String> lists = Arrays.asList(projectIds.split(","));
List<String> obj = new ArrayList<String>(lists);
String prijectId = po.toString();
if (lists.contains(prijectId)) {
obj.remove(prijectId);
projectIds = StringUtils.strip(obj.toString(), "[]").replace(" ", "");
mapper.updateProject(projectIds, null, pointId);
}
}
}
//删除分数
indexMapper.removeAllprojectId(po);
mapper.deleteRole(po);
}
int size = projectId.size();
for (int i = 0;i<size;i++){
Integer id = projectId.get(i);
List<Integer> result = mapper.queryproject(id);
if (result.size()==0){
mapper.daleteManegement(id);
}
mapper.deleteProjectManagement(id);
}
5 years ago
resp.put("retcode", 200);
} catch (Exception e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "Delete Failed");
throw new RuntimeException();
}
return resp;
}
/**
* 根据项目管理id查询对应信息
*
* @param projectId
* @return
*/
public HashMap<String, Object> getProjectId(Integer projectId) {
HashMap<String, Object> resp = new HashMap<String, Object>();
List<Integer> judgmentPointsId = new ArrayList<Integer>();
List<Object> obj = new ArrayList<Object>();
List<Integer> indexs = new ArrayList<Integer>();
try {
// 项目信息
ProjectManagement management = mapper.getProjectId(projectId);
5 years ago
if (null != management) {
// 判分点信息
4 years ago
List<JudgmentPoints> points = mapper.getByProjectId(projectId);
5 years ago
//判分点不为空
if (null != points && !points.isEmpty()) {
//存储判分点id
for (int i = 0; i < points.size(); i++) {
judgmentPointsId.add(points.get(i).getJudgmentPointsId());
}
//得到对应判分点的分数
List<ScoreIndex> scores = indexMapper.queryScore(judgmentPointsId, projectId, management.getUserId());
if (scores.size() > 0 && !scores.isEmpty()) {
//为有分数的赋值
for (int i = 0; i < points.size(); i++) {
4 years ago
JudgmentPoints point = points.get(i);
5 years ago
for (int j = 0; j < scores.size(); j++) {
ScoreIndex score = scores.get(j);
if (point.getJudgmentPointsId().equals(score.getJudgmentPointsId())) {
point.setScore(score.getScore());
points.set(i, point);
indexs.add(i);
break;
}
}
}
//为没值的赋值
for (int i = 0; i < points.size(); i++) {
if (!indexs.contains(i)) {
4 years ago
JudgmentPoints points3 = points.get(i);
5 years ago
points3.setScore(0);
points.set(i, points3);
}
}
} else {
for (int i = 0; i < points.size(); i++) {
4 years ago
JudgmentPoints point = points.get(i);
5 years ago
//给分数赋值
point.setScore(0);
//修改该判分点
points.set(i, point);
}
}
}
// 角色信息
List<Role> roles = mapper.queryProjectId(projectId);
// 存数据
obj.add(management);
obj.add(points);
obj.add(roles);
}
resp.put("retvalue", obj);
resp.put("retcode", 200);
} catch (Exception e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "Inquiry Failed");
return resp;
}
return resp;
}
4 years ago
/**
* 根据项目管理id查询对应交易类判分点信息
*
* @param projectId
* @return
*/
public HashMap<String, Object> getTrdingJudgmentPoints(Integer projectId) {
HashMap<String, Object> resp = new HashMap<String, Object>();
List<Object> obj = new ArrayList<Object>();
try {
// 项目信息
ProjectManagement management = mapper.getProjectId(projectId);
if (null != management) {
// 判分点信息
List<JudgmentPoints> points = mapper.queryJudgmentPoints(projectId);
// 角色信息
List<Role> roles = mapper.queryProjectId(projectId);
// 存数据
obj.add(management);
obj.add(points);
obj.add(roles);
}
resp.put("retvalue", obj);
resp.put("retcode", 200);
} catch (Exception e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "Inquiry Failed");
return resp;
}
return resp;
}
/**
* 根据项目管理id查询对应交易类判分点信息
*
* @param projectId
* @return
*/
public HashMap<String, Object> getProject(Integer projectId) {
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
// 项目信息
ProjectManagement management = mapper.getProjectId(projectId);
resp.put("retvalue", management);
resp.put("retcode", 200);
} catch (Exception e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "Inquiry Failed");
return resp;
}
return resp;
}
5 years ago
/**
* 添加判分点页面的判分点信息展示
*
* @return
*/
4 years ago
public HashMap<String, Object> queryAllJudgmentPoints(JudgmentPoints points) {
5 years ago
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
resp.put("retvalue", mapper.queryAllJudgmentPoints(points));
resp.put("retcode", 200);
} catch (Exception e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "Add Failed");
return resp;
}
return resp;
}
/**
* 创建项目管理页面的判分点信息展示
*
* @param judgmentPointsId 判分点id
* @return
*/
public HashMap<String, Object> getByjudgmentPointsId(List<Integer> judgmentPointsId, Integer projectId, Integer userId) {
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
4 years ago
List<JudgmentPoints> points = mapper.getByjudgmentPointsIds(judgmentPointsId);
5 years ago
List<ScoreIndex> scores = indexMapper.queryScore(judgmentPointsId, projectId, userId);
List<Integer> indexs = new ArrayList<Integer>();
//为新增项目时勾选判分点赋值
if (scores.size() <= 0) {
for (int i = 0; i < points.size(); i++) {
4 years ago
JudgmentPoints points2 = points.get(i);
5 years ago
points2.setScore(0);
points.set(i, points2);
}
}
//为修改项目时勾选判分点赋值
else {
//为有分数的赋值
for (int i = 0; i < points.size(); i++) {
4 years ago
JudgmentPoints point = points.get(i);
5 years ago
for (int j = 0; j < scores.size(); j++) {
ScoreIndex score = scores.get(j);
if (point.getJudgmentPointsId().equals(score.getJudgmentPointsId())) {
point.setScore(score.getScore());
points.set(i, point);
indexs.add(i);
break;
}
}
}
//为没值的赋值
for (int i = 0; i < points.size(); i++) {
if (!indexs.contains(i)) {
4 years ago
JudgmentPoints points3 = points.get(i);
5 years ago
points3.setScore(0);
points.set(i, points3);
}
}
}
resp.put("retvalue", points);
resp.put("retcode", 200);
} catch (Exception e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "Inquiry Failed");
return resp;
}
return resp;
}
/**
* 平均分配分值
*
* @param number
* @return
*/
public HashMap<String, Object> avgValues(Integer number) {
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
resp.put("retvalue", UserUtil.averageValue(number));
resp.put("retcode", 200);
} catch (Exception e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "Calculation ERROR");
return resp;
}
return resp;
}
/**
* 查询单个项目判分点信息根据项目id
*
* @param projectId 项目id
* @return
*/
public HashMap<String, Object> getJudgmentPoints(Integer projectId) {
HashMap<String, Object> resp = new HashMap<String, Object>();
4 years ago
HashMap<String, Object> obj = new HashMap<String, Object>();
HashMap<String, Object> score = new HashMap<String, Object>();
List<ScoreIndex> scoreIndexList = null;
try {
//根据projectId查询判分点交易类型
List<TradingJudgmentPoints> judgmentPointsList = mapper.getJudgmentPoints(projectId);
Integer size = judgmentPointsList.size();
for (int i = 0; i<size; i++){
TradingJudgmentPoints tradingJudgmentPoints = judgmentPointsList.get(i);
Integer judgmentPointsId = tradingJudgmentPoints.getId();
Integer systemId = tradingJudgmentPoints.getSystemId();
scoreIndexList = mapper.getScore(judgmentPointsId,systemId,projectId);
score.put("scoreIndexList"+i,scoreIndexList);
4 years ago
}
List<Role> roleList = mapper.queryProjectId(projectId);
obj.put("roleList",roleList);
obj.put("judgmentPointsList", judgmentPointsList);
obj.put("scoreIndexList", score);
resp.put("retvalue", obj);
resp.put("retcode", 200);
} catch (Exception e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "Inquiry Failed");
return resp;
}
return resp;
}
/**
* 查询职站单个项目判分点信息根据项目id
*
* @param projectId 项目id
* @return
*/
public HashMap<String, Object> getZZJudgmentPoints(Integer projectId) {
HashMap<String, Object> resp = new HashMap<String, Object>();
HashMap<String, Object> obj = new HashMap<String, Object>();
HashMap<String, Object> score = new HashMap<String, Object>();
List<ScoreIndex> scoreIndexList = null;
try {
List<JudgmentPoints> judgmentPointsList = mapper.getZZJudgmentPoints(projectId);
Integer size = judgmentPointsList.size();
for (int i = 0; i<size; i++){
JudgmentPoints judgmentPoints = judgmentPointsList.get(i);
Integer judgmentPointsId = judgmentPoints.getJudgmentPointsId();
Integer systemId = judgmentPoints.getSystemId();
scoreIndexList = mapper.getScore(judgmentPointsId,systemId,projectId);
score.put("scoreIndexList"+i,scoreIndexList);
}
List<Role> roleList = mapper.queryProjectId(projectId);
obj.put("roleList",roleList);
obj.put("judgmentPointsList", judgmentPointsList);
4 years ago
obj.put("scoreIndexList", score);
4 years ago
resp.put("retvalue", obj);
resp.put("retcode", 200);
} catch (Exception e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "Inquiry Failed");
return resp;
}
return resp;
}
/**
* 查询单个项目判分点信息
5 years ago
*
* @param roleId 角色ID
* @return
*/
public HashMap<String, Object> getByRoleId(List<Integer> roleId) {
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
resp.put("retvalue", mapper.getByRoleId(roleId));
resp.put("retcode", 200);
} catch (Exception e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "Inquiry Failed");
return resp;
}
return resp;
}
/**
* 修改角色信息
*
* @param role 角色信息
* @return
*/
public HashMap<String, Object> updateRole(Role role) {
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
mapper.updateRole(role);
resp.put("retcode", 200);
} catch (Exception e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "UPDATE ERROR");
return resp;
}
return resp;
}
/**
* 添加角色信息
*
* @param role 角色信息
* @return
*/
public HashMap<String, Object> insertRole(Role role) {
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
mapper.insertRole(role);
Integer roleId = role.getRoleId();
resp.put("retvalue", roleId);
resp.put("retcode", 200);
} catch (Exception e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "Add Failed");
return resp;
}
return resp;
}
/**
* 添加项目管理信息
*
* @return
*/
@Transactional
4 years ago
public HashMap<String, Object> newAddProjectManagement(ProjectManagement pro, List<JudgmentPoints> points, List<Integer> roles) {
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
// 添加项目信息
mapper.insertProjectManagement(pro);
// 取出添加的项目信息的id
Integer projectId = pro.getProjectId();
for (int i = 0; i < points.size(); i++) {
//拼接判分点中的项目id
StringBuffer buff = new StringBuffer();
//判分点id
Integer pointId = points.get(i).getJudgmentPointsId();
//根据该判分点得到数据库存储的对应数据
JudgmentPoints point = mapper.newGetProjectId(pointId);
//取出绑定的项目id
String projectIds = point.getProjectId();
//取出实验要求
String experimentalRequirements = point.getExperimentalRequirements();
//数据库中该判分点已绑定过别的项目id,并且该判分点没有绑定过此时前端传来的项目id
if (!StringUtils.isEmpty(projectIds)) {
List<String> lists = Arrays.asList(projectIds.split(","));
if (!lists.contains(projectId.toString())) {
buff.append(projectIds);
buff.append(",");
buff.append(projectId);
}
}
//数据库中该判分点未绑定任何项目id
else if (projectIds == null) {
buff.append(projectId);
}
//数据中实验要求不为空,且数据库中的实验要求与前端传来的实验要求信息一致
if (experimentalRequirements != null && !experimentalRequirements.equals("")
&& experimentalRequirements.equals(points.get(i).getExperimentalRequirements())) {
mapper.updateTradingJudgmentPoints(new String(buff), pointId);
}
//数据库中的实验要求与前端传来的实验要求信息不一致
else if (!experimentalRequirements.equals(points.get(i).getExperimentalRequirements())) {
mapper.updateTradingJudgmentPoints(new String(buff), pointId);
}
// 得到判分指标信息
ScoreIndex scoreIndex = new ScoreIndex(points.get(i).getScore(), pointId, projectId, pro.getUserId(),pro.getSystemId());
// 在判分指标中添加对应信息
indexMapper.addScoreIndex(scoreIndex);
}
// 修改角色信息中的项目管理id
if (roles != null && roles.size() > 0) {
Integer size = roles.size();
for (int i = 0; i<size; i++){
Integer roleId = roles.get(i);
mapper.updateRoleProjectId(roleId, projectId);
}
}
resp.put("retcode", 200);
} catch (RuntimeException e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "Add Failed");
System.out.println(e.getMessage());
throw new RuntimeException();
}
return resp;
}
/**
* 添加项目管理信息
*
* @return
*/
@Transactional
public HashMap<String, Object> insertProjectManagement(ProjectManagement pro, List<JudgmentPoints> points, List<Integer> roles) {
5 years ago
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
// 添加项目信息
mapper.insertProjectManagement(pro);
// 取出添加的项目信息的id
Integer projectId = pro.getProjectId();
for (int i = 0; i < points.size(); i++) {
//拼接判分点中的项目id
StringBuffer buff = new StringBuffer();
//判分点id
Integer pointId = points.get(i).getJudgmentPointsId();
//根据该判分点得到数据库存储的对应数据
JudgmentPoints point = mapper.getByjudgmentPointsId(pointId);
//JudgmentPoints point = mapper.newGetProjectId(pointId);
5 years ago
//取出绑定的项目id
String projectIds = point.getProjectId();
//取出实验要求
String experimentalRequirements = point.getExperimentalRequirements();
//数据库中该判分点已绑定过别的项目id,并且该判分点没有绑定过此时前端传来的项目id
if (!StringUtils.isEmpty(projectIds)) {
List<String> lists = Arrays.asList(projectIds.split(","));
if (!lists.contains(projectId.toString())) {
buff.append(projectIds);
buff.append(",");
buff.append(projectId);
}
}
//数据库中该判分点未绑定任何项目id
else if (projectIds == null) {
buff.append(projectId);
}
//数据中实验要求不为空,且数据库中的实验要求与前端传来的实验要求信息一致
if (experimentalRequirements != null && !experimentalRequirements.equals("")
&& experimentalRequirements.equals(points.get(i).getExperimentalRequirements())) {
mapper.updateProject(new String(buff), null, pointId);
}
//数据库中的实验要求与前端传来的实验要求信息不一致
else if (!experimentalRequirements.equals(points.get(i).getExperimentalRequirements())) {
mapper.updateProject(new String(buff), points.get(i).getExperimentalRequirements(), pointId);
}
// 得到判分指标信息
4 years ago
ScoreIndex scoreIndex = new ScoreIndex(points.get(i).getScore(), pointId, projectId, pro.getUserId(),pro.getSystemId());
5 years ago
// 在判分指标中添加对应信息
indexMapper.addScoreIndex(scoreIndex);
}
// 修改角色信息中的项目管理id
if (roles != null && roles.size() > 0) {
4 years ago
Integer size = roles.size();
for (int i = 0; i<size; i++){
Integer roleId = roles.get(i);
mapper.updateRoleProjectId(roleId, projectId);
}
5 years ago
}
resp.put("retcode", 200);
} catch (RuntimeException e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "Add Failed");
5 years ago
System.out.println(e.getMessage());
5 years ago
throw new RuntimeException();
}
return resp;
}
public HashMap<String, Object> getByName(String projectName){
HashMap<String, Object> resp = new HashMap<String, Object>();
try{
Integer count = mapper.getByprojectName(projectName);
if(count>=1){
4 years ago
resp.put("retcode", 300);
resp.put("retvalue", "该项目名称已存在");
}else{
resp.put("retcode", 200);
}
}catch (RuntimeException e){
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "QUERY Failed");
throw new RuntimeException();
}
return resp;
}
5 years ago
/**
* 修改项目管理信息
*
* @return
*/
@Transactional
4 years ago
public HashMap<String, Object> updateProjectManagement(ProjectManagement pro, List<JudgmentPoints> points,
List<Integer> roles) {
5 years ago
HashMap<String, Object> resp = new HashMap<String, Object>();
//项目id
Integer project = pro.getProjectId();
//用户id
Integer userId = pro.getUserId();
try {
// 取出该项目对应的判分点id
List<Integer> judgments = mapper.getByPointProjectId(project);
// 取出该项目对应的角色id
List<Integer> rolesIds = mapper.getByRoleProjectId(project);
for (int i = 0; i < points.size(); i++) {
//拼接判分点中的项目id
StringBuffer buff = new StringBuffer();
//前端传来的判分点id
Integer pointId = points.get(i).getJudgmentPointsId();
//前端传来的实验要求
String experimentalRequirements1 = points.get(i).getExperimentalRequirements();
//前端传来的分数
Integer score1 = points.get(i).getScore();
4 years ago
Integer systemId = pro.getSystemId();
5 years ago
//判分点信息
4 years ago
JudgmentPoints point = mapper.getByjudgmentPointsId(pointId);
5 years ago
String projectIds = point.getProjectId();
String experimentalRequirements2 = point.getExperimentalRequirements();
// 如果数据库中有,则取出分数,进行比较
if (judgments.contains(pointId)) {
//分数
Integer score2 = indexMapper.getbyJudgmentPointsIdScore(pointId, project, userId);
// 如果分数不一致,则修改分数表中的分数
if (score2 != null && score1 != score2) {
4 years ago
indexMapper.updateScore(new ScoreIndex(score1, pointId, project, userId,systemId));
5 years ago
}
// 如果数据库中该判分点分数为空,则添加分数
else if (score2 == null) {
4 years ago
indexMapper.addScoreIndex(new ScoreIndex(score1, pointId, project, pro.getUserId(),systemId));
5 years ago
}
//如果前端传来的实验要求与数据库中不一致,则修改数据库中的判分点信息
if (!experimentalRequirements2.equals(experimentalRequirements1)) {
mapper.updateProject(point.getProjectId(), experimentalRequirements1, pointId);
}
} else {
//数据库中该判分点已绑定过别的项目id,并且该判分点没有绑定过此时前端传来的项目id
if (!StringUtils.isEmpty(projectIds)) {
List<String> lists = Arrays.asList(projectIds.split(","));
if (!lists.contains(project.toString())) {
buff.append(projectIds);
buff.append(",");
buff.append(project);
}
}
//数据库中该判分点未绑定任何项目id
else if (StringUtils.isEmpty(projectIds)) {
5 years ago
buff.append(project);
}
//数据中实验要求不为空,且数据库中的实验要求与前端传来的实验要求信息一致
if (experimentalRequirements2 != null && !experimentalRequirements2.equals("")
&& experimentalRequirements2.equals(experimentalRequirements1)) {
mapper.updateProject(new String(buff), null, pointId);
}
//数据库中的实验要求与前端传来的实验要求信息不一致
else if (!experimentalRequirements2.equals(experimentalRequirements1)) {
mapper.updateProject(new String(buff), experimentalRequirements1, pointId);
}
// 添加分数
4 years ago
indexMapper.addScoreIndex(new ScoreIndex(score1, pointId, project, pro.getUserId(),systemId));
}
judgments.remove(pointId);
}
// 从判分点id中删除该项目的id
for (int i = 0; i < judgments.size(); i++) {
Integer judgmentPointsId = judgments.get(i);
JudgmentPoints point = mapper.getByjudgmentPointsId(judgmentPointsId);
String projectIds = point.getProjectId();
// 删除分数表中对应的判分点id+项目id数据
indexMapper.removeScore(judgmentPointsId, project, userId);
// 对取出的数据,删除该项目的id
List<String> str3 = Arrays.asList(projectIds.split(","));
if (str3.contains(project.toString())) {
List<String> arrayList = new ArrayList<String>(str3);
arrayList.remove(project.toString());
// 删除字符中项目id
projectIds = StringUtils.strip(arrayList.toString(), "[]").replace(" ", "");
// 修改判分点中的项目id
mapper.updateProject(projectIds, null, judgments.get(i));
}
}
// 用来存储需要修改的角色id
List<Integer> roleid = new ArrayList<Integer>();
// 遍历前端传来的新的角色id
for (int i = 0; i < roles.size(); i++) {
// 如果前端传来的数据,在数据库中没有,则存起来
if (!rolesIds.contains(roles.get(i))) {
roleid.add(roles.get(i));
}
}
if (roles != null && roles.size() > 0) {
Integer size = roles.size();
for (int i = 0; i<size; i++){
Integer roleId = roles.get(i);
mapper.updateRoleProjectId(roleId, project);
}
}
//修改项目信息
mapper.updateProjectManagement(pro);
resp.put("retcode", 200);
} catch (RuntimeException e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "Update Failed");
throw new RuntimeException();
}
return resp;
}
/**
* 新修改修改项目管理信息
*
* @return
*/
@Transactional
public HashMap<String, Object> newUpdateProjectManagement(ProjectManagement pro, List<JudgmentPoints> points,
List<Integer> roles) {
HashMap<String, Object> resp = new HashMap<String, Object>();
//项目id
Integer project = pro.getProjectId();
// int del = mapper.delete(project);
//用户id
Integer userId = pro.getUserId();
try {
//删除项目原本绑定的判分点
int del = mapper.delete(project);
// 取出该项目对应的判分点id
List<Integer> judgments = mapper.getByPointProjectId(project);
// 取出该项目对应的角色id
List<Integer> rolesIds = mapper.getByRoleProjectId(project);
for (int i = 0; i < points.size(); i++) {
//拼接判分点中的项目id
StringBuffer buff = new StringBuffer();
//前端传来的判分点id
Integer pointId = points.get(i).getJudgmentPointsId();
//前端传来的实验要求
String experimentalRequirements1 = points.get(i).getExperimentalRequirements();
//前端传来的分数
Integer score1 = points.get(i).getScore();
Integer systemId = pro.getSystemId();
//判分点信息
JudgmentPoints point = mapper.getNewByjudgmentPointsId(pointId);
String projectIds = point.getProjectId();
String experimentalRequirements2 = point.getExperimentalRequirements();
// 如果数据库中有,则取出分数,进行比较
if (judgments.contains(pointId)) {
//分数
Integer score2 = indexMapper.getbyJudgmentPointsIdScore(pointId, project, userId);
// 如果分数不一致,则修改分数表中的分数
if (score2 != null && score1 != score2) {
indexMapper.updateScore(new ScoreIndex(score1, pointId, project, userId,systemId));
}
// 如果数据库中该判分点分数为空,则添加分数
else if (score2 == null) {
indexMapper.addScoreIndex(new ScoreIndex(score1, pointId, project, pro.getUserId(),systemId));
}
//如果前端传来的实验要求与数据库中不一致,则修改数据库中的判分点信息
if (!experimentalRequirements2.equals(experimentalRequirements1)) {
mapper.updateTradingJudgmentPoints(point.getProjectId(), pointId);
}
} else {
//数据库中该判分点已绑定过别的项目id,并且该判分点没有绑定过此时前端传来的项目id
if (!StringUtils.isEmpty(projectIds)) {
List<String> lists = Arrays.asList(projectIds.split(","));
if (!lists.contains(project.toString())) {
buff.append(projectIds);
buff.append(",");
buff.append(project);
}
}
//数据库中该判分点未绑定任何项目id
else if (StringUtils.isEmpty(projectIds)) {
buff.append(project);
}
//数据中实验要求不为空,且数据库中的实验要求与前端传来的实验要求信息一致
if (experimentalRequirements2 != null && !experimentalRequirements2.equals("")
&& experimentalRequirements2.equals(experimentalRequirements1)) {
mapper.updateTradingJudgmentPoints(new String(buff), pointId);
}
//数据库中的实验要求与前端传来的实验要求信息不一致
else if (!experimentalRequirements2.equals(experimentalRequirements1)) {
mapper.updateTradingJudgmentPoints(new String(buff), pointId);
}
// 添加分数
indexMapper.addScoreIndex(new ScoreIndex(score1, pointId, project, pro.getUserId(),systemId));
5 years ago
}
judgments.remove(pointId);
}
// 从判分点id中删除该项目的id
for (int i = 0; i < judgments.size(); i++) {
Integer judgmentPointsId = judgments.get(i);
4 years ago
JudgmentPoints point = mapper.getByjudgmentPointsId(judgmentPointsId);
5 years ago
String projectIds = point.getProjectId();
// 删除分数表中对应的判分点id+项目id数据
indexMapper.removeScore(judgmentPointsId, project, userId);
// 对取出的数据,删除该项目的id
List<String> str3 = Arrays.asList(projectIds.split(","));
if (str3.contains(project.toString())) {
List<String> arrayList = new ArrayList<String>(str3);
arrayList.remove(project.toString());
// 删除字符中项目id
projectIds = StringUtils.strip(arrayList.toString(), "[]").replace(" ", "");
// 修改判分点中的项目id
mapper.updateProject(projectIds, null, judgments.get(i));
}
}
// 用来存储需要修改的角色id
List<Integer> roleid = new ArrayList<Integer>();
// 遍历前端传来的新的角色id
for (int i = 0; i < roles.size(); i++) {
// 如果前端传来的数据,在数据库中没有,则存起来
if (!rolesIds.contains(roles.get(i))) {
roleid.add(roles.get(i));
}
}
4 years ago
if (roles != null && roles.size() > 0) {
Integer size = roles.size();
for (int i = 0; i<size; i++){
Integer roleId = roles.get(i);
mapper.updateRoleProjectId(roleId, project);
}
5 years ago
}
5 years ago
//修改项目信息
mapper.updateProjectManagement(pro);
resp.put("retcode", 200);
} catch (RuntimeException e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "Update Failed");
throw new RuntimeException();
}
return resp;
}
public HashMap<String, Object> getManagements(Integer projectPermissions){
HashMap<String, Object> resp = new HashMap<String, Object>();
try{
List<ProjectManagement> projectManagements = mapper.getManagements(projectPermissions);
resp.put("retcode", 200);
resp.put("retvalue",projectManagements);
}catch (RuntimeException e){
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "数据有误,查询失败!");
throw new RuntimeException();
}
return resp;
}
/**
* 项目启用/禁用
*/
public HashMap<String, Object> enable(Integer id, Integer enable) {
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
mapper.enable(id, enable);
resp.put("retcode", 200);
resp.put("retvalue","SUCCESS");
} catch (RuntimeException e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "SERVER ERROR");
throw new RuntimeException();
}
return resp;
}
5 years ago
}