Commit 010d4080 authored by liuyang's avatar liuyang

添加讲师角色

修改添加讲师功能
添加重置密码接口
parent 39292f18
......@@ -12,6 +12,10 @@ public class BizConstants {
* 运营人员
*/
public static final String ROLE_OPERATOR = "OPERATOR";
/**
* 讲师
*/
public static final String ROLE_TEACHER = "TEACHER";
/**
* 企业管理员
*/
......
......@@ -37,7 +37,7 @@ public class CourseController {
@ApiOperation("课程查询")
@PostMapping("/list")
@RequiresRoles(value = {BizConstants.ROLE_ADMIN,BizConstants.ROLE_OPERATOR},logical = Logical.OR)
@RequiresRoles(value = {BizConstants.ROLE_ADMIN,BizConstants.ROLE_OPERATOR,BizConstants.ROLE_TEACHER},logical = Logical.OR)
@SysLog("课程查询")
public PageResult<CourseListItemModel> list(@RequestBody QueryCourseModel param){
......@@ -45,7 +45,7 @@ public class CourseController {
}
@ApiOperation("获取课程详情")
@GetMapping("/{id}")
@RequiresRoles(value = {BizConstants.ROLE_ADMIN,BizConstants.ROLE_OPERATOR},logical = Logical.OR)
@RequiresRoles(value = {BizConstants.ROLE_ADMIN,BizConstants.ROLE_OPERATOR,BizConstants.ROLE_TEACHER},logical = Logical.OR)
@SysLog("获取课程详情")
public Result<CourseDetailModel> courseDetail(@PathVariable Long id){
return Result.succeed(courseService.getCourseDetail(id));
......
......@@ -58,7 +58,7 @@ public class TeacherController {
@SysLog(value = "删除讲师信息")
@RequiresRoles(value = {BizConstants.ROLE_ADMIN,BizConstants.ROLE_OPERATOR},logical = Logical.OR)
public Result<String> delete(@RequestBody List<Long> ids){
teacherService.removeByIds(ids);
teacherService.removeTeachers(ids);
return Result.succeed("ok");
}
@ApiOperation("查询讲师信息")
......
......@@ -50,6 +50,10 @@ public class TeacherPO extends BasePO {
* 头像
*/
private String avatarUrl;
/**
* 讲师帐号
*/
private String account;
/**
* 删除标识
......
......@@ -4,15 +4,22 @@ import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.qkdata.biz.enums.AccountStatusEnum;
import com.qkdata.biz.management.entity.TeacherPO;
import com.qkdata.biz.management.mapper.TeacherMapper;
import com.qkdata.biz.management.vo.QueryTeacherModel;
import com.qkdata.biz.management.vo.TeacherModel;
import com.qkdata.biz.sys.entity.SysUserPO;
import com.qkdata.biz.sys.service.SysUserService;
import com.qkdata.biz.sys.vo.SysUserModel;
import com.qkdata.common.base.enums.CodeEnum;
import com.qkdata.common.base.exception.BusinessException;
import com.qkdata.common.base.model.PageResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
......@@ -30,6 +37,10 @@ public class TeacherService extends ServiceImpl<TeacherMapper, TeacherPO> {
private String defaultNo = "00001";
private String codePrefix = "TH";
@Autowired
private SysUserService sysUserService;
@Transactional
public void saveModel(TeacherModel model) {
TeacherPO po = new TeacherPO();
BeanUtils.copyProperties(model,po);
......@@ -37,6 +48,26 @@ public class TeacherService extends ServiceImpl<TeacherMapper, TeacherPO> {
String teacherCode = getTeacherCode(dbMaxCode);
po.setCode(teacherCode);
super.save(po);
//添加讲师帐号
if (StrUtil.isNotBlank(po.getAccount())){
addTeacherAccount(po.getAccount(),po.getName());
}
}
/**
* 添加讲师帐号
* @param account
* @param name
*/
private void addTeacherAccount(String account, String name) {
SysUserModel model = new SysUserModel();
model.setUsername(account);
model.setPassword("123456");
model.setStatus(AccountStatusEnum.ENABLE);
model.setNickName(name);
model.setRoleIdList(Lists.newArrayList(6L));
sysUserService.saveUser(model);
}
private String findMaxNo() {
......@@ -58,6 +89,7 @@ public class TeacherService extends ServiceImpl<TeacherMapper, TeacherPO> {
return StrUtil.format("{}{}",codePrefix,defaultNo);
}
@Transactional
public void updateModel(TeacherModel model) {
TeacherPO po = getById(model.getId());
if (po == null){
......@@ -68,6 +100,10 @@ public class TeacherService extends ServiceImpl<TeacherMapper, TeacherPO> {
po.setIntroduce(model.getIntroduce());
po.setOrgId(model.getOrgId());
updateById(po);
//添加讲师帐号
if (StrUtil.isBlank(po.getAccount()) && StrUtil.isNotBlank(model.getAccount())){
addTeacherAccount(model.getAccount(),po.getName());
}
}
public PageResult<TeacherModel> queryPage(QueryTeacherModel param) {
......@@ -77,4 +113,14 @@ public class TeacherService extends ServiceImpl<TeacherMapper, TeacherPO> {
return PageResult.<TeacherModel>builder().code(CodeEnum.SUCCESS.getCode()).count(page.getTotal()).data(list).build();
}
@Transactional
public void removeTeachers(List<Long> ids) {
for (Long id : ids){
TeacherPO teacherPO = getById(id);
removeById(id);
//删除讲师帐号
sysUserService.removeByUsername(teacherPO.getAccount());
}
}
}
\ No newline at end of file
......@@ -38,6 +38,10 @@ public class TeacherModel {
* 简介
*/
private String introduce;
/**
* 讲师帐号
*/
private String account;
/**
* 课程数量
*/
......
......@@ -28,27 +28,27 @@ public class SysLoginController {
@ApiOperation("登陆")
@SysLog(value = "登陆",includeParam = false)
@SysLog(value = "登陆", includeParam = false)
@PostMapping("/login")
public Result<LoginUserInfo> login(@RequestBody @Valid LoginModel loginModel) throws JsonProcessingException {
LoginUserInfo loginUserInfo = shiroService.login(loginModel.getUsername(),loginModel.getPassword());
LoginUserInfo loginUserInfo = shiroService.login(loginModel.getUsername(), loginModel.getPassword());
hasPermission(loginUserInfo);
return Result.succeed(loginUserInfo);
}
private void hasPermission(LoginUserInfo loginUserInfo) {
List<SysRoleModel> roles = loginUserInfo.getRoles();
if (CollUtil.isEmpty(roles)){
if (CollUtil.isEmpty(roles)) {
throw new BusinessException("对不起,您没有权限");
}
boolean hasPermission = false;
for (SysRoleModel role : roles){
if (role.getCode().equals(BizConstants.ROLE_ADMIN) || role.getCode().equals(BizConstants.ROLE_OPERATOR)){
for (SysRoleModel role : roles) {
if (role.getCode().equals(BizConstants.ROLE_ADMIN) || role.getCode().equals(BizConstants.ROLE_OPERATOR) || role.getCode().equals(BizConstants.ROLE_TEACHER)) {
hasPermission = true;
break;
}
}
if (!hasPermission){
if (!hasPermission) {
throw new BusinessException("对不起,您没有权限");
}
}
......@@ -56,7 +56,7 @@ public class SysLoginController {
@ApiOperation("登出")
@SysLog("登出")
@GetMapping("/logout")
public Result<String> logout(){
public Result<String> logout() {
SecurityUtils.getSubject().logout();
return Result.succeed("ok");
}
......
......@@ -110,4 +110,13 @@ public class SysUserController {
sysUserService.removeUsers(Arrays.asList(userIds));
return Result.succeed("ok");
}
@ApiOperation("重置密码")
@SysLog("重置密码")
@GetMapping("/resetPwd")
@RequiresRoles(value = {BizConstants.ROLE_ADMIN,BizConstants.ROLE_OPERATOR},logical = Logical.OR)
public Result<String> resetPwd(@RequestParam Long id){
sysUserService.resetPwd(id);
return Result.succeed("ok");
}
}
......@@ -9,10 +9,7 @@ import com.qkdata.biz.common.BizConstants;
import com.qkdata.biz.enums.AccountStatusEnum;
import com.qkdata.biz.enums.AccountTypeEnum;
import com.qkdata.biz.enums.ProductTypeEnum;
import com.qkdata.biz.management.entity.OrgSurplusPO;
import com.qkdata.biz.management.entity.OrgUserReceiveRecordPO;
import com.qkdata.biz.management.entity.OrganizationPO;
import com.qkdata.biz.management.entity.UserCourseAuthPO;
import com.qkdata.biz.management.entity.*;
import com.qkdata.biz.management.service.OrgSurplusService;
import com.qkdata.biz.management.service.OrgUserReceiveRecordService;
import com.qkdata.biz.management.service.OrganizationService;
......@@ -308,4 +305,17 @@ public class SysUserService extends BaseServiceImpl<SysUserMapper, SysUserPO> {
updateById(oldUser);
}
public void removeByUsername(String username) {
remove(Wrappers.<SysUserPO>lambdaQuery().eq(SysUserPO::getUsername,username));
}
public void resetPwd(Long id) {
SysUserPO userPO = getById(id);
if(userPO == null){
throw new BusinessException("请求错误,用户不存在");
}
userPO.setPassword(new Sha256Hash("123456", userPO.getSalt()).toHex());
updateById(userPO);
}
}
CREATE TABLE `question` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) NULL COMMENT '用户ID',
`course_id` bigint(20) NULL COMMENT '课程ID',
`chapter_id` bigint(20) NULL COMMENT '章节ID',
`content` text NULL COMMENT '问题内容',
`create_time` datetime(0) NULL,
`update_time` datetime(0) NULL,
`status` VARCHAR(20) NULL COMMENT '状态:待回复、已回复、已完成',
PRIMARY KEY (`id`)
) COMMENT = '用户问题表';
CREATE TABLE `answer` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`question_id` bigint(20) NULL COMMENT '问题ID',
`user_id` bigint(20) NULL COMMENT '回复人ID',
`type` VARCHAR(20) NULL COMMENT '区分讲师回复还是用户回复',
`content` text NULL COMMENT '内容',
`create_time` datetime(0) NULL,
`update_time` datetime(0) NULL,
PRIMARY KEY (`id`)
) COMMENT = '问题回答表';
ALTER TABLE `teacher` ADD COLUMN `account` varchar(20) NULL COMMENT '讲师帐号' AFTER `avatar_url`;
INSERT INTO `sys_role` VALUES (6, 'TEACHER', '讲师', '2021-04-25 16:10:06', '2021-04-25 16:10:06');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment