From 01aad063c9143843ebd000be547d6e39c4e78027 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Thu, 29 Sep 2022 18:12:27 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E3=80=90=E7=BB=84=E7=BB=87=E3=80=81?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=85=B3=E8=81=94=E5=85=B3=E7=B3=BB=EF=BC=9B?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E8=8E=B7=E5=8F=96=E9=A1=B9=E7=9B=AE=E7=9A=84?= =?UTF-8?q?=E7=BB=84=E7=BB=87=E4=BF=A1=E6=81=AF=EF=BC=9B=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E7=BB=84=E7=BB=87=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/20220929-wei-org-project.sql | 11 + .../controller/org/OrgProjectController.java | 33 ++ .../joylink/rtss/dao/org/OrgProjectDao.java | 16 + .../rtss/entity/org/OrgProjectExample.java | 511 ++++++++++++++++++ .../rtss/services/org/IOrgProjectService.java | 39 ++ .../rtss/services/org/OrgProjectService.java | 148 +++++ .../joylink/rtss/services/org/OrgService.java | 7 + .../rtss/vo/client/org/OrgProjectVO.java | 15 +- .../mybatis/mapper/OrgProjectDao.xml | 208 +++++++ 9 files changed, 982 insertions(+), 6 deletions(-) create mode 100644 sql/20220929-wei-org-project.sql create mode 100644 src/main/java/club/joylink/rtss/controller/org/OrgProjectController.java create mode 100644 src/main/java/club/joylink/rtss/dao/org/OrgProjectDao.java create mode 100644 src/main/java/club/joylink/rtss/entity/org/OrgProjectExample.java create mode 100644 src/main/java/club/joylink/rtss/services/org/IOrgProjectService.java create mode 100644 src/main/java/club/joylink/rtss/services/org/OrgProjectService.java create mode 100644 src/main/resources/mybatis/mapper/OrgProjectDao.xml diff --git a/sql/20220929-wei-org-project.sql b/sql/20220929-wei-org-project.sql new file mode 100644 index 000000000..41283592c --- /dev/null +++ b/sql/20220929-wei-org-project.sql @@ -0,0 +1,11 @@ +create TABLE `org_project` ( + `id` int NOT NULL AUTO_INCREMENT comment '主键', + `org_id` int NOT NULL comment '组织ID', + `project_code` varchar(255) NOT NULL comment '项目编码', + `creator_id` int DEFAULT NULL comment '创建者', + `create_time` datetime DEFAULT NULL comment '创建时间', + PRIMARY KEY (`id`), + UNIQUE KEY `org_id_2` (`org_id`,`project_code`), + KEY `org_id` (`org_id`), + KEY `project_code` (`project_code`) +) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; \ No newline at end of file diff --git a/src/main/java/club/joylink/rtss/controller/org/OrgProjectController.java b/src/main/java/club/joylink/rtss/controller/org/OrgProjectController.java new file mode 100644 index 000000000..3dc046754 --- /dev/null +++ b/src/main/java/club/joylink/rtss/controller/org/OrgProjectController.java @@ -0,0 +1,33 @@ +package club.joylink.rtss.controller.org; + +import club.joylink.rtss.services.org.IOrgProjectService; +import club.joylink.rtss.vo.LoginUserInfoVO; +import club.joylink.rtss.vo.client.org.OrgProjectVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/org") +public class OrgProjectController { + + @Autowired + private IOrgProjectService orgProjectService; + + /** + * 用户登录时,要选择的组织列表 + */ + @GetMapping("list") + public List queryOrgList(@RequestAttribute LoginUserInfoVO loginInfo) { + return orgProjectService.queryOrgProjectListByProjectAndUid(loginInfo.getProject(), loginInfo.getAccountVO().getId()); + } + + /** + * 选择登入组织 + */ + @PutMapping("signIn/{orgId}") + public void signInOrg(@PathVariable Long orgId, @RequestAttribute LoginUserInfoVO loginInfo) { + orgProjectService.signInOrg(orgId, loginInfo); + } +} diff --git a/src/main/java/club/joylink/rtss/dao/org/OrgProjectDao.java b/src/main/java/club/joylink/rtss/dao/org/OrgProjectDao.java new file mode 100644 index 000000000..9993ffdea --- /dev/null +++ b/src/main/java/club/joylink/rtss/dao/org/OrgProjectDao.java @@ -0,0 +1,16 @@ +package club.joylink.rtss.dao.org; + +import club.joylink.rtss.dao.MyBatisBaseDao; +import club.joylink.rtss.entity.org.OrgProject; +import club.joylink.rtss.entity.org.OrgProjectExample; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +/** + * 组织与项目关系 + */ +@Repository +public interface OrgProjectDao extends MyBatisBaseDao { + + int deleteByExampleSelective(@Param("example") OrgProjectExample example); +} \ No newline at end of file diff --git a/src/main/java/club/joylink/rtss/entity/org/OrgProjectExample.java b/src/main/java/club/joylink/rtss/entity/org/OrgProjectExample.java new file mode 100644 index 000000000..7fff5a11f --- /dev/null +++ b/src/main/java/club/joylink/rtss/entity/org/OrgProjectExample.java @@ -0,0 +1,511 @@ +package club.joylink.rtss.entity.org; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class OrgProjectExample { + protected String orderByClause; + + protected boolean distinct; + + protected List oredCriteria; + + public OrgProjectExample() { + oredCriteria = new ArrayList(); + } + + public void setOrderByClause(String orderByClause) { + this.orderByClause = orderByClause; + } + + public String getOrderByClause() { + return orderByClause; + } + + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + public boolean isDistinct() { + return distinct; + } + + public List getOredCriteria() { + return oredCriteria; + } + + public void or(Criteria criteria) { + oredCriteria.add(criteria); + } + + public Criteria or() { + Criteria criteria = createCriteriaInternal(); + oredCriteria.add(criteria); + return criteria; + } + + public Criteria createCriteria() { + Criteria criteria = createCriteriaInternal(); + if (oredCriteria.size() == 0) { + oredCriteria.add(criteria); + } + return criteria; + } + + protected Criteria createCriteriaInternal() { + Criteria criteria = new Criteria(); + return criteria; + } + + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + } + + protected abstract static class GeneratedCriteria { + protected List criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List getCriteria() { + return criteria; + } + + protected void addCriterion(String condition) { + if (condition == null) { + throw new RuntimeException("Value for condition cannot be null"); + } + criteria.add(new Criterion(condition)); + } + + protected void addCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value)); + } + + protected void addCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value1, value2)); + } + + public Criteria andIdIsNull() { + addCriterion("id is null"); + return (Criteria) this; + } + + public Criteria andIdIsNotNull() { + addCriterion("id is not null"); + return (Criteria) this; + } + + public Criteria andIdEqualTo(Integer value) { + addCriterion("id =", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotEqualTo(Integer value) { + addCriterion("id <>", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThan(Integer value) { + addCriterion("id >", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThanOrEqualTo(Integer value) { + addCriterion("id >=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThan(Integer value) { + addCriterion("id <", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThanOrEqualTo(Integer value) { + addCriterion("id <=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdIn(List values) { + addCriterion("id in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdNotIn(List values) { + addCriterion("id not in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdBetween(Integer value1, Integer value2) { + addCriterion("id between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andIdNotBetween(Integer value1, Integer value2) { + addCriterion("id not between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andOrgIdIsNull() { + addCriterion("org_id is null"); + return (Criteria) this; + } + + public Criteria andOrgIdIsNotNull() { + addCriterion("org_id is not null"); + return (Criteria) this; + } + + public Criteria andOrgIdEqualTo(Long value) { + addCriterion("org_id =", value, "orgId"); + return (Criteria) this; + } + + public Criteria andOrgIdNotEqualTo(Long value) { + addCriterion("org_id <>", value, "orgId"); + return (Criteria) this; + } + + public Criteria andOrgIdGreaterThan(Long value) { + addCriterion("org_id >", value, "orgId"); + return (Criteria) this; + } + + public Criteria andOrgIdGreaterThanOrEqualTo(Long value) { + addCriterion("org_id >=", value, "orgId"); + return (Criteria) this; + } + + public Criteria andOrgIdLessThan(Long value) { + addCriterion("org_id <", value, "orgId"); + return (Criteria) this; + } + + public Criteria andOrgIdLessThanOrEqualTo(Long value) { + addCriterion("org_id <=", value, "orgId"); + return (Criteria) this; + } + + public Criteria andOrgIdIn(List values) { + addCriterion("org_id in", values, "orgId"); + return (Criteria) this; + } + + public Criteria andOrgIdNotIn(List values) { + addCriterion("org_id not in", values, "orgId"); + return (Criteria) this; + } + + public Criteria andOrgIdBetween(Long value1, Long value2) { + addCriterion("org_id between", value1, value2, "orgId"); + return (Criteria) this; + } + + public Criteria andOrgIdNotBetween(Long value1, Long value2) { + addCriterion("org_id not between", value1, value2, "orgId"); + return (Criteria) this; + } + + public Criteria andProjectCodeIsNull() { + addCriterion("project_code is null"); + return (Criteria) this; + } + + public Criteria andProjectCodeIsNotNull() { + addCriterion("project_code is not null"); + return (Criteria) this; + } + + public Criteria andProjectCodeEqualTo(String value) { + addCriterion("project_code =", value, "projectCode"); + return (Criteria) this; + } + + public Criteria andProjectCodeNotEqualTo(String value) { + addCriterion("project_code <>", value, "projectCode"); + return (Criteria) this; + } + + public Criteria andProjectCodeGreaterThan(String value) { + addCriterion("project_code >", value, "projectCode"); + return (Criteria) this; + } + + public Criteria andProjectCodeGreaterThanOrEqualTo(String value) { + addCriterion("project_code >=", value, "projectCode"); + return (Criteria) this; + } + + public Criteria andProjectCodeLessThan(String value) { + addCriterion("project_code <", value, "projectCode"); + return (Criteria) this; + } + + public Criteria andProjectCodeLessThanOrEqualTo(String value) { + addCriterion("project_code <=", value, "projectCode"); + return (Criteria) this; + } + + public Criteria andProjectCodeLike(String value) { + addCriterion("project_code like", value, "projectCode"); + return (Criteria) this; + } + + public Criteria andProjectCodeNotLike(String value) { + addCriterion("project_code not like", value, "projectCode"); + return (Criteria) this; + } + + public Criteria andProjectCodeIn(List values) { + addCriterion("project_code in", values, "projectCode"); + return (Criteria) this; + } + + public Criteria andProjectCodeNotIn(List values) { + addCriterion("project_code not in", values, "projectCode"); + return (Criteria) this; + } + + public Criteria andProjectCodeBetween(String value1, String value2) { + addCriterion("project_code between", value1, value2, "projectCode"); + return (Criteria) this; + } + + public Criteria andProjectCodeNotBetween(String value1, String value2) { + addCriterion("project_code not between", value1, value2, "projectCode"); + return (Criteria) this; + } + + public Criteria andCreatorIdIsNull() { + addCriterion("creator_id is null"); + return (Criteria) this; + } + + public Criteria andCreatorIdIsNotNull() { + addCriterion("creator_id is not null"); + return (Criteria) this; + } + + public Criteria andCreatorIdEqualTo(Integer value) { + addCriterion("creator_id =", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdNotEqualTo(Integer value) { + addCriterion("creator_id <>", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdGreaterThan(Integer value) { + addCriterion("creator_id >", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdGreaterThanOrEqualTo(Integer value) { + addCriterion("creator_id >=", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdLessThan(Integer value) { + addCriterion("creator_id <", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdLessThanOrEqualTo(Integer value) { + addCriterion("creator_id <=", value, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdIn(List values) { + addCriterion("creator_id in", values, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdNotIn(List values) { + addCriterion("creator_id not in", values, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdBetween(Integer value1, Integer value2) { + addCriterion("creator_id between", value1, value2, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreatorIdNotBetween(Integer value1, Integer value2) { + addCriterion("creator_id not between", value1, value2, "creatorId"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNull() { + addCriterion("create_time is null"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNotNull() { + addCriterion("create_time is not null"); + return (Criteria) this; + } + + public Criteria andCreateTimeEqualTo(Date value) { + addCriterion("create_time =", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotEqualTo(Date value) { + addCriterion("create_time <>", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThan(Date value) { + addCriterion("create_time >", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThanOrEqualTo(Date value) { + addCriterion("create_time >=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThan(Date value) { + addCriterion("create_time <", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThanOrEqualTo(Date value) { + addCriterion("create_time <=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeIn(List values) { + addCriterion("create_time in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotIn(List values) { + addCriterion("create_time not in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeBetween(Date value1, Date value2) { + addCriterion("create_time between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotBetween(Date value1, Date value2) { + addCriterion("create_time not between", value1, value2, "createTime"); + return (Criteria) this; + } + } + + public static class Criteria extends GeneratedCriteria { + + protected Criteria() { + super(); + } + } + + public static class Criterion { + private String condition; + + private Object value; + + private Object secondValue; + + private boolean noValue; + + private boolean singleValue; + + private boolean betweenValue; + + private boolean listValue; + + private String typeHandler; + + public String getCondition() { + return condition; + } + + public Object getValue() { + return value; + } + + public Object getSecondValue() { + return secondValue; + } + + public boolean isNoValue() { + return noValue; + } + + public boolean isSingleValue() { + return singleValue; + } + + public boolean isBetweenValue() { + return betweenValue; + } + + public boolean isListValue() { + return listValue; + } + + public String getTypeHandler() { + return typeHandler; + } + + protected Criterion(String condition) { + super(); + this.condition = condition; + this.typeHandler = null; + this.noValue = true; + } + + protected Criterion(String condition, Object value, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.typeHandler = typeHandler; + if (value instanceof List) { + this.listValue = true; + } else { + this.singleValue = true; + } + } + + protected Criterion(String condition, Object value) { + this(condition, value, null); + } + + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.secondValue = secondValue; + this.typeHandler = typeHandler; + this.betweenValue = true; + } + + protected Criterion(String condition, Object value, Object secondValue) { + this(condition, value, secondValue, null); + } + } +} \ No newline at end of file diff --git a/src/main/java/club/joylink/rtss/services/org/IOrgProjectService.java b/src/main/java/club/joylink/rtss/services/org/IOrgProjectService.java new file mode 100644 index 000000000..3f04621c5 --- /dev/null +++ b/src/main/java/club/joylink/rtss/services/org/IOrgProjectService.java @@ -0,0 +1,39 @@ +package club.joylink.rtss.services.org; + +import club.joylink.rtss.entity.org.OrgProject; +import club.joylink.rtss.vo.AccountVO; +import club.joylink.rtss.vo.LoginUserInfoVO; +import club.joylink.rtss.vo.client.org.OrgProjectVO; + +import java.util.List; + +/** + * 项目与组织关系 + */ +public interface IOrgProjectService { + + /** + * 根据组织Id获取项目列表 + */ + List queryOrgProjectListByOrgId(Long orgId); + + /** + * 根据项目获取组织列表 + */ + List queryOrgProjectListByProjectAndUid(String project, Long uid); + + /** + * 选择登入项目 + */ + void signInOrg(Long orgId, LoginUserInfoVO loginInfo); + + /** + * 保存顶级信息时,处理信息 + */ + void save(Long orgId, List projectList, AccountVO user); + + /** + * 保存顶级信息时,处理编辑信息 + */ + void update(Long orgId, List projectList, AccountVO user); +} diff --git a/src/main/java/club/joylink/rtss/services/org/OrgProjectService.java b/src/main/java/club/joylink/rtss/services/org/OrgProjectService.java new file mode 100644 index 000000000..1dc3f5e8c --- /dev/null +++ b/src/main/java/club/joylink/rtss/services/org/OrgProjectService.java @@ -0,0 +1,148 @@ +package club.joylink.rtss.services.org; + +import club.joylink.rtss.constants.BusinessConsts; +import club.joylink.rtss.dao.OrgDAO; +import club.joylink.rtss.dao.OrgUserDAO; +import club.joylink.rtss.dao.org.OrgProjectDao; +import club.joylink.rtss.entity.Org; +import club.joylink.rtss.entity.OrgExample; +import club.joylink.rtss.entity.OrgUser; +import club.joylink.rtss.entity.OrgUserExample; +import club.joylink.rtss.entity.org.OrgProject; +import club.joylink.rtss.entity.org.OrgProjectExample; +import club.joylink.rtss.simulation.cbtc.exception.SimulationException; +import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; +import club.joylink.rtss.vo.AccountVO; +import club.joylink.rtss.vo.LoginUserInfoVO; +import club.joylink.rtss.vo.client.org.OrgProjectVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 组织与项目关联管理 + */ +@Service +public class OrgProjectService implements IOrgProjectService { + @Autowired + private OrgProjectDao orgProjectDao; + + @Autowired + private OrgUserDAO orgUserDAO; + + @Autowired + private OrgDAO orgDAO; + + @Override + public List queryOrgProjectListByOrgId(Long orgId) { + OrgProjectExample orgProjectExample = new OrgProjectExample(); + orgProjectExample.createCriteria().andOrgIdEqualTo(orgId); + return orgProjectDao.selectByExample(orgProjectExample); + } + + @Override + public List queryOrgProjectListByProjectAndUid(String project, Long uid) { + // 查询项目关联顶级组织 + OrgProjectExample orgProjectExample = new OrgProjectExample(); + orgProjectExample.createCriteria().andProjectCodeEqualTo(project); + List orgProjectList = orgProjectDao.selectByExample(orgProjectExample); + if (CollectionUtils.isEmpty(orgProjectList)) { + return List.of(); + } + List orgTopIdList = orgProjectList.stream().map(OrgProject::getOrgId).collect(Collectors.toList()); + // 获取人员关联组织 + OrgUserExample example = new OrgUserExample(); + example.createCriteria().andUserIdEqualTo(uid); + List orgUserList = orgUserDAO.selectByExample(example); + if (CollectionUtils.isEmpty(orgUserList)) { + return List.of(); + } + List orgIdList = orgUserList.stream().map(OrgUser::getOrgId).collect(Collectors.toList()); + OrgExample orgExample = new OrgExample(); + orgExample.createCriteria().andStatusEqualTo(BusinessConsts.Org.Status.VALID).andIdIn(orgIdList).andRootIdIn(orgTopIdList); + List orgList = orgDAO.selectByExample(orgExample); + return orgList.stream().map(org -> new OrgProjectVO(org, project)).collect(Collectors.toList()); + } + + @Override + public void signInOrg(Long orgId, LoginUserInfoVO loginInfo) { + Org orgInfo = orgDAO.selectByPrimaryKey(orgId); + // 查询项目关联顶级组织 + OrgProjectExample orgProjectExample = new OrgProjectExample(); + orgProjectExample.createCriteria().andProjectCodeEqualTo(loginInfo.getProject()).andOrgIdEqualTo(orgInfo.getRootId()); + List orgProjectList = orgProjectDao.selectByExample(orgProjectExample); + if (CollectionUtils.isEmpty(orgProjectList)) { + throw new SimulationException(SimulationExceptionType.Illegal_Argument); + } + // 检验用户是否有组织信息 + OrgUserExample example = new OrgUserExample(); + example.createCriteria().andUserIdEqualTo(loginInfo.getAccountVO().getId()).andOrgIdEqualTo(orgId); + List orgUserList = orgUserDAO.selectByExample(example); + if (CollectionUtils.isEmpty(orgUserList)) { + throw new SimulationException(SimulationExceptionType.Illegal_Argument); + } + loginInfo.setOrgProjectVO(new OrgProjectVO(orgInfo, loginInfo.getProject())); + } + + @Override + public void save(Long orgId, List projectList, AccountVO user) { + if (orgId == null || CollectionUtils.isEmpty(projectList)) { + return; + } + projectList.stream().forEach(code -> { + OrgProject orgProject = new OrgProject(); + orgProject.setOrgId(orgId); + orgProject.setProjectCode(code); + orgProject.setCreateTime(LocalDateTime.now()); + orgProject.setCreatorId(user.getId()); + orgProjectDao.insert(orgProject); + }); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(Long orgId, List projectList, AccountVO user) { + OrgProjectExample orgProjectExample = new OrgProjectExample(); + if (CollectionUtils.isEmpty(projectList)) { // 为空,直接删除项目列表 + orgProjectExample.createCriteria().andOrgIdEqualTo(orgId); + orgProjectDao.deleteByExampleSelective(orgProjectExample); + } else { + List orgProjects = orgProjectDao.selectByExample(orgProjectExample); + if (checkChange(orgProjects, projectList)) { + List oldProjectList = orgProjects.stream().map(OrgProject::getProjectCode).collect(Collectors.toList()); + // 删除不存在的 + List delCodeList = oldProjectList.stream().filter(code -> !projectList.contains(code)).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(delCodeList)) { + orgProjectExample.createCriteria().andOrgIdEqualTo(orgId).andProjectCodeIn(delCodeList); + orgProjectDao.deleteByExampleSelective(orgProjectExample); + } + // 插入信息的 + List newCodeList = projectList.stream().filter(code -> !oldProjectList.contains(code)).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(newCodeList)) { + save(orgId, newCodeList, user); + } + } + } + } + + /** + * 判断数组是否发生变化 + */ + private boolean checkChange(List orgProjects, List projectList) { + if (CollectionUtils.isEmpty(projectList) && CollectionUtils.isEmpty(projectList)) { + return false; + } + if (orgProjects.size() != projectList.size()) { + return true; + } + if (orgProjects.stream().anyMatch(o -> !projectList.contains(o.getProjectCode()))) { + return true; + } + return false; + } +} diff --git a/src/main/java/club/joylink/rtss/services/org/OrgService.java b/src/main/java/club/joylink/rtss/services/org/OrgService.java index e4517deaf..1411c1aca 100644 --- a/src/main/java/club/joylink/rtss/services/org/OrgService.java +++ b/src/main/java/club/joylink/rtss/services/org/OrgService.java @@ -43,6 +43,9 @@ public class OrgService implements IOrgService { @Autowired private QRCodeManager qrCodeManager; + @Autowired + private IOrgProjectService orgProjectService; + @Transactional @Override public CompanyVO createTopOrg(CompanyVO companyVO, AccountVO user) { @@ -60,6 +63,8 @@ public class OrgService implements IOrgService { this.orgDAO.insert(entity); entity.setRootId(entity.getId()); orgDAO.updateByPrimaryKey(entity); + // 20220929 增加 + orgProjectService.save(entity.getId(), companyVO.getProjectCodes(), user); return new CompanyVO(entity); } @@ -154,6 +159,8 @@ public class OrgService implements IOrgService { if (!CollectionUtils.isEmpty(companyVO.getProjectCodes())) { BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(isTopOrg(org), "非顶级组织不能修改关联项目"); // confirmProjectCodesNotRepeat(org.getId(), companyVO.getProjectCodes()); + // 20220929 增加 + orgProjectService.update(id, companyVO.getProjectCodes(), user); } confirmNameUnique(id, companyVO.getName()); //更新 diff --git a/src/main/java/club/joylink/rtss/vo/client/org/OrgProjectVO.java b/src/main/java/club/joylink/rtss/vo/client/org/OrgProjectVO.java index 6bf1b97a5..6782f5b74 100644 --- a/src/main/java/club/joylink/rtss/vo/client/org/OrgProjectVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/org/OrgProjectVO.java @@ -1,19 +1,22 @@ package club.joylink.rtss.vo.client.org; -import club.joylink.rtss.entity.org.OrgProject; +import club.joylink.rtss.entity.Org; import lombok.Data; +import lombok.NoArgsConstructor; @Data +@NoArgsConstructor public class OrgProjectVO { - private Long topOrgId; - private Long orgId; + private Long topOrgId; + private String projectCode; - public OrgProjectVO(OrgProject orgProject) { - this.orgId = orgProject.getOrgId(); - this.projectCode = orgProject.getProjectCode(); + public OrgProjectVO(Org org, String projectCode) { + this.orgId = org.getId(); + this.topOrgId = org.getRootId(); + this.projectCode = projectCode; } } diff --git a/src/main/resources/mybatis/mapper/OrgProjectDao.xml b/src/main/resources/mybatis/mapper/OrgProjectDao.xml new file mode 100644 index 000000000..8cc519b86 --- /dev/null +++ b/src/main/resources/mybatis/mapper/OrgProjectDao.xml @@ -0,0 +1,208 @@ + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + id, org_id, project_code, creator_id, create_time + + + + + delete from org_project where id = #{id,jdbcType=BIGINT} + + + delete from org_project + + + + + + insert into org_project (org_id, project_code, creator_id, create_time) + values (#{orgId,jdbcType=BIGINT}, #{projectCode,jdbcType=VARCHAR}, + #{creatorId,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}) + + + insert into org_project + + + id, + + + org_id, + + + project_code, + + + creator_id, + + + create_time, + + + + + #{id,jdbcType=BIGINT}, + + + #{orgId,jdbcType=BIGINT}, + + + #{projectCode,jdbcType=VARCHAR}, + + + #{creatorId,jdbcType=BIGINT}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + + + update org_project + + + id = #{record.id,jdbcType=BIGINT}, + + + org_id = #{record.orgId,jdbcType=BIGINT}, + + + project_code = #{record.projectCode,jdbcType=VARCHAR}, + + + creator_id = #{record.creatorId,jdbcType=BIGINT}, + + + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + + + + + + + + update org_project + set id = #{record.id,jdbcType=BIGINT}, + org_id = #{record.orgId,jdbcType=BIGINT}, + project_code = #{record.projectCode,jdbcType=VARCHAR}, + creator_id = #{record.creatorId,jdbcType=BIGINT}, + create_time = #{record.createTime,jdbcType=TIMESTAMP} + + + + + + update org_project + + + org_id = #{orgId,jdbcType=BIGINT}, + + + project_code = #{projectCode,jdbcType=VARCHAR}, + + + creator_id = #{creatorId,jdbcType=BIGINT}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=BIGINT} + + + update org_project + set org_id = #{orgId,jdbcType=BIGINT}, + project_code = #{projectCode,jdbcType=VARCHAR}, + creator_id = #{creatorId,jdbcType=BIGINT}, + create_time = #{createTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=BIGINT} + + \ No newline at end of file From 1db89def39db1f641a2bfef7db8dcf642df86b7f Mon Sep 17 00:00:00 2001 From: tiger_zhou <123456> Date: Fri, 30 Sep 2022 09:24:41 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=AF=AD=E9=9F=B3=E8=AF=86=E5=88=AB?= =?UTF-8?q?=EF=BC=8C=E5=90=88=E6=88=90=E9=87=8D=E6=9E=84=20=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../joylink/rtss/services/paper/PagerQuestionService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/club/joylink/rtss/services/paper/PagerQuestionService.java b/src/main/java/club/joylink/rtss/services/paper/PagerQuestionService.java index ea7ad2395..3c4bb569c 100644 --- a/src/main/java/club/joylink/rtss/services/paper/PagerQuestionService.java +++ b/src/main/java/club/joylink/rtss/services/paper/PagerQuestionService.java @@ -37,8 +37,9 @@ public class PagerQuestionService { private PaperQuestionDAO questionDAO; private Object queryQuestions(QuestionQueryVO queryVO, boolean isPaging,boolean companyIdCanNull){ - boolean check = Objects.equals(false,companyIdCanNull) && Objects.isNull(queryVO.getCompanyId()); - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(check,"题目答案不能为空"); + if(Objects.equals(false,companyIdCanNull)){ + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(queryVO.getCompanyId()),"题目答案不能为空"); + } if(isPaging){ PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); } From 84b542daa03e508c7e7828427bd395c8ee2697f2 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Fri, 30 Sep 2022 09:32:05 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E3=80=90=E5=A2=9E=E5=8A=A0=E9=9D=9E?= =?UTF-8?q?=E7=A9=BA=E5=88=A4=E6=96=AD=EF=BC=8C=E5=A2=9E=E5=8A=A0=E7=BB=84?= =?UTF-8?q?=E7=BB=87=E5=90=8D=E7=A7=B0=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/club/joylink/rtss/services/org/OrgProjectService.java | 3 +++ .../java/club/joylink/rtss/vo/client/org/OrgProjectVO.java | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/main/java/club/joylink/rtss/services/org/OrgProjectService.java b/src/main/java/club/joylink/rtss/services/org/OrgProjectService.java index 1dc3f5e8c..e1fc328c7 100644 --- a/src/main/java/club/joylink/rtss/services/org/OrgProjectService.java +++ b/src/main/java/club/joylink/rtss/services/org/OrgProjectService.java @@ -72,6 +72,9 @@ public class OrgProjectService implements IOrgProjectService { @Override public void signInOrg(Long orgId, LoginUserInfoVO loginInfo) { Org orgInfo = orgDAO.selectByPrimaryKey(orgId); + if (orgInfo == null) { + throw new SimulationException(SimulationExceptionType.Illegal_Argument); + } // 查询项目关联顶级组织 OrgProjectExample orgProjectExample = new OrgProjectExample(); orgProjectExample.createCriteria().andProjectCodeEqualTo(loginInfo.getProject()).andOrgIdEqualTo(orgInfo.getRootId()); diff --git a/src/main/java/club/joylink/rtss/vo/client/org/OrgProjectVO.java b/src/main/java/club/joylink/rtss/vo/client/org/OrgProjectVO.java index 6782f5b74..01d1933a4 100644 --- a/src/main/java/club/joylink/rtss/vo/client/org/OrgProjectVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/org/OrgProjectVO.java @@ -9,6 +9,7 @@ import lombok.NoArgsConstructor; public class OrgProjectVO { private Long orgId; + private String name; private Long topOrgId; @@ -16,6 +17,7 @@ public class OrgProjectVO { public OrgProjectVO(Org org, String projectCode) { this.orgId = org.getId(); + this.name = org.getName(); this.topOrgId = org.getRootId(); this.projectCode = projectCode; }