feat: add school product configuration
parent
649b6a08af
commit
a11fb0c8d0
@ -0,0 +1,13 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS school_product_config (
|
||||||
|
school_id VARCHAR(64) NOT NULL PRIMARY KEY,
|
||||||
|
organization_mode VARCHAR(32) NOT NULL DEFAULT 'ADMIN_CLASS_ENABLED',
|
||||||
|
student_roster_owner VARCHAR(32) NOT NULL DEFAULT 'SCHOOL_ADMIN',
|
||||||
|
create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
) COMMENT='school product capability configuration';
|
||||||
|
|
||||||
|
INSERT INTO school_product_config (school_id, organization_mode, student_roster_owner)
|
||||||
|
SELECT school_id, 'ADMIN_CLASS_ENABLED', 'SCHOOL_ADMIN' FROM school
|
||||||
|
ON DUPLICATE KEY UPDATE school_id = VALUES(school_id);
|
||||||
|
|
||||||
|
ALTER TABLE teaching_class_student MODIFY admin_class_id VARCHAR(64) NULL;
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
package com.sztzjy.linkCommerce.entity;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class SchoolProductConfig {
|
||||||
|
private String schoolId;
|
||||||
|
private String organizationMode;
|
||||||
|
private String studentRosterOwner;
|
||||||
|
private Date createTime;
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
public String getSchoolId() { return schoolId; }
|
||||||
|
public void setSchoolId(String schoolId) { this.schoolId = schoolId == null ? null : schoolId.trim(); }
|
||||||
|
public String getOrganizationMode() { return organizationMode; }
|
||||||
|
public void setOrganizationMode(String organizationMode) { this.organizationMode = organizationMode == null ? null : organizationMode.trim(); }
|
||||||
|
public String getStudentRosterOwner() { return studentRosterOwner; }
|
||||||
|
public void setStudentRosterOwner(String studentRosterOwner) { this.studentRosterOwner = studentRosterOwner == null ? null : studentRosterOwner.trim(); }
|
||||||
|
public Date getCreateTime() { return createTime; }
|
||||||
|
public void setCreateTime(Date createTime) { this.createTime = createTime; }
|
||||||
|
public Date getUpdateTime() { return updateTime; }
|
||||||
|
public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; }
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
package com.sztzjy.linkCommerce.mapper;
|
||||||
|
|
||||||
|
import com.sztzjy.linkCommerce.entity.SchoolProductConfig;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface SchoolProductConfigMapper {
|
||||||
|
SchoolProductConfig selectByPrimaryKey(String schoolId);
|
||||||
|
|
||||||
|
int insert(SchoolProductConfig record);
|
||||||
|
|
||||||
|
int updateByPrimaryKey(SchoolProductConfig record);
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
package com.sztzjy.linkCommerce.service;
|
||||||
|
|
||||||
|
import com.sztzjy.linkCommerce.entity.SchoolProductConfig;
|
||||||
|
|
||||||
|
public interface SchoolProductConfigService {
|
||||||
|
SchoolProductConfig getRequiredConfig(String schoolId);
|
||||||
|
|
||||||
|
boolean requiresAdminClass(String schoolId);
|
||||||
|
|
||||||
|
boolean isTeacherRosterManaged(String schoolId);
|
||||||
|
|
||||||
|
void requireAdminClassEnabled(String schoolId);
|
||||||
|
}
|
||||||
@ -0,0 +1,50 @@
|
|||||||
|
package com.sztzjy.linkCommerce.service.impl;
|
||||||
|
|
||||||
|
import com.sztzjy.linkCommerce.config.exception.handler.ServiceException;
|
||||||
|
import com.sztzjy.linkCommerce.entity.SchoolProductConfig;
|
||||||
|
import com.sztzjy.linkCommerce.mapper.SchoolProductConfigMapper;
|
||||||
|
import com.sztzjy.linkCommerce.service.SchoolProductConfigService;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class SchoolProductConfigServiceImpl implements SchoolProductConfigService {
|
||||||
|
public static final String ADMIN_CLASS_ENABLED = "ADMIN_CLASS_ENABLED";
|
||||||
|
public static final String TEACHING_CLASS_ONLY = "TEACHING_CLASS_ONLY";
|
||||||
|
public static final String SCHOOL_ADMIN = "SCHOOL_ADMIN";
|
||||||
|
public static final String TEACHER = "TEACHER";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public SchoolProductConfigMapper schoolProductConfigMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchoolProductConfig getRequiredConfig(String schoolId) {
|
||||||
|
if (StringUtils.isBlank(schoolId)) {
|
||||||
|
throw new ServiceException(HttpStatus.BAD_REQUEST, "学校组织配置不存在");
|
||||||
|
}
|
||||||
|
SchoolProductConfig config = schoolProductConfigMapper.selectByPrimaryKey(schoolId);
|
||||||
|
if (config == null) {
|
||||||
|
throw new ServiceException(HttpStatus.BAD_REQUEST, "学校组织配置不存在");
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresAdminClass(String schoolId) {
|
||||||
|
return ADMIN_CLASS_ENABLED.equals(getRequiredConfig(schoolId).getOrganizationMode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTeacherRosterManaged(String schoolId) {
|
||||||
|
return TEACHER.equals(getRequiredConfig(schoolId).getStudentRosterOwner());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void requireAdminClassEnabled(String schoolId) {
|
||||||
|
if (!requiresAdminClass(schoolId)) {
|
||||||
|
throw new ServiceException(HttpStatus.BAD_REQUEST, "当前学校未启用行政班");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.sztzjy.linkCommerce.mapper.SchoolProductConfigMapper">
|
||||||
|
<resultMap id="BaseResultMap" type="com.sztzjy.linkCommerce.entity.SchoolProductConfig">
|
||||||
|
<id column="school_id" property="schoolId" jdbcType="VARCHAR"/>
|
||||||
|
<result column="organization_mode" property="organizationMode" jdbcType="VARCHAR"/>
|
||||||
|
<result column="student_roster_owner" property="studentRosterOwner" jdbcType="VARCHAR"/>
|
||||||
|
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||||
|
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||||
|
</resultMap>
|
||||||
|
<sql id="Columns">school_id, organization_mode, student_roster_owner, create_time, update_time</sql>
|
||||||
|
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||||
|
select <include refid="Columns"/> from school_product_config where school_id = #{schoolId,jdbcType=VARCHAR}
|
||||||
|
</select>
|
||||||
|
<insert id="insert" parameterType="com.sztzjy.linkCommerce.entity.SchoolProductConfig">
|
||||||
|
insert into school_product_config (school_id, organization_mode, student_roster_owner, create_time, update_time)
|
||||||
|
values (#{schoolId,jdbcType=VARCHAR}, #{organizationMode,jdbcType=VARCHAR}, #{studentRosterOwner,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
|
||||||
|
</insert>
|
||||||
|
<update id="updateByPrimaryKey" parameterType="com.sztzjy.linkCommerce.entity.SchoolProductConfig">
|
||||||
|
update school_product_config set organization_mode = #{organizationMode,jdbcType=VARCHAR}, student_roster_owner = #{studentRosterOwner,jdbcType=VARCHAR}, update_time = #{updateTime,jdbcType=TIMESTAMP} where school_id = #{schoolId,jdbcType=VARCHAR}
|
||||||
|
</update>
|
||||||
|
</mapper>
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
package com.sztzjy.linkCommerce.service.impl;
|
||||||
|
|
||||||
|
import com.sztzjy.linkCommerce.config.exception.handler.ServiceException;
|
||||||
|
import com.sztzjy.linkCommerce.entity.SchoolProductConfig;
|
||||||
|
import com.sztzjy.linkCommerce.mapper.SchoolProductConfigMapper;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
class SchoolProductConfigServiceImplTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void teachingClassOnlySchoolDoesNotRequireAdministrativeClass() {
|
||||||
|
SchoolProductConfigServiceImpl service = new SchoolProductConfigServiceImpl();
|
||||||
|
service.schoolProductConfigMapper = mock(SchoolProductConfigMapper.class);
|
||||||
|
when(service.schoolProductConfigMapper.selectByPrimaryKey("school-zj"))
|
||||||
|
.thenReturn(config("school-zj", "TEACHING_CLASS_ONLY", "TEACHER"));
|
||||||
|
|
||||||
|
assertFalse(service.requiresAdminClass("school-zj"));
|
||||||
|
assertTrue(service.isTeacherRosterManaged("school-zj"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void standardSchoolRequiresAdministrativeClass() {
|
||||||
|
SchoolProductConfigServiceImpl service = new SchoolProductConfigServiceImpl();
|
||||||
|
service.schoolProductConfigMapper = mock(SchoolProductConfigMapper.class);
|
||||||
|
when(service.schoolProductConfigMapper.selectByPrimaryKey("school-standard"))
|
||||||
|
.thenReturn(config("school-standard", "ADMIN_CLASS_ENABLED", "SCHOOL_ADMIN"));
|
||||||
|
|
||||||
|
assertTrue(service.requiresAdminClass("school-standard"));
|
||||||
|
assertFalse(service.isTeacherRosterManaged("school-standard"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void missingConfigurationIsRejected() {
|
||||||
|
SchoolProductConfigServiceImpl service = new SchoolProductConfigServiceImpl();
|
||||||
|
service.schoolProductConfigMapper = mock(SchoolProductConfigMapper.class);
|
||||||
|
|
||||||
|
assertThrows(ServiceException.class, () -> service.getRequiredConfig("missing-school"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void administrativeClassGuardRejectsTeachingClassOnlySchool() {
|
||||||
|
SchoolProductConfigServiceImpl service = new SchoolProductConfigServiceImpl();
|
||||||
|
service.schoolProductConfigMapper = mock(SchoolProductConfigMapper.class);
|
||||||
|
when(service.schoolProductConfigMapper.selectByPrimaryKey("school-zj"))
|
||||||
|
.thenReturn(config("school-zj", "TEACHING_CLASS_ONLY", "TEACHER"));
|
||||||
|
|
||||||
|
assertThrows(ServiceException.class, () -> service.requireAdminClassEnabled("school-zj"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private SchoolProductConfig config(String schoolId, String organizationMode, String rosterOwner) {
|
||||||
|
SchoolProductConfig config = new SchoolProductConfig();
|
||||||
|
config.setSchoolId(schoolId);
|
||||||
|
config.setOrganizationMode(organizationMode);
|
||||||
|
config.setStudentRosterOwner(rosterOwner);
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue