员工功能

This commit is contained in:
磷叶 2024-11-23 14:47:44 +08:00
parent f6ff7b75ac
commit 9c9aeadb61
20 changed files with 236 additions and 9 deletions

View File

@ -41,12 +41,15 @@ public class SmUser extends BaseEntity
@Excel(name = "用户名称")
@ApiModelProperty("用户名称")
@NotNull(message = "用户名称不允许为空", groups = {ValidGroup.Create.class})
@JsonView(JsonViewProfile.App.class)
@Sensitive(desensitizedType = DesensitizedType.USERNAME)
private String userName;
/** 用户昵称 */
@Excel(name = "用户昵称")
@ApiModelProperty("用户昵称")
@JsonView(JsonViewProfile.App.class)
@Sensitive(desensitizedType = DesensitizedType.USERNAME)
private String nickName;
/** 用户邮箱 */

View File

@ -1,7 +1,6 @@
package com.ruoyi.common.utils.collection;
import com.ruoyi.common.utils.DateUtils;
import org.apache.poi.ss.formula.functions.T;
import java.math.BigDecimal;
import java.time.LocalDate;
@ -177,4 +176,11 @@ public class CollectionUtils extends org.springframework.util.CollectionUtils {
public static <T> BigDecimal sumDecimal(Collection<T> collection, Function<T, BigDecimal> decimalMapper) {
return collection.stream().map(decimalMapper).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
}
public static <T> T getFirst(List<T> list) {
if (isEmpty(list)) {
return null;
}
return list.get(0);
}
}

View File

@ -103,4 +103,9 @@ public interface DeviceValidator {
* 校验分成
*/
void checkBonus(DeviceVO device);
/**
* 校验分成
*/
void checkBonus(Long deviceId);
}

View File

@ -44,6 +44,7 @@ import com.ruoyi.ss.record.time.service.IRecordTimeService;
import com.ruoyi.ss.record.time.service.RecordTimeConverter;
import com.ruoyi.ss.store.domain.StoreVo;
import com.ruoyi.ss.store.service.StoreService;
import com.ruoyi.ss.storeStaff.service.StoreStaffValidator;
import com.ruoyi.ss.suit.domain.enums.SuitFeeType;
import com.ruoyi.ss.timeBill.domain.TimeBillQuery;
import com.ruoyi.ss.timeBill.domain.TimeBillVO;
@ -139,6 +140,9 @@ public class DeviceServiceImpl implements DeviceService
@Autowired
private UserValidator userValidator;
@Autowired
private StoreStaffValidator storeStaffValidator;
/**
* 查询设备
*
@ -230,6 +234,7 @@ public class DeviceServiceImpl implements DeviceService
// 后校验
DeviceVO vo = this.selectById(data.getDeviceId());
deviceAssembler.assembleBonusList(vo);
deviceValidator.afterCheck(vo);
// 更新套餐关联
@ -1212,6 +1217,9 @@ public class DeviceServiceImpl implements DeviceService
int updateCount = deviceMapper.bind(device.getDeviceId(), storeId, userId);
ServiceUtil.assertion(updateCount != 1, "当前设备信息已变更,请刷新后重试");
// 校验分成
deviceValidator.checkBonus(device.getDeviceId());
// 记录绑定记录
int record = smDeviceBindRecordService.record(userId, device.getDeviceId(), BindRecordType.BIND, BindRecordUserType.MCH);
ServiceUtil.assertion(record != 1, "添加绑定记录失败");
@ -1221,7 +1229,6 @@ public class DeviceServiceImpl implements DeviceService
int changeType = userService.changeType(userId, UserType.MCH);
ServiceUtil.assertion(changeType != 1, "修改用户类型失败");
}
return updateCount;
});

View File

@ -12,6 +12,7 @@ import com.ruoyi.ss.device.domain.DeviceBO;
import com.ruoyi.ss.device.domain.DeviceQuery;
import com.ruoyi.ss.device.domain.enums.DeviceServiceMode;
import com.ruoyi.ss.device.domain.vo.DeviceVO;
import com.ruoyi.ss.device.service.DeviceAssembler;
import com.ruoyi.ss.device.service.DeviceService;
import com.ruoyi.ss.device.service.DeviceValidator;
import com.ruoyi.ss.store.service.StoreValidator;
@ -50,6 +51,9 @@ public class DeviceValidatorImpl extends BaseValidator implements DeviceValidato
@Autowired
private ISmUserService userService;
@Autowired
private DeviceAssembler deviceAssembler;
/**
* 设备编号是否存在
*
@ -275,8 +279,18 @@ public class DeviceValidatorImpl extends BaseValidator implements DeviceValidato
// 不允许分成小于0
for (Bonus bonus : device.getBonusList()) {
ServiceUtil.assertion(bonus.getPoint() == null, "设备%s的分成比例不允许为空", device.getDeviceNo());
ServiceUtil.assertion(bonus.getPoint().compareTo(BigDecimal.ZERO) < 0, "设备%s的分成比例不允许小于0", device.getDeviceNo());
ServiceUtil.assertion(bonus.getPoint() == null, "设备%s的%s分成比例不允许为空", device.getDeviceNo(), bonus.getArrivalName());
ServiceUtil.assertion(bonus.getPoint().compareTo(BigDecimal.ZERO) < 0, "设备%s的%s分成比例不允许小于0", device.getDeviceNo(), bonus.getArrivalName());
}
}
@Override
public void checkBonus(Long deviceId) {
if (deviceId == null) {
return;
}
DeviceVO device = deviceService.selectById(deviceId);
deviceAssembler.assembleBonusList(device);
this.checkBonus(device);
}
}

View File

@ -118,4 +118,11 @@ public class StoreBO extends Store {
bo.setUseOutTime(getUseOutTime());
return bo;
}
/**
* 店铺员工修改店铺
*/
public StoreBO filterUpdateByAppStaff() {
return this.filterUpdateByApp();
}
}

View File

@ -3,6 +3,7 @@ package com.ruoyi.ss.store.domain;
import com.ruoyi.common.core.domain.ValidGroup;
import com.ruoyi.common.valid.EnumValid;
import com.ruoyi.ss.store.domain.enums.StoreGroupBy;
import com.ruoyi.ss.storeStaff.domain.StoreStaffQuery;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -46,4 +47,13 @@ public class StoreQuery extends Store {
@ApiModelProperty("关键词")
private String keyword;
@ApiModelProperty("是否在员工信息中(根据员工信息筛选时使用)")
private Boolean inStaff;
@ApiModelProperty("员工用户ID")
private Long staffUserId;
@ApiModelProperty("员工权限")
private String staffPermission;
}

View File

@ -76,6 +76,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{item}
</foreach>
</if>
<if test="query.inStaff != null">
and ss.store_id
<if test="!query.inStaff">not</if>
in (<include refid="selectStaffViewStoreIds"/>)
</if>
</sql>
<!--查询员工可查看的店铺ID列表-->
<sql id="selectStaffViewStoreIds">
select distinct sss.store_id
from ss_store_staff sss
<where>
<if test="query.staffUserId != null">and sss.user_id = #{query.staffUserId}</if>
<if test="query.staffPermission != null and query.staffPermission != ''">
and find_in_set(#{query.staffPermission}, sss.permissions)
</if>
</where>
</sql>
<select id="selectSmStoreList" parameterType="StoreQuery" resultMap="SmStoreResult">

View File

@ -145,4 +145,14 @@ public interface StoreService
* 条件更新
*/
int updateByQuery(Store data, StoreQuery query);
/**
* 查询员工管理的列表
*/
List<StoreVo> selectStaffStoreList(StoreQuery query);
/**
* 查询一个员工管理的店铺
*/
StoreVo selectStaffStoreOne(StoreQuery query);
}

View File

@ -1,5 +1,6 @@
package com.ruoyi.ss.store.service.impl;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ServiceUtil;
@ -387,6 +388,19 @@ public class StoreServiceImpl implements StoreService
return storeMapper.updateByQuery(data, query);
}
@Override
public List<StoreVo> selectStaffStoreList(StoreQuery query) {
query.setInStaff(true);
return this.selectSmStoreList(query);
}
@Override
public StoreVo selectStaffStoreOne(StoreQuery query) {
PageHelper.startPage(1, 1);
List<StoreVo> list = this.selectStaffStoreList(query);
return CollectionUtils.getFirst(list);
}
/**
* 通用查询数量
*

View File

@ -21,4 +21,7 @@ public class StoreStaffQuery extends StoreStaffVO {
@ApiModelProperty("店铺ID列表")
private List<Long> storeIds;
@ApiModelProperty("权限")
private String permission;
}

View File

@ -1,5 +1,7 @@
package com.ruoyi.ss.storeStaff.domain;
import com.ruoyi.common.annotation.Sensitive;
import com.ruoyi.common.enums.DesensitizedType;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -14,6 +16,7 @@ public class StoreStaffVO extends StoreStaff{
private String storeName;
@ApiModelProperty("用户名称")
@Sensitive(desensitizedType = DesensitizedType.USERNAME)
private String userName;
@ApiModelProperty("商户ID")

View File

@ -0,0 +1,25 @@
package com.ruoyi.ss.storeStaff.domain.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author wjh
* 2024/11/23
*/
@Getter
@AllArgsConstructor
public enum StoreStaffPermissions {
STORE_VIEW("1", "查看店铺"),
STORE_OPERA("2", "操作店铺"),
DEVICE_VIEW("3", "查看设备"),
DEVICE_OPERA("4", "操作设备"),
ORDER_VIEW("5", "查看订单"),
ORDER_OPERA("6", "操作订单"),
;
private final String code;
private final String msg;
}

View File

@ -23,7 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
sss.create_id,
ss.name as store_name,
ss.user_id as mch_id,
su.user_name as user_name
if(su.is_real, su.real_name, su.user_name) as user_name
from ss_store_staff sss
left join sm_store ss on ss.store_id = sss.store_id
left join sm_user su on su.user_id = sss.user_id
@ -39,8 +39,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="query.enabled != null "> and sss.enabled = #{query.enabled}</if>
<if test="query.createId != null "> and sss.create_id = #{query.createId}</if>
<if test="query.storeName != null and query.storeName != ''">and ss.name like concat('%', #{query.storeName}, '%')</if>
<if test="query.userName != null and query.userName != ''">and su.user_name like concat('%', #{query.userName}, '%')</if>
<if test="query.userName != null and query.userName != ''">and if(su.is_real, su.real_name, su.user_name) like concat('%', #{query.userName}, '%')</if>
<if test="query.mchId != null">and ss.user_id = #{query.mchId}</if>
<if test="query.permission != null and query.permission != ''">
and find_in_set(#{query.permission}, sss.permissions);
</if>
<if test="query.excludeEmployId != null">
and sss.employ_id != #{query.excludeEmployId}
</if>

View File

@ -25,4 +25,11 @@ public interface StoreStaffValidator {
* 是否是商户
*/
boolean isMch(List<Long> employIds, Long userId);
/**
* 判断用户能否操作店铺
* @param storeId 店铺ID
* @param userId 员工ID
*/
boolean canOperaStore(Long storeId, Long userId);
}

View File

@ -2,7 +2,6 @@ package com.ruoyi.ss.storeStaff.service.impl;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.ss.bonus.domain.Bonus;
import com.ruoyi.ss.device.domain.vo.DeviceVO;
import com.ruoyi.ss.device.service.DeviceAssembler;
import com.ruoyi.ss.device.service.DeviceService;
@ -10,12 +9,12 @@ import com.ruoyi.ss.device.service.DeviceValidator;
import com.ruoyi.ss.storeStaff.domain.StoreStaff;
import com.ruoyi.ss.storeStaff.domain.StoreStaffQuery;
import com.ruoyi.ss.storeStaff.domain.StoreStaffVO;
import com.ruoyi.ss.storeStaff.domain.enums.StoreStaffPermissions;
import com.ruoyi.ss.storeStaff.service.StoreStaffService;
import com.ruoyi.ss.storeStaff.service.StoreStaffValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
@ -95,6 +94,19 @@ public class StoreStaffValidatorImpl implements StoreStaffValidator {
return true;
}
@Override
public boolean canOperaStore(Long storeId, Long userId) {
if (storeId == null || userId == null) {
return false;
}
StoreStaffQuery query = new StoreStaffQuery();
query.setStoreId(storeId);
query.setUserId(userId);
query.setEnabled(true);
query.setPermission(StoreStaffPermissions.STORE_OPERA.getCode());
return storeStaffService.selectCount(query) > 0;
}
private void checkRepeatUser(Long storeId, Long userId, Long employId) {
if (storeId == null || userId == null) {
return;

View File

@ -2,8 +2,10 @@ package com.ruoyi.ss.user.domain;
import com.fasterxml.jackson.annotation.JsonView;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.annotation.Sensitive;
import com.ruoyi.common.core.domain.JsonViewProfile;
import com.ruoyi.common.core.domain.entity.SmUser;
import com.ruoyi.common.enums.DesensitizedType;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -41,6 +43,8 @@ public class SmUserVO extends SmUser {
private Integer storeCount;
@ApiModelProperty("实名或用户名")
@JsonView(JsonViewProfile.App.class)
@Sensitive(desensitizedType = DesensitizedType.USERNAME)
private String realOrUserName;
@ApiModelProperty("实际到账延迟")

View File

@ -173,7 +173,7 @@ public class SmUserServiceImpl implements ISmUserService
return null;
}
SmUserQuery dto = new SmUserQuery();
dto.setPhonenumber(phoneNumber);
dto.setEqPhonenumber(phoneNumber);
List<SmUserVO> list = smUserMapper.selectSmUserList(dto);
if (CollectionUtils.isEmpty(list)) {
return null;

View File

@ -7,12 +7,14 @@ import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.JsonViewProfile;
import com.ruoyi.common.core.domain.entity.SmUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.service.SysPasswordService;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.ss.realName.domain.enums.RealNameType;
import com.ruoyi.ss.user.domain.SmUserQuery;
import com.ruoyi.ss.user.domain.SmUserVO;
import com.ruoyi.ss.user.domain.dto.UserChangeMobileDTO;
import com.ruoyi.ss.user.domain.dto.UserRealNameDTO;
@ -168,4 +170,11 @@ public class AppUserController extends BaseController {
data.setUserId(getUserId());
return toAjax(userService.updateSmUser(userConvert.toUserSettingByApp(data)));
}
@ApiOperation("通过精准手机号查询用户列表")
@GetMapping("/getByEqPhone")
@JsonView(JsonViewProfile.App.class)
public AjaxResult getByEqPhone(String eqPhonenumber) {
return success(userService.selectUserByPhone(eqPhonenumber));
}
}

View File

@ -0,0 +1,68 @@
package com.ruoyi.web.controller.staff;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.ValidGroup;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.ss.store.domain.StoreBO;
import com.ruoyi.ss.store.domain.StoreQuery;
import com.ruoyi.ss.store.service.StoreService;
import com.ruoyi.ss.store.service.StoreValidator;
import com.ruoyi.ss.storeStaff.domain.enums.StoreStaffPermissions;
import com.ruoyi.ss.storeStaff.service.StoreStaffValidator;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* 员工 店铺Controller
* @author wjh
* 2024/11/23
*/
@RestController
@RequestMapping("/staff/store")
public class StaffStoreController extends BaseController {
@Autowired
private StoreService storeService;
@Autowired
private StoreStaffValidator storeStaffValidator;
@Autowired
private StoreValidator storeValidator;
@ApiOperation("员工获取管理的店铺列表")
@GetMapping("/list")
public TableDataInfo list(StoreQuery query) {
startPage();
query.setStaffUserId(getUserId());
query.setStaffPermission(StoreStaffPermissions.STORE_VIEW.getCode());
return getDataTable(storeService.selectStaffStoreList(query));
}
@ApiOperation("员工获取店铺详情")
@GetMapping("/{storeId}")
public AjaxResult getDetail(@PathVariable Long storeId) {
StoreQuery query = new StoreQuery();
query.setStaffUserId(getUserId());
query.setStaffPermission(StoreStaffPermissions.STORE_VIEW.getCode());
query.setStoreId(storeId);
return success(storeService.selectStaffStoreOne(query));
}
// TODO 建议还是合在商户的接口中使用
@ApiOperation("员工申请修改店铺信息")
@PutMapping
public AjaxResult update(@RequestBody @Validated(ValidGroup.FrontUpdate.class) StoreBO data) {
if (!storeStaffValidator.canOperaStore(data.getStoreId(), getUserId())) {
return error("您无权修改该店铺");
}
data = data.filterUpdateByAppStaff();
ServiceUtil.assertion(storeValidator.preUpdateByApp(data));
return toAjax(storeService.updateApply(data));
}
}