商城系统运营员工管理;商城角色管理
This commit is contained in:
parent
d9c152cfc7
commit
0c55cd317f
@ -177,7 +177,7 @@ public interface Constants {
|
||||
/**
|
||||
* 超级管理员
|
||||
*/
|
||||
String SUPER_ADMIN_VALUE = "superAdmin";
|
||||
String SUPER_ADMIN_VALUE = "SuperAdmin";
|
||||
|
||||
/**
|
||||
* 所有权限
|
||||
|
||||
@ -31,7 +31,7 @@ spring:
|
||||
max-file-size: 1024MB
|
||||
max-request-size: 300MB
|
||||
profiles:
|
||||
active: dev,mall,system
|
||||
active: dev,mall,system,jambox,sdk
|
||||
datasource:
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
||||
@ -0,0 +1,44 @@
|
||||
package com.cpop.mall.business.bo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Description: 修改用户密码bo
|
||||
* date: 2023/5/12 16:01
|
||||
*
|
||||
* @Author ST
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@ApiModel(value = "ModifyUserPasswordBo对象", description = "修改用户密码bo")
|
||||
public class ModifyUserPasswordBo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@NotBlank(message = "用户id不能为空")
|
||||
@ApiModelProperty(value = "用户id",required = true)
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 旧密码
|
||||
*/
|
||||
@NotBlank(message = "旧密码不能为空")
|
||||
@ApiModelProperty(value = "旧密码",required = true)
|
||||
private String oldPassword;
|
||||
|
||||
/**
|
||||
* 新密码
|
||||
*/
|
||||
@NotBlank(message = "新密码不能为空")
|
||||
@ApiModelProperty(value = "新密码",required = true)
|
||||
private String newPassword;
|
||||
}
|
||||
118
Cpop-Mall/src/main/java/com/cpop/mall/business/bo/StaffBo.java
Normal file
118
Cpop-Mall/src/main/java/com/cpop/mall/business/bo/StaffBo.java
Normal file
@ -0,0 +1,118 @@
|
||||
package com.cpop.mall.business.bo;
|
||||
|
||||
import com.cpop.core.annontation.StringArrayConvert;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 员工表Bo
|
||||
*
|
||||
* @author DB.lost
|
||||
* @since 2023-05-11
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@ApiModel(value = "Staff对象", description = "员工表")
|
||||
public class StaffBo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@ApiModelProperty("主键")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 姓名不能为空
|
||||
*/
|
||||
@NotBlank(message = "姓名不能为空")
|
||||
@ApiModelProperty("姓名")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 品牌
|
||||
*/
|
||||
@ApiModelProperty(value = "品牌")
|
||||
private String brandId;
|
||||
|
||||
/**
|
||||
* 角色品牌id
|
||||
*/
|
||||
@ApiModelProperty("角色品牌id")
|
||||
private String roleBrandId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@ApiModelProperty("用户id")
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@NotBlank(message = "用户名不能为空")
|
||||
@ApiModelProperty(value = "用户名",required = true)
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@NotBlank(message = "密码不能为空")
|
||||
@ApiModelProperty(value = "密码",required = true)
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
@NotBlank(message = "昵称不能为空")
|
||||
@ApiModelProperty(value = "昵称",required = true)
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
@ApiModelProperty(value = "邮箱")
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
@NotBlank(message = "手机号不能为空")
|
||||
@ApiModelProperty(value = "手机号",required = true)
|
||||
private String phoneNumber;
|
||||
|
||||
/**
|
||||
* 性别(0:男;1:女)
|
||||
*/
|
||||
@NotNull(message = "性别不能为空")
|
||||
@ApiModelProperty(value = "性别(0:男;1:女)",required = true)
|
||||
private Boolean sex;
|
||||
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
@ApiModelProperty(value = "头像")
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 状态(0:停用;1:启用)
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
@ApiModelProperty(value = "状态(0:停用;1:启用)",required = true)
|
||||
private Boolean status;
|
||||
|
||||
/**
|
||||
* 角色id
|
||||
*/
|
||||
@NotBlank(message = "角色id不能为空")
|
||||
@ApiModelProperty(value = "角色id",required = true)
|
||||
private String roleId;
|
||||
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package com.cpop.mall.business.bo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author DB
|
||||
* @createTime 2023/10/20 11:08
|
||||
* @description
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@ApiModel(value = "商城员工分页请求对象")
|
||||
public class StaffPageBo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
@ApiModelProperty("姓名")
|
||||
private String name;
|
||||
}
|
||||
@ -1,6 +1,25 @@
|
||||
package com.cpop.mall.business.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cpop.common.constant.Constants;
|
||||
import com.cpop.core.annontation.OperationLog;
|
||||
import com.cpop.core.base.R;
|
||||
import com.cpop.core.base.enums.OperationLogEnum;
|
||||
import com.cpop.core.utils.SecurityUtils;
|
||||
import com.cpop.core.utils.SpringUtils;
|
||||
import com.cpop.mall.business.bo.ModifyUserPasswordBo;
|
||||
import com.cpop.mall.business.bo.StaffBo;
|
||||
import com.cpop.mall.business.bo.StaffPageBo;
|
||||
import com.cpop.mall.business.entity.RoleBrand;
|
||||
import com.cpop.mall.business.service.RoleBrandService;
|
||||
import com.cpop.mall.business.vo.StaffInfoVo;
|
||||
import com.cpop.mall.business.vo.StaffPageVo;
|
||||
import com.cpop.system.business.service.RoleService;
|
||||
import com.cpop.system.business.vo.RoleVo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@ -18,6 +37,9 @@ import io.swagger.annotations.ApiParam;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import static com.cpop.mall.business.entity.table.RoleBrandTableDef.ROLE_BRAND;
|
||||
import static com.cpop.system.business.entity.table.RoleTableDef.ROLE;
|
||||
|
||||
/**
|
||||
* 员工表 控制层。
|
||||
*
|
||||
@ -33,74 +55,130 @@ public class StaffController {
|
||||
private StaffService staffService;
|
||||
|
||||
/**
|
||||
* 添加员工表。
|
||||
*
|
||||
* @param staff 员工表
|
||||
* @return {@code true} 添加成功,{@code false} 添加失败
|
||||
* @descriptions 查询员工分页列表
|
||||
* @author DB
|
||||
* @date 2023/09/07 18:07
|
||||
* @param bo 请求参数
|
||||
* @return R<Page<SysStaffPageVo>>
|
||||
*/
|
||||
@PostMapping("/save")
|
||||
@ApiOperation("保存员工表")
|
||||
public boolean save(@RequestBody @ApiParam("员工表") Staff staff) {
|
||||
return staffService.save(staff);
|
||||
@PreAuthorize("@aps.hasPermission('system:account:list')")
|
||||
@ApiOperation("查询员工分页列表")
|
||||
@GetMapping("/getStaffPageList")
|
||||
public R<Page<StaffPageVo>> getStaffPageList(StaffPageBo bo) {
|
||||
Page<StaffPageVo> pageVo = staffService.getStaffPageList(bo);
|
||||
return R.ok(pageVo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据主键删除员工表。
|
||||
*
|
||||
* @descriptions 新增员工
|
||||
* @author DB
|
||||
* @date 2023/09/08 14:04
|
||||
* @param bo 请求参数
|
||||
* @return com.jambox.core.base.R<java.lang.Void>
|
||||
*/
|
||||
@PreAuthorize("@aps.hasPermission('system:account:insert')")
|
||||
@ApiOperation("新增员工")
|
||||
@PostMapping("/insertStaff")
|
||||
public R<Void> insertStaff(@RequestBody @Validated StaffBo bo) {
|
||||
staffService.insertStaff(bo);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 修改员工
|
||||
* @author DB
|
||||
* @date 2023/09/08 15:20
|
||||
* @param bo 请求参数
|
||||
* @return com.jambox.core.base.R<java.lang.Void>
|
||||
*/
|
||||
@PreAuthorize("@aps.hasPermission('system:account:update')")
|
||||
@ApiOperation("修改员工")
|
||||
@PutMapping("/updateStaff")
|
||||
public R<Void> updateStaff(@RequestBody @Validated StaffBo bo) {
|
||||
staffService.updateStaff(bo);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 删除员工
|
||||
* @author DB
|
||||
* @date 2023/09/12 16:57
|
||||
* @param id 主键
|
||||
* @return {@code true} 删除成功,{@code false} 删除失败
|
||||
* @return com.jambox.core.base.R<java.lang.Void>
|
||||
*/
|
||||
@DeleteMapping("/remove/{id}")
|
||||
@ApiOperation("根据主键员工表")
|
||||
public boolean remove(@PathVariable @ApiParam("员工表主键") Serializable id) {
|
||||
return staffService.removeById(id);
|
||||
@PreAuthorize("@aps.hasPermission('system:account:remove')")
|
||||
@ApiOperation("删除员工")
|
||||
@DeleteMapping("/removeStaffById/{id}")
|
||||
public R<Void> removeStaffById(@PathVariable String id) {
|
||||
staffService.removeStaffById(id);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据主键更新员工表。
|
||||
*
|
||||
* @param staff 员工表
|
||||
* @return {@code true} 更新成功,{@code false} 更新失败
|
||||
* 获取所有角色信息
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@ApiOperation("根据主键更新员工表")
|
||||
public boolean update(@RequestBody @ApiParam("员工表主键") Staff staff) {
|
||||
return staffService.updateById(staff);
|
||||
@ApiOperation("获取所有角色信息")
|
||||
@GetMapping("/getAllRoleList")
|
||||
public R<List<RoleVo>> getAllSysRoleList() {
|
||||
//获取当前登陆用户所在品牌
|
||||
JSONObject loginStaffInfo = SecurityUtils.getInstance().getLoginStaffInfo();
|
||||
String roleBrandId = loginStaffInfo.getString("roleBrandId");
|
||||
RoleBrandService roleBrandService = SpringUtils.getBean(RoleBrandService.class);
|
||||
RoleBrand roleBrand = roleBrandService.getById(roleBrandId);
|
||||
List<RoleVo> list = roleBrandService.listAs(QueryWrapper.create()
|
||||
.from(ROLE_BRAND)
|
||||
.leftJoin(ROLE).on(ROLE.ID.eq(ROLE_BRAND.ROLE_ID))
|
||||
.where(ROLE.STATUS.eq(true))
|
||||
.and(ROLE_BRAND.BRAND_ID.eq(roleBrand.getBrandId()))
|
||||
.and(ROLE.ROLE_VALUE.ne(Constants.SUPER_ADMIN_VALUE))
|
||||
.orderBy(ROLE.ORDER_NO.asc())
|
||||
, RoleVo.class);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有员工表。
|
||||
*
|
||||
* @return 所有数据
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("查询所有员工表")
|
||||
public List<Staff> list() {
|
||||
return staffService.list();
|
||||
* @Description: 用户名是否存在
|
||||
* @param username 用户名
|
||||
* @param id 主键
|
||||
* @return: R<Void>
|
||||
* @Author: DB
|
||||
* @Date: 2023/5/11 10:09
|
||||
**/
|
||||
@ApiOperation("用户名是否存在")
|
||||
@GetMapping("/isAccountExist")
|
||||
public R<Void> isAccountExist(@ApiParam("用户名") String username, @ApiParam("userId") String id) {
|
||||
staffService.isAccountExist(username, id);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据员工表主键获取详细信息。
|
||||
*
|
||||
* @param id 员工表主键
|
||||
* @return 员工表详情
|
||||
*/
|
||||
@GetMapping("/getInfo/{id}")
|
||||
@ApiOperation("根据主键获取员工表")
|
||||
public Staff getInfo(@PathVariable @ApiParam("员工表主键") Serializable id) {
|
||||
return staffService.getById(id);
|
||||
* @Description: 获取员工信息
|
||||
* @param id 主键
|
||||
* @return: R<StaffVo>
|
||||
* @Author: DB
|
||||
* @Date: 2023/5/17 10:33
|
||||
**/
|
||||
@PreAuthorize("@aps.hasPermission('system:account:info')")
|
||||
@ApiOperation("获取员工信息")
|
||||
@GetMapping("/getStaffInfo/{id}")
|
||||
public R<StaffInfoVo> getStaffInfo(@PathVariable String id) {
|
||||
StaffInfoVo staffInfo = staffService.getStaffInfo(id);
|
||||
return R.ok(staffInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询员工表。
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @return 分页对象
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("分页查询员工表")
|
||||
public Page<Staff> page(@ApiParam("分页信息") Page<Staff> page) {
|
||||
return staffService.page(page);
|
||||
* @Description: 修改系统用户密码
|
||||
* @param bo 请求参数
|
||||
* @return: AjaxResult<Void>
|
||||
* @Author: DB
|
||||
* @Date: 2023/5/12 16:00
|
||||
**/
|
||||
@PreAuthorize("@aps.hasPermission('system:account:update')")
|
||||
@ApiOperation("修改系统用户密码")
|
||||
@PutMapping("/modifyUserPassword")
|
||||
public R<Void> modifyUserPassword(@Validated @RequestBody ModifyUserPasswordBo bo) {
|
||||
staffService.modifyUserPassword(bo);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,11 @@
|
||||
package com.cpop.mall.business.service;
|
||||
|
||||
import com.cpop.mall.business.bo.ModifyUserPasswordBo;
|
||||
import com.cpop.mall.business.bo.StaffBo;
|
||||
import com.cpop.mall.business.bo.StaffPageBo;
|
||||
import com.cpop.mall.business.vo.StaffInfoVo;
|
||||
import com.cpop.mall.business.vo.StaffPageVo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.cpop.mall.business.entity.Staff;
|
||||
|
||||
@ -11,4 +17,67 @@ import com.cpop.mall.business.entity.Staff;
|
||||
*/
|
||||
public interface StaffService extends IService<Staff> {
|
||||
|
||||
/**
|
||||
* @descriptions 查询员工分页列表
|
||||
* @author DB
|
||||
* @date 2023/10/20 11:12
|
||||
* @param bo 请求参数
|
||||
* @return: com.mybatisflex.core.paginate.Page<com.cpop.mall.business.vo.StaffPageVo>
|
||||
*/
|
||||
Page<StaffPageVo> getStaffPageList(StaffPageBo bo);
|
||||
|
||||
/**
|
||||
* @descriptions 新增员工
|
||||
* @author DB
|
||||
* @date 2023/10/20 11:24
|
||||
* @param bo 请求参数
|
||||
* @return: void
|
||||
*/
|
||||
void insertStaff(StaffBo bo);
|
||||
|
||||
/**
|
||||
* @descriptions 修改员工
|
||||
* @author DB
|
||||
* @date 2023/10/20 11:36
|
||||
* @param bo 请求参数
|
||||
* @return: void
|
||||
*/
|
||||
void updateStaff(StaffBo bo);
|
||||
|
||||
/**
|
||||
* @descriptions 删除员工
|
||||
* @author DB
|
||||
* @date 2023/10/20 11:44
|
||||
* @param id 主键
|
||||
* @return: void
|
||||
*/
|
||||
void removeStaffById(String id);
|
||||
|
||||
/**
|
||||
* @descriptions 用户名是否存在
|
||||
* @author DB
|
||||
* @date 2023/10/20 11:55
|
||||
* @param username 用户名
|
||||
* @param id 主键
|
||||
* @return: void
|
||||
*/
|
||||
void isAccountExist(String username, String id);
|
||||
|
||||
/**
|
||||
* @descriptions 获取员工信息
|
||||
* @author DB
|
||||
* @date 2023/10/20 12:00
|
||||
* @param id 主键
|
||||
* @return: com.cpop.mall.business.vo.StaffInfoVo
|
||||
*/
|
||||
StaffInfoVo getStaffInfo(String id);
|
||||
|
||||
/**
|
||||
* @descriptions 修改系统用户密码
|
||||
* @author DB
|
||||
* @date 2023/10/20 12:04
|
||||
* @param bo 请求体
|
||||
* @return: void
|
||||
*/
|
||||
void modifyUserPassword(ModifyUserPasswordBo bo);
|
||||
}
|
||||
|
||||
@ -32,6 +32,7 @@ import static com.cpop.mall.business.entity.table.StaffTableDef.STAFF;
|
||||
import static com.cpop.system.business.entity.table.MenuTableDef.MENU;
|
||||
import static com.cpop.system.business.entity.table.RoleMenuTableDef.ROLE_MENU;
|
||||
import static com.cpop.system.business.entity.table.RoleTableDef.ROLE;
|
||||
import static com.mybatisflex.core.query.QueryMethods.distinct;
|
||||
import static com.mybatisflex.core.query.QueryMethods.groupConcat;
|
||||
|
||||
/**
|
||||
@ -58,7 +59,7 @@ public class RoleBrandServiceImpl extends ServiceImpl<RoleBrandMapper, RoleBrand
|
||||
PageDomain pageDomain = SqlUtils.getInstance().getPageDomain();
|
||||
return this.mapper.paginateAs(pageDomain.getPageNum(), pageDomain.getPageSize(),
|
||||
QueryWrapper.create()
|
||||
.select(ROLE_BRAND.ALL_COLUMNS)
|
||||
.select(distinct(ROLE_BRAND.ALL_COLUMNS))
|
||||
//角色信息
|
||||
.select(ROLE.ROLE_NAME, ROLE.ROLE_VALUE, ROLE.STATUS, ROLE.REMARK, ROLE.ORDER_NO, ROLE.CREATE_TIME)
|
||||
.select(groupConcat(MENU.ID).as(MallRolePageVo::getMenuIds))
|
||||
@ -69,10 +70,10 @@ public class RoleBrandServiceImpl extends ServiceImpl<RoleBrandMapper, RoleBrand
|
||||
//角色菜单中甲表
|
||||
.leftJoin(ROLE_MENU).on(ROLE_MENU.ROLE_ID.eq(ROLE_BRAND.ROLE_ID))
|
||||
.leftJoin(MENU).on(MENU.ID.eq(ROLE_MENU.MENU_ID))
|
||||
.where(STAFF.ID.eq(staffInfo.getString("id")))
|
||||
.where(ROLE_BRAND.BRAND_ID.eq(staffInfo.getString("roleBrandId")))
|
||||
.and(ROLE.ROLE_NAME.like(bo.getRoleName()))
|
||||
.and(ROLE.STATUS.eq(bo.getStatus()))
|
||||
.groupBy(ROLE.ID)
|
||||
.groupBy(ROLE_BRAND.ID)
|
||||
.orderBy(ROLE.ORDER_NO.asc())
|
||||
, MallRolePageVo.class);
|
||||
}
|
||||
|
||||
@ -1,10 +1,47 @@
|
||||
package com.cpop.mall.business.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cpop.common.constant.Constants;
|
||||
import com.cpop.common.utils.StringUtils;
|
||||
import com.cpop.common.utils.bean.BeanUtils;
|
||||
import com.cpop.core.base.entity.LoginUser;
|
||||
import com.cpop.core.base.entity.PageDomain;
|
||||
import com.cpop.core.base.entity.loginInfo.MallStaffLoginInfo;
|
||||
import com.cpop.core.base.entity.loginInfo.OamStaffLoginInfo;
|
||||
import com.cpop.core.base.enums.UserType;
|
||||
import com.cpop.core.base.exception.ServiceException;
|
||||
import com.cpop.core.base.table.SysUser;
|
||||
import com.cpop.core.service.CoreService;
|
||||
import com.cpop.core.service.RedisService;
|
||||
import com.cpop.core.utils.*;
|
||||
import com.cpop.core.utils.sql.SqlUtils;
|
||||
import com.cpop.core.utils.uuid.IdUtils;
|
||||
import com.cpop.mall.business.bo.ModifyUserPasswordBo;
|
||||
import com.cpop.mall.business.bo.StaffBo;
|
||||
import com.cpop.mall.business.bo.StaffPageBo;
|
||||
import com.cpop.mall.business.entity.RoleBrand;
|
||||
import com.cpop.mall.business.service.RoleBrandService;
|
||||
import com.cpop.mall.business.vo.StaffInfoVo;
|
||||
import com.cpop.mall.business.vo.StaffPageVo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.row.DbChain;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.cpop.mall.business.entity.Staff;
|
||||
import com.cpop.mall.business.mapper.StaffMapper;
|
||||
import com.cpop.mall.business.service.StaffService;
|
||||
import org.springframework.security.crypto.bcrypt.BCrypt;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static com.cpop.core.base.table.table.SysUserTableDef.SYS_USER;
|
||||
import static com.cpop.mall.business.entity.table.RoleBrandTableDef.ROLE_BRAND;
|
||||
import static com.cpop.mall.business.entity.table.StaffTableDef.STAFF;
|
||||
import static com.cpop.system.business.entity.table.RoleTableDef.ROLE;
|
||||
import static com.mybatisflex.core.query.QueryMethods.distinct;
|
||||
import static com.mybatisflex.core.query.QueryMethods.groupConcat;
|
||||
|
||||
/**
|
||||
* 员工表 服务层实现。
|
||||
@ -15,4 +52,255 @@ import org.springframework.stereotype.Service;
|
||||
@Service("staffService")
|
||||
public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements StaffService {
|
||||
|
||||
/**
|
||||
* @descriptions 查询员工分页列表
|
||||
* @author DB
|
||||
* @date 2023/10/20 11:12
|
||||
* @param bo 请求参数
|
||||
* @return: com.mybatisflex.core.paginate.Page<com.cpop.mall.business.vo.StaffPageVo>
|
||||
*/
|
||||
@Override
|
||||
public Page<StaffPageVo> getStaffPageList(StaffPageBo bo) {
|
||||
PageDomain pageDomain = SqlUtils.getInstance().getPageDomain();
|
||||
return this.mapper.paginateAs(pageDomain.getPageNum(), pageDomain.getPageSize()
|
||||
, QueryWrapper.create()
|
||||
//去重
|
||||
.select(distinct(STAFF.ALL_COLUMNS))
|
||||
.select(SYS_USER.USER_NAME,SYS_USER.NICK_NAME, SYS_USER.EMAIL, SYS_USER.PHONE_NUMBER, SYS_USER.SEX, SYS_USER.AVATAR, SYS_USER.STATUS, SYS_USER.PASSWORD)
|
||||
.select(ROLE.ROLE_NAME)
|
||||
.from(STAFF)
|
||||
.leftJoin(SYS_USER).on(SYS_USER.ID.eq(STAFF.USER_ID))
|
||||
//关键中间表
|
||||
.leftJoin(ROLE_BRAND).on(ROLE_BRAND.ID.eq(STAFF.ROLE_BRAND_ID))
|
||||
.leftJoin(ROLE).on(ROLE.ID.eq(ROLE_BRAND.ROLE_ID))
|
||||
//姓名
|
||||
.and(STAFF.NAME.like(bo.getName()))
|
||||
.and(SYS_USER.USER_NAME.ne(Constants.SUPER_ADMIN).or(SYS_USER.USER_NAME.isNull()))
|
||||
.groupBy(STAFF.ID)
|
||||
, StaffPageVo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 新增员工
|
||||
* @author DB
|
||||
* @date 2023/10/20 11:24
|
||||
* @param bo 请求参数
|
||||
* @return: void
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void insertStaff(StaffBo bo) {
|
||||
//先添加用户信息
|
||||
SysUser sysUser;
|
||||
if (validatedUserInfo(bo)) {
|
||||
throw new ServiceException(MessageUtils.message("i18n_alert_userOrPhoneOrEmailIsExist"));
|
||||
} else {
|
||||
//用户名-手机-邮箱都需要做唯一校验
|
||||
sysUser = BeanUtils.mapToClass(bo, SysUser.class);
|
||||
//解密与重设密码
|
||||
decryptAndResetPasswords(sysUser);
|
||||
sysUser.setId(IdUtils.fastSimpleUUID());
|
||||
//获取当前创建人员信息
|
||||
LoginUser loginUser = SecurityUtils.getInstance().getLoginUser();
|
||||
sysUser.setCreateUserId(loginUser.getUserId());
|
||||
sysUser.setUpdateUserId(loginUser.getUserId());
|
||||
sysUser.setUserType(UserType.MALL_USER);
|
||||
SpringUtils.getBean(CoreService.class).insertSysUser(sysUser);
|
||||
}
|
||||
//再添加员工信息
|
||||
RoleBrand roleBrand = new RoleBrand();
|
||||
Staff staff = new Staff();
|
||||
RoleBrandService roleBrandService = SpringUtils.getBean(RoleBrandService.class);
|
||||
//如果有传入品牌(超级管理员初始化管理账户)
|
||||
if (StringUtils.isNotBlank(bo.getBrandId())) {
|
||||
roleBrand.setBrandId(bo.getBrandId());
|
||||
} else {
|
||||
//获取当前用户信息
|
||||
JSONObject loginStaffInfo = SecurityUtils.getInstance().getLoginStaffInfo();
|
||||
RoleBrand roleBrandId = roleBrandService.queryChain().where(ROLE_BRAND.ID.eq(loginStaffInfo.get("roleBrandId"))).one();
|
||||
roleBrand.setBrandId(roleBrandId.getBrandId());
|
||||
}
|
||||
roleBrand.setRoleId(bo.getRoleId());
|
||||
//设置中间表
|
||||
roleBrandService.save(roleBrand);
|
||||
staff.setUserId(sysUser.getId())
|
||||
.setName(bo.getName())
|
||||
.setRoleBrandId(roleBrand.getId());
|
||||
this.save(staff);
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 修改员工
|
||||
* @author DB
|
||||
* @date 2023/10/20 11:36
|
||||
* @param bo 请求参数
|
||||
* @return: void
|
||||
*/
|
||||
@Override
|
||||
public void updateStaff(StaffBo bo) {
|
||||
//先修改系统用户信息 用户名-手机-邮箱都需要做唯一校验
|
||||
if (validatedUserInfo(bo)) {
|
||||
throw new ServiceException(MessageUtils.message("i18n_alert_userOrPhoneOrEmailIsExist"));
|
||||
} else {
|
||||
SysUser sysUser = BeanUtils.mapToClass(bo, SysUser.class);
|
||||
sysUser.setId(bo.getUserId());
|
||||
//密码在这里不做修改
|
||||
sysUser.setPassword(null);
|
||||
sysUser.setUpdateUserId(SecurityUtils.getInstance().getLoginUser().getUserId());
|
||||
sysUser.setUpdateTime(LocalDateTime.now());
|
||||
SpringUtils.getBean(CoreService.class).updateSysUser(sysUser);
|
||||
}
|
||||
//角色品牌
|
||||
RoleBrandService roleBrandService = SpringUtils.getBean(RoleBrandService.class);
|
||||
RoleBrand roleBrand = roleBrandService.getById(bo.getRoleBrandId());
|
||||
roleBrand.setRoleId(bo.getRoleId());
|
||||
roleBrandService.updateById(roleBrand);
|
||||
//再修改员工信息
|
||||
Staff staff = new Staff();
|
||||
staff.setName(bo.getName())
|
||||
.setId(bo.getId());
|
||||
this.updateById(staff);
|
||||
//获取缓存信息
|
||||
RedisService redisService = SpringUtils.getBean(RedisService.class);
|
||||
JSONObject jsonObject = redisService.getCacheObject(UserType.MINI_USER.getKey() + bo.getUserName());
|
||||
if (jsonObject != null) {
|
||||
LoginUser loginUser = jsonObject.getObject("user", LoginUser.class);
|
||||
MallStaffLoginInfo staffLoginInfo = BeanUtils.mapToClass(bo, MallStaffLoginInfo.class);
|
||||
loginUser.setUser(staffLoginInfo);
|
||||
redisService.setCacheObject(UserType.MINI_USER.getKey() + loginUser.getUsername(), loginUser);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description: 用户名-手机-邮箱都需要做唯一校验
|
||||
* @param bo 请求参数
|
||||
* @return Boolean 通过/未通过
|
||||
* @Author DB
|
||||
* @Date: 2023/5/11 11:02
|
||||
**/
|
||||
private Boolean validatedUserInfo(StaffBo bo) {
|
||||
long count = this.count(QueryWrapper.create()
|
||||
//用户名
|
||||
.where(SYS_USER.USER_NAME.eq(bo.getUserName()))
|
||||
//手机号
|
||||
.or(SYS_USER.PHONE_NUMBER.eq(bo.getPhoneNumber()))
|
||||
.and(SYS_USER.USER_TYPE.eq(UserType.MALL_USER))
|
||||
.from(SYS_USER));
|
||||
if (StringUtils.isNotBlank(bo.getUserId())) {
|
||||
return count > 1;
|
||||
} else {
|
||||
return count > 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description: 解密与重设密码
|
||||
* @param sysUser 系统用户
|
||||
* @Author: DB
|
||||
* @Date: 2023/5/11 11:03
|
||||
**/
|
||||
private void decryptAndResetPasswords(SysUser sysUser) {
|
||||
//先用rsa解密
|
||||
String password = SpringUtils.getBean(RsaUtils.class).decrypt(sysUser.getPassword());
|
||||
//再加密
|
||||
sysUser.setPassword(SpringUtils.getBean(PasswordEncoder.class).encode(password));
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 删除员工
|
||||
* @author DB
|
||||
* @date 2023/10/20 11:44
|
||||
* @param id 主键
|
||||
* @return: void
|
||||
*/
|
||||
@Override
|
||||
public void removeStaffById(String id) {
|
||||
//先获取员工
|
||||
Staff staff = this.getById(id);
|
||||
if (null == staff) {
|
||||
throw new ServiceException("获取信息失败,请联系相关人员");
|
||||
}
|
||||
//删除用户
|
||||
SpringUtils.getBean(CoreService.class).removeSysUserById(staff.getUserId());
|
||||
//删除中间表
|
||||
SpringUtils.getBean(RoleBrandService.class).removeById(staff.getRoleBrandId());
|
||||
//删除员工
|
||||
this.removeById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 用户名是否存在
|
||||
* @author DB
|
||||
* @date 2023/10/20 11:55
|
||||
* @param username 用户名
|
||||
* @param id 主键
|
||||
* @return: void
|
||||
*/
|
||||
@Override
|
||||
public void isAccountExist(String username, String id) {
|
||||
if (StringUtils.isBlank(username)){
|
||||
return;
|
||||
}
|
||||
if (this.count(QueryWrapper.create()
|
||||
.where(SYS_USER.USER_NAME.eq(username))
|
||||
.and(SYS_USER.USER_TYPE.eq(UserType.MALL_USER))
|
||||
.and(SYS_USER.ID.ne(id))) > 0) {
|
||||
throw new ServiceException(MessageUtils.message("i18n_alert_userIsExist"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 获取员工信息
|
||||
* @author DB
|
||||
* @date 2023/10/20 12:00
|
||||
* @param id 主键
|
||||
* @return: com.cpop.mall.business.vo.StaffInfoVo
|
||||
*/
|
||||
@Override
|
||||
public StaffInfoVo getStaffInfo(String id) {
|
||||
return this.getOneAs(QueryWrapper.create()
|
||||
.select(STAFF.ALL_COLUMNS)
|
||||
.select(SYS_USER.USER_NAME, SYS_USER.NICK_NAME, SYS_USER.SEX, SYS_USER.PHONE_NUMBER, SYS_USER.ID.as(StaffInfoVo::getUserId))
|
||||
.select(ROLE_BRAND.ROLE_ID)
|
||||
.select(ROLE.ROLE_NAME)
|
||||
.from(STAFF)
|
||||
.leftJoin(ROLE_BRAND).on(ROLE_BRAND.ID.eq(STAFF.ROLE_BRAND_ID))
|
||||
.leftJoin(SYS_USER).on(SYS_USER.ID.eq(STAFF.USER_ID))
|
||||
.leftJoin(ROLE).on(ROLE.ID.eq(ROLE_BRAND.ROLE_ID))
|
||||
.where(STAFF.ID.eq(id))
|
||||
, StaffInfoVo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 修改系统用户密码
|
||||
* @author DB
|
||||
* @date 2023/10/20 12:04
|
||||
* @param bo 请求体
|
||||
* @return: void
|
||||
*/
|
||||
@Override
|
||||
public void modifyUserPassword(ModifyUserPasswordBo bo) {
|
||||
//只允许超级管理员或自己修改面膜
|
||||
JSONObject loginStaffInfo = SecurityUtils.getInstance().getLoginStaffInfo();
|
||||
String userName = loginStaffInfo.getString("userName");
|
||||
//同数据库密码进行比较
|
||||
SysUser user = DbChain.table(SYS_USER)
|
||||
.where(SYS_USER.ID.eq(bo.getUserId()))
|
||||
.oneAs(SysUser.class);
|
||||
if (!StringUtils.equals(userName, Constants.SUPER_ADMIN) || !StringUtils.equals(userName, user.getUserName())) {
|
||||
throw new ServiceException("非超级管理员不允许修改他人密码");
|
||||
}
|
||||
//先用rsa解密
|
||||
RsaUtils rsaUtils = SpringUtils.getBean(RsaUtils.class);
|
||||
String oldPassword = rsaUtils.decrypt(bo.getOldPassword());
|
||||
if (BCrypt.checkpw(oldPassword, user.getPassword())) {
|
||||
//存入系统
|
||||
DbChain.table(SYS_USER)
|
||||
.set(SYS_USER.PASSWORD,SpringUtils.getBean(PasswordEncoder.class).encode(rsaUtils.decrypt(bo.getNewPassword())))
|
||||
.where(SYS_USER.ID.eq(bo.getUserId()))
|
||||
.update();
|
||||
} else {
|
||||
throw new ServiceException(MessageUtils.message("i18n_alert_oldPasswordIsWrong"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,88 @@
|
||||
package com.cpop.mall.business.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* date: 2023/5/17 10:34
|
||||
*
|
||||
* @Author ST
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@ApiModel(value = "StaffInfo对象", description = "员工信息")
|
||||
public class StaffInfoVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@ApiModelProperty("主键")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
@ApiModelProperty("姓名")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@ApiModelProperty("用户id")
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 角色-品牌-id
|
||||
*/
|
||||
@ApiModelProperty("角色-品牌-id")
|
||||
private String roleBrandId;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@ApiModelProperty(value = "用户名")
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
@ApiModelProperty(value = "昵称")
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
@ApiModelProperty(value = "手机号")
|
||||
private String phoneNumber;
|
||||
|
||||
/**
|
||||
* 性别(0:男;1:女)
|
||||
*/
|
||||
@ApiModelProperty(value = "性别(0:男;1:女)")
|
||||
private Boolean sex;
|
||||
|
||||
/**
|
||||
* 角色id
|
||||
*/
|
||||
@ApiModelProperty(value = "角色id")
|
||||
private String roleId;
|
||||
|
||||
/**
|
||||
* 角色名
|
||||
*/
|
||||
@ApiModelProperty(value = "角色名")
|
||||
private String roleName;
|
||||
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
@ApiModelProperty(value = "头像")
|
||||
private String avatar;
|
||||
}
|
||||
@ -0,0 +1,115 @@
|
||||
package com.cpop.mall.business.vo;
|
||||
|
||||
import com.cpop.core.annontation.StringArrayConvert;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author DB
|
||||
* @createTime 2023/10/20 11:06
|
||||
* @description
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@ApiModel(value = "商城员工分页返回对象")
|
||||
public class StaffPageVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@ApiModelProperty("主键")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
@ApiModelProperty("姓名")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@ApiModelProperty("用户id")
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 角色-品牌-id
|
||||
*/
|
||||
@ApiModelProperty("角色-品牌-id")
|
||||
private String roleBrandId;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@ApiModelProperty("用户名")
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
@ApiModelProperty("昵称")
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
@ApiModelProperty("邮箱")
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
@ApiModelProperty("手机号")
|
||||
private String phoneNumber;
|
||||
|
||||
/**
|
||||
* 性别(0:男;1:女)
|
||||
*/
|
||||
@ApiModelProperty("性别(0:男;1:女)")
|
||||
private Boolean sex;
|
||||
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
@ApiModelProperty("头像")
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 状态(0:停用;1:启用)
|
||||
*/
|
||||
@ApiModelProperty("状态(0:停用;1:启用)")
|
||||
private Boolean status;
|
||||
|
||||
/**
|
||||
* 角色id
|
||||
*/
|
||||
@ApiModelProperty("角色id")
|
||||
private String roleId;
|
||||
|
||||
/**
|
||||
* 角色名
|
||||
*/
|
||||
@ApiModelProperty("角色名")
|
||||
private String roleName;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@ApiModelProperty("更新时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@ApiModelProperty("密码")
|
||||
private String password;
|
||||
}
|
||||
@ -83,7 +83,6 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
||||
.and(MENU.TITLE.like(bo.getTitle()))
|
||||
//构建公共菜单与特有菜单
|
||||
.and(MENU.USER_TYPE.in("COMMON", user.getUserType()))
|
||||
.and(MENU.STATUS.eq(true))
|
||||
.orderBy(MENU.ORDER_NO.asc()), MenuVo.class));
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user