Commit b8cae1c8 authored by leyboy's avatar leyboy

1.管理员逻辑修改

parent 6a04a8f7
This diff is collapsed.
......@@ -59,10 +59,10 @@ public class AdminController {
}
@DeleteMapping("/admin/{adminId}")
public ResponseEntity deleteOne(@PathVariable String adminId) {
@DeleteMapping("/admin/{adminName}")
public ResponseEntity deleteOne(@PathVariable String adminName) {
try {
int result = adminService.deleteAdmin(adminId);
int result = adminService.deleteAdmin(adminName);
if(result==1){
return GenResponse.success(String.valueOf(HttpStatus.OK.value()),
"删除成功",true);
......
......@@ -13,13 +13,13 @@ import java.util.List;
@Mapper
public interface AdminDao {
@Insert("insert into tb_admin(admin_name,admin_password,create_time) " +
"values(#{name},#{password},#{createTime})")
@Insert("insert into tb_admin(admin_id,admin_name,admin_password,create_time) " +
"values(#{adminId},#{name},#{password},#{createTime})")
int insertAdmin(Admin admin);
@Delete("delete from tb_admin where admin_id = #{adminId}")
int deleteAdmin(@Param("adminId") String adminId);
@Delete("delete from tb_admin where admin_name = #{adminName}")
int deleteAdmin(@Param("adminName") String adminName);
int updateAdmin(Admin admin);
......@@ -32,7 +32,8 @@ public interface AdminDao {
@Results({
@Result(column = "create_time", property = "createTime"),
@Result(column = "admin_name", property = "name"),
@Result(column = "admin_password", property = "password")
@Result(column = "admin_password", property = "password"),
@Result(column = "admin_id",property = "adminId")
}
)
Admin findAdminByAdminName(String adminName);
......
......@@ -20,6 +20,8 @@ public class Admin {
private transient String plainPassword;
private String adminId;
public Admin() {
}
......@@ -56,6 +58,14 @@ public class Admin {
}
public String getAdminId() {
return adminId;
}
public void setAdminId(String adminId) {
this.adminId = adminId;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("{");
......@@ -65,6 +75,8 @@ public class Admin {
.append(password).append('\"');
sb.append(",\"createTime\":\"")
.append(createTime).append('\"');
sb.append(",\"adminId\":\"")
.append(adminId).append('\"');
sb.append('}');
return sb.toString();
}
......
......@@ -36,6 +36,7 @@ public class AdminService {
public int insertAdmin(Admin admin) {
Admin findAdmin = adminDao.findAdminByAdminName(admin.getName());
if (findAdmin == null) {
admin.setAdminId(UUID.randomUUID());
admin.setCreateTime(new Date(System.currentTimeMillis()));
if (StringUtils.hasText(admin.getPlainPassword())) {
admin.setPassword(Base64Utils.encode(admin.getPlainPassword().getBytes(Charset.defaultCharset())));
......@@ -58,12 +59,13 @@ public class AdminService {
Admin findAdmin = adminDao.findAdminByAdminName(admin.getName());
if (findAdmin != null) {
if (StringUtils.hasText(admin.getPlainPassword())) {
admin.setPassword(Base64Utils.encode(admin.getPlainPassword().getBytes(Charset.defaultCharset())));
findAdmin.setPassword(Base64Utils.encode(admin.getPlainPassword().getBytes(Charset.defaultCharset())));
}
return adminDao.updateAdmin(admin);
return adminDao.updateAdmin(findAdmin);
}else{
//没有查询到,更新失败
return -1;
}
//没有查询到,更新失败
return -1;
}
......
......@@ -15,13 +15,16 @@
<update id="updateAdmin" parameterType="com.adc.da.znks.entity.Admin">
update tb_admin
<set>
<if test="name != null">
<if test="name != null and name != ''">
admin_name = #{name},
</if>
<if test="password != null">
<if test="password != null and password != ''">
admin_password = #{password},
</if>
</set>
<where>
admin_id = #{adminId}
</where>
</update>
<select id="listAdminsByCondition" parameterType="object" resultMap="BaseResultMap">
......
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