Commit a820efe6 by 宋振民

feat:后台管理新增管理员权限

parent 5c523da6
-- 添加管理员权限字段
ALTER TABLE `sys_user`
ADD COLUMN `IS_ADMIN` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否是管理员' AFTER `MAC_ADDRESS`;
update sys_user set is_admin=1 where USER_CODE in('hospital','admin');
\ No newline at end of file
......@@ -87,6 +87,14 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
......
......@@ -79,7 +79,8 @@ public class Result<T> {
SUCCESS(1,"成功","success"),
INVALID_TOKEN(401,"无效的TOKEN","invalid token"),
ERROR(400,"错误","error"),
USERERROR(2,"账号或密码错误","wrong account or password");
USERERROR(2,"账号或密码错误","wrong account or password"),
NO_PERMISSION(3,"非管理员账号","no permission");
private int code;
private String cnMessage;
private String enMessage;
......
......@@ -31,7 +31,10 @@ public class LoginController {
LoginService.LoginInfo loginInfo = loginServiceImpl.login(
codeAndPwd.getLoginName(),codeAndPwd.getPassword(),ip);
if(loginInfo.getUser() == null){
return Result.error(Result.ErrorCode.USERERROR);
return Result.error(Result.ErrorCode.USERERROR.getCnMessage());
}
if(loginInfo.getUser() != null && !loginInfo.getUser().getIsAdmin()){
return Result.error(Result.ErrorCode.NO_PERMISSION.getCnMessage());
}
return Result.success(loginInfo);
}
......
package com.hs.admin.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Date;
public class SysUser {
......@@ -33,6 +35,8 @@ public class SysUser {
private String lastIp;
private boolean isAdmin;
public Integer getId() {
return id;
}
......@@ -152,4 +156,12 @@ public class SysUser {
public void setLastIp(String lastIp) {
this.lastIp = lastIp;
}
public boolean getIsAdmin() {
return isAdmin;
}
public void setIsAdmin(boolean isAdmin) {
this.isAdmin = isAdmin;
}
}
\ No newline at end of file
......@@ -37,4 +37,16 @@ public class AddUserReq {
@ApiModelProperty(value = "机构ID", required = true)
@NotNull(message = "机构ID 参数必传")
private List<Long> org;
@ApiModelProperty(value = "是否是管理员", required = true)
@NotNull(message = "是否是管理员 参数必传")
private boolean isAdmin;
public boolean getIsAdmin() {
return isAdmin;
}
public void setIsAdmin(boolean isAdmin) {
this.isAdmin = isAdmin;
}
}
......@@ -41,4 +41,16 @@ public class UpdateUserReq {
@ApiModelProperty(value = "机构ID", required = true)
@NotNull(message = "机构ID 参数必传")
private List<Long> org;
@ApiModelProperty(value = "是否是管理员", required = true)
@NotNull(message = "是否是管理员 参数必传")
private boolean isAdmin;
public boolean getIsAdmin() {
return isAdmin;
}
public void setIsAdmin(boolean isAdmin) {
this.isAdmin = isAdmin;
}
}
......@@ -23,6 +23,10 @@ public class UserReq {
this.userName = userName;
}
public void setPage(PageRequest page) {
this.page = page;
}
public PageRequest getPage() {
return page;
}
......
......@@ -56,6 +56,7 @@ public class UserServiceImpl implements UserService {
sysUser.setCreateDate(new Date());
sysUser.setCreateUserid(userId);
sysUser.setState((short) StateType.ON.getValue());
sysUser.setIsAdmin(user.getIsAdmin());
sysUserMapper.insert(sysUser);
//添加角色信息
......@@ -95,6 +96,7 @@ public class UserServiceImpl implements UserService {
sysUser.setIdcard(user.getIdcard());
sysUser.setMobile(user.getMobile());
sysUser.setSex(user.getSex());
sysUser.setIsAdmin(user.getIsAdmin());
sysUserMapper.updateByPrimaryKey(sysUser);
//修改角色信息
......
......@@ -17,6 +17,7 @@
<result column="ERROR_TIME" jdbcType="TIMESTAMP" property="errorTime"/>
<result column="LAST_TIME" jdbcType="TIMESTAMP" property="lastTime"/>
<result column="LAST_IP" jdbcType="VARCHAR" property="lastIp"/>
<result column="IS_ADMIN" jdbcType="BOOLEAN" property="isAdmin"/>
</resultMap>
<resultMap id="SysUserList" extends="BaseResultMap" type="com.hs.admin.model.respmodel.SysUserList">
<result column="ROLE_ID" jdbcType="INTEGER" property="roleId"/>
......@@ -37,12 +38,12 @@
USER_CODE, USER_NAME, `PASSWORD`,
IDCARD, SEX, MOBILE,
PAGE_COUNT, ERROR_COUNT, ERROR_TIME,
LAST_TIME, LAST_IP,MAC_ADDRESS)
LAST_TIME, LAST_IP,MAC_ADDRESS,IS_ADMIN)
values (#{createDate,jdbcType=TIMESTAMP}, #{createUserid,jdbcType=DECIMAL}, #{state,jdbcType=DECIMAL},
#{userCode,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
#{idcard,jdbcType=VARCHAR}, #{sex,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR},
#{pageCount,jdbcType=DECIMAL}, #{errorCount,jdbcType=DECIMAL}, #{errorTime,jdbcType=TIMESTAMP},
#{lastTime,jdbcType=TIMESTAMP}, #{lastIp,jdbcType=VARCHAR},'EO-D5-5E-6C-4D-7B')
#{lastTime,jdbcType=TIMESTAMP}, #{lastIp,jdbcType=VARCHAR},'EO-D5-5E-6C-4D-7B',#{isAdmin,jdbcType=BOOLEAN})
</insert>
<update id="updateByPrimaryKey" parameterType="com.hs.admin.model.SysUser">
update sys_user
......@@ -59,7 +60,8 @@
ERROR_COUNT = #{errorCount,jdbcType=DECIMAL},
ERROR_TIME = #{errorTime,jdbcType=TIMESTAMP},
LAST_TIME = #{lastTime,jdbcType=TIMESTAMP},
LAST_IP = #{lastIp,jdbcType=VARCHAR}
LAST_IP = #{lastIp,jdbcType=VARCHAR},
IS_ADMIN = #{isAdmin,jdbcType=VARCHAR}
where ID = #{id,jdbcType=INTEGER}
</update>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
......@@ -77,7 +79,8 @@
ERROR_COUNT,
ERROR_TIME,
LAST_TIME,
LAST_IP
LAST_IP,
IS_ADMIN
from sys_user
where ID = #{id,jdbcType=INTEGER}
</select>
......@@ -96,7 +99,8 @@
ERROR_COUNT,
ERROR_TIME,
LAST_TIME,
LAST_IP
LAST_IP,
IS_ADMIN
from sys_user
</select>
<select id="selectByCode" resultMap="BaseResultMap">
......@@ -114,7 +118,8 @@
ERROR_COUNT,
ERROR_TIME,
LAST_TIME,
LAST_IP
LAST_IP,
IS_ADMIN
from SYS_USER
where USER_CODE = #{userCode,jdbcType=VARCHAR}
and `STATE` != 0
......
package com.hs.admin;
import org.junit.jupiter.api.Test;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
@SpringBootTest
@SpringBootApplication
@MapperScan("com.hs.admin.mapper")
@ComponentScan(basePackages = {"com.hs.common.config", "com.hs.admin"})
class HsAdminApplicationTests {
@Test
......
package com.hs.admin;
import com.hs.admin.common.base.PageRequest;
import com.hs.admin.common.base.PageResult;
import com.hs.admin.model.SysUser;
import com.hs.admin.model.reqmodel.UpdateUserReq;
import com.hs.admin.model.reqmodel.UserReq;
import com.hs.admin.model.respmodel.SysUserList;
import com.hs.admin.service.LoginService;
import com.hs.admin.service.UserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.ArrayList;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = HsAdminApplicationTests.class)
public class UserServiceTest {
@Autowired
private UserService userService;
@Autowired
private LoginService loginService;
@Test
public void testInfo() {
SysUserList info = userService.info(39);
System.out.println(info);
/*UserReq.GetUserReq userReq = new UserReq.GetUserReq();
PageRequest page = new PageRequest();
page.setPageNum(1);
page.setPageSize(10);
userReq.setUserName("hospital");
userReq.setPage(page);
PageResult all = userService.getAllByPage(userReq);
System.out.println(all);*/
}
@Test
public void testLogin() {
String loginName = "ddd";
String password = "1231";
String ip = "8.8.8.8";
LoginService.LoginInfo loginInfo = loginService.login(loginName, password, ip);
System.out.println(loginInfo);
}
@Test
public void testUpdate() {
UpdateUserReq user = new UpdateUserReq();
user.setUserId(38);
user.setPassword("123");
user.setUserCode("ddd");
user.setUserName("ddd");
user.setRoleId(2L);
user.setIsAdmin(true);
ArrayList orgs = new ArrayList();
orgs.add(1L);
orgs.add(60L);
user.setOrg(orgs);
userService.updateUser(user);
}
}
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