店铺相关模块

This commit is contained in:
SjS 2025-04-22 19:43:53 +08:00
parent c9a65f993c
commit ea53005a37
25 changed files with 505 additions and 84 deletions

View File

@ -7,6 +7,9 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity; import com.ruoyi.common.core.domain.BaseEntity;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/** /**
* 卡座对象 bst_booth * 卡座对象 bst_booth
* *
@ -22,10 +25,12 @@ public class Booth extends BaseEntity
@Excel(name = "分区ID") @Excel(name = "分区ID")
@ApiModelProperty("分区ID") @ApiModelProperty("分区ID")
@NotNull(message = "分区ID不能为空")
private Long partId; private Long partId;
@Excel(name = "卡座名称") @Excel(name = "卡座名称")
@ApiModelProperty("卡座名称") @ApiModelProperty("卡座名称")
@NotBlank(message = "卡座名称不能为空")
private String boothName; private String boothName;
@Excel(name = "分区图片") @Excel(name = "分区图片")

View File

@ -1,7 +1,15 @@
package com.ruoyi.bst.booth.domain; package com.ruoyi.bst.booth.domain;
import com.ruoyi.common.annotation.Excel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.util.List;
@Data @Data
public class BoothQuery extends Booth { public class BoothQuery extends BoothVO {
@ApiModelProperty("卡座ID列表")
private List<Long> ids;
} }

View File

@ -1,7 +1,14 @@
package com.ruoyi.bst.booth.domain; package com.ruoyi.bst.booth.domain;
import com.ruoyi.common.annotation.Excel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@Data @Data
public class BoothVO extends Booth{ public class BoothVO extends Booth{
@Excel(name = "分区名称")
@ApiModelProperty("分区名称")
private String partName;
} }

View File

@ -14,18 +14,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectBoothVo"> <sql id="selectBoothVo">
select select
booth_id, bb.booth_id,
part_id, bb.part_id,
booth_name, bb.booth_name,
picture, bb.picture,
create_time bb.create_time,
from bst_booth bp.part_name as partName,
bs.user_id
<include refid="searchTables"/>
</sql>
<sql id="searchTables">
from bst_booth bb
left join bst_part bp on bp.part_id = bb.part_id
left join bst_floor bf on bp.floor_id = bf.floor_id
left join bst_store bs on bf.store_id = bs.store_id
</sql> </sql>
<sql id="searchCondition"> <sql id="searchCondition">
<if test="query.partId != null "> and part_id = #{query.partId}</if> <if test="query.partId != null "> and part_id = #{query.partId}</if>
<if test="query.boothName != null and query.boothName != ''"> and booth_name like concat('%', #{query.boothName}, '%')</if> <if test="query.boothName != null and query.boothName != ''"> and booth_name like concat('%', #{query.boothName}, '%')</if>
<if test="query.picture != null and query.picture != ''"> and picture = #{query.picture}</if> <if test="query.picture != null and query.picture != ''"> and picture = #{query.picture}</if>
<if test="query.partName != null and query.partName != ''"> and bp.part_name like concat('%', #{query.partName}, '%') </if>
${@com.ruoyi.framework.util.DataScopeUtil@create(query.scope)
.userSetAlias("bs.user_id")
.build()
}
${query.params.dataScope} ${query.params.dataScope}
</sql> </sql>
@ -41,6 +55,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where booth_id = #{boothId} where booth_id = #{boothId}
</select> </select>
<!-- selectIdByQuery -->
<select id="selectIdByQuery" resultType="Long">
select bb.booth_id <include refid="searchTables"/>
<where>
<include refid="searchCondition"/>
</where>
</select>
<insert id="insertBooth" parameterType="Booth" useGeneratedKeys="true" keyProperty="boothId"> <insert id="insertBooth" parameterType="Booth" useGeneratedKeys="true" keyProperty="boothId">
insert into bst_booth insert into bst_booth
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
@ -151,7 +173,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<delete id="deleteBoothByBoothIds" parameterType="String"> <delete id="deleteBoothByBoothIds" parameterType="String">
delete from bst_booth where booth_id in delete from bst_booth where booth_id in
<foreach item="boothId" collection="array" open="(" separator="," close=")"> <foreach item="boothId" collection="ids" open="(" separator="," close=")">
#{boothId} #{boothId}
</foreach> </foreach>
</delete> </delete>

View File

@ -7,6 +7,9 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.TreeEntity; import com.ruoyi.common.core.domain.TreeEntity;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/** /**
* 分区对象 bst_part * 分区对象 bst_part
* *
@ -20,12 +23,14 @@ public class Part extends TreeEntity
private Long partId; private Long partId;
@Excel(name = "店铺ID") @Excel(name = "楼层ID")
@ApiModelProperty("店铺ID") @ApiModelProperty("楼层ID")
private Long storeId; @NotNull(message = "楼层ID不能为空")
private Long floorId;
@Excel(name = "分区名称") @Excel(name = "分区名称")
@ApiModelProperty("分区名称") @ApiModelProperty("分区名称")
@NotBlank(message = "分区名称不能为空")
private String partName; private String partName;
@Excel(name = "分区图片") @Excel(name = "分区图片")

View File

@ -1,7 +1,15 @@
package com.ruoyi.bst.part.domain; package com.ruoyi.bst.part.domain;
import com.ruoyi.common.annotation.Excel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.util.List;
@Data @Data
public class PartQuery extends Part { public class PartQuery extends PartVO {
@ApiModelProperty("分区ID列表")
private List<Long> ids;
} }

View File

@ -7,8 +7,8 @@ import lombok.Data;
@Data @Data
public class PartVO extends Part{ public class PartVO extends Part{
@Excel(name = "店铺名称") @Excel(name = "楼层名称")
@ApiModelProperty("店铺名称") @ApiModelProperty("楼层名称")
private Long storeName; private String floorName;
} }

View File

@ -70,5 +70,7 @@ public interface PartMapper
* @param partIds 需要删除的数据主键集合 * @param partIds 需要删除的数据主键集合
* @return 结果 * @return 结果
*/ */
public int deletePartByPartIds(Long[] partIds); public int deletePartByPartIds(@Param("ids") List<Long> partIds);
public List<Long> selectIdByQuery(@Param("query") PartQuery query);
} }

View File

@ -6,8 +6,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="PartVO" id="PartResult" autoMapping="true"> <resultMap type="PartVO" id="PartResult" autoMapping="true">
<result property="partId" column="part_id" /> <result property="partId" column="part_id" />
<result property="parentId" column="parent_id" /> <result property="floorId" column="floor_id" />
<result property="storeId" column="store_id" />
<result property="partName" column="part_name" /> <result property="partName" column="part_name" />
<result property="picture" column="picture" /> <result property="picture" column="picture" />
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time" />
@ -16,21 +15,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectPartVo"> <sql id="selectPartVo">
select select
bp.part_id, bp.part_id,
bp.parent_id, bp.floor_id,
bp.store_id,
bp.part_name, bp.part_name,
bp.picture, bp.picture,
bp.create_time, bp.create_time,
bs.store_name bs.store_name,
bs.user_id,
bf.floor_name as floorName
<include refid="searchTables"/>
</sql>
<sql id="searchTables">
from bst_part bp from bst_part bp
left join bst_store bs on bp.store_id = bs.store_id left join bst_floor bf on bp.floor_id = bf.floor_id
left join bst_store bs on bf.store_id = bs.store_id
</sql> </sql>
<sql id="searchCondition"> <sql id="searchCondition">
<if test="query.parentId != null "> and parent_id = #{query.parentId}</if>
<if test="query.storeId != null "> and store_id = #{query.storeId}</if> <if test="query.floorId != null "> and floor_id = #{query.floor_id}</if>
<if test="query.partName != null and query.partName != ''"> and part_name like concat('%', #{query.partName}, '%')</if> <if test="query.partName != null and query.partName != ''"> and part_name like concat('%', #{query.partName}, '%')</if>
<if test="query.picture != null and query.picture != ''"> and picture = #{query.picture}</if> <if test="query.picture != null and query.picture != ''"> and picture = #{query.picture}</if>
<if test="query.floorName != null and query.floorName != ''"> and bf.floor_name like concat('%', #{query.floorName}, '%') </if>
${@com.ruoyi.framework.util.DataScopeUtil@create(query.scope)
.userSetAlias("bs.user_id")
.build()
}
${query.params.dataScope} ${query.params.dataScope}
</sql> </sql>
@ -43,21 +53,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectPartByPartId" parameterType="Long" resultMap="PartResult"> <select id="selectPartByPartId" parameterType="Long" resultMap="PartResult">
<include refid="selectPartVo"/> <include refid="selectPartVo"/>
where part_id = #{partId} where bp.part_id = #{partId}
</select>
<!-- selectIdByQuery -->
<select id="selectIdByQuery" resultType="Long">
select bp.part_id <include refid="searchTables"/>
<where>
<include refid="searchCondition"/>
</where>
</select> </select>
<insert id="insertPart" parameterType="Part" useGeneratedKeys="true" keyProperty="partId"> <insert id="insertPart" parameterType="Part" useGeneratedKeys="true" keyProperty="partId">
insert into bst_part insert into bst_part
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="parentId != null">parent_id,</if> <if test="floorId != null">floor_id,</if>
<if test="storeId != null">store_id,</if>
<if test="partName != null">part_name,</if> <if test="partName != null">part_name,</if>
<if test="picture != null">picture,</if> <if test="picture != null">picture,</if>
<if test="createTime != null">create_time,</if> <if test="createTime != null">create_time,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="parentId != null">#{parentId},</if> <if test="floorId != null">#{floorId},</if>
<if test="storeId != null">#{storeId},</if>
<if test="partName != null">#{partName},</if> <if test="partName != null">#{partName},</if>
<if test="picture != null">#{picture},</if> <if test="picture != null">#{picture},</if>
<if test="createTime != null">#{createTime},</if> <if test="createTime != null">#{createTime},</if>
@ -67,7 +83,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="batchInsert" parameterType="Part" useGeneratedKeys="true" keyProperty="partId"> <insert id="batchInsert" parameterType="Part" useGeneratedKeys="true" keyProperty="partId">
insert into bst_part insert into bst_part
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
parent_id, floor_id
store_id, store_id,
part_name, part_name,
picture, picture,
@ -76,10 +92,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
values values
<foreach collection="list" item="i" separator=","> <foreach collection="list" item="i" separator=",">
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="i.parentId != null ">#{i.parentId},</if> <if test="i.floorId != null ">#{i.floorId},</if>
<if test="i.parentId == null ">default,</if> <if test="i.floorId == null ">default,</if>
<if test="i.storeId != null ">#{i.storeId},</if>
<if test="i.storeId == null ">default,</if>
<if test="i.partName != null ">#{i.partName},</if> <if test="i.partName != null ">#{i.partName},</if>
<if test="i.partName == null ">default,</if> <if test="i.partName == null ">default,</if>
<if test="i.picture != null ">#{i.picture},</if> <if test="i.picture != null ">#{i.picture},</if>
@ -93,20 +107,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="batchUpdate"> <update id="batchUpdate">
update bst_part update bst_part
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
<foreach open="parent_id = CASE part_id" collection="list" item="item" close="END,">
<choose>
<when test="item.parentId != null ">
WHEN #{item.part_id} THEN #{item.parentId}
</when>
<otherwise>
WHEN #{item.part_id} THEN `parent_id`
</otherwise>
</choose>
</foreach>
<foreach open="store_id = CASE part_id" collection="list" item="item" close="END,"> <foreach open="store_id = CASE part_id" collection="list" item="item" close="END,">
<choose> <choose>
<when test="item.storeId != null "> <when test="item.floorId != null ">
WHEN #{item.part_id} THEN #{item.storeId} WHEN #{item.part_id} THEN #{item.floorId}
</when> </when>
<otherwise> <otherwise>
WHEN #{item.part_id} THEN `store_id` WHEN #{item.part_id} THEN `store_id`
@ -159,8 +163,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update> </update>
<sql id="updateColumns"> <sql id="updateColumns">
<if test="data.parentId != null">parent_id = #{data.parentId},</if> <if test="data.floorId != null">store_id = #{data.floorId},</if>
<if test="data.storeId != null">store_id = #{data.storeId},</if>
<if test="data.partName != null">part_name = #{data.partName},</if> <if test="data.partName != null">part_name = #{data.partName},</if>
<if test="data.picture != null">picture = #{data.picture},</if> <if test="data.picture != null">picture = #{data.picture},</if>
<if test="data.createTime != null">create_time = #{data.createTime},</if> <if test="data.createTime != null">create_time = #{data.createTime},</if>
@ -172,7 +175,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<delete id="deletePartByPartIds" parameterType="String"> <delete id="deletePartByPartIds" parameterType="String">
delete from bst_part where part_id in delete from bst_part where part_id in
<foreach item="partId" collection="array" open="(" separator="," close=")"> <foreach item="partId" collection="ids" open="(" separator="," close=")">
#{partId} #{partId}
</foreach> </foreach>
</delete> </delete>

View File

@ -16,10 +16,16 @@ public interface PartService
/** /**
* 查询分区 * 查询分区
* *
* @param partId 分区主键 * @param id 分区主键
* @return 分区 * @return 分区
*/ */
public PartVO selectPartByPartId(Long partId); public PartVO selectPartById(Long id, boolean scope);
default PartVO selectPartById(Long id) {
return this.selectPartById(id, false);
}
public PartVO selectOne(PartQuery query);
/** /**
* 查询分区列表 * 查询分区列表
@ -51,7 +57,7 @@ public interface PartService
* @param partIds 需要删除的分区主键集合 * @param partIds 需要删除的分区主键集合
* @return 结果 * @return 结果
*/ */
public int deletePartByPartIds(Long[] partIds); public int deletePartByPartIds(List<Long> partIds);
/** /**
* 删除分区信息 * 删除分区信息
@ -60,4 +66,6 @@ public interface PartService
* @return 结果 * @return 结果
*/ */
public int deletePartByPartId(Long partId); public int deletePartByPartId(Long partId);
Long getUserId(Part part);
} }

View File

@ -0,0 +1,29 @@
package com.ruoyi.bst.part.service;
import java.util.List;
public interface PartValidator {
/**
* 判断当前用户是否可以选择制定分区
* @param partId 分区ID
* @return 是否允许
*/
boolean canCheckForPart(Long partId);
/**
* 当前用户是否可以编辑分区
* @param partId 分区ID
* @return 是否可以编辑
*/
boolean canEdit(Long partId);
/**
* 当前用户是否可以删除分区
* @param partIds 分区ID列表
* @return 是否可以删除
*/
boolean canDeleteAll(List<Long> partIds);
}

View File

@ -1,7 +1,12 @@
package com.ruoyi.bst.part.service.impl; package com.ruoyi.bst.part.service.impl;
import java.util.List; import java.util.List;
import com.github.pagehelper.PageHelper;
import com.ruoyi.bst.store.service.StoreService;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.collection.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ruoyi.bst.part.mapper.PartMapper; import com.ruoyi.bst.part.mapper.PartMapper;
@ -21,17 +26,32 @@ public class PartServiceImpl implements PartService
{ {
@Autowired @Autowired
private PartMapper partMapper; private PartMapper partMapper;
@Autowired
private StoreService storeService;
/** /**
* 查询分区 * 查询分区
* *
* @param partId 分区主键 * @param id 分区主键
* @return 分区 * @return 分区
*/ */
@Override @Override
public PartVO selectPartByPartId(Long partId) public PartVO selectPartById(Long id, boolean scope)
{ {
return partMapper.selectPartByPartId(partId); if (id == null) {
return null;
}
PartQuery query = new PartQuery();
query.setPartId(id);
query.setScope(scope);
return this.selectOne(query);
}
@Override
public PartVO selectOne(PartQuery query) {
PageHelper.startPage(1, 1);
List<PartVO> list = partMapper.selectPartList(query);
return CollectionUtils.firstElement(list);
} }
/** /**
@ -78,7 +98,7 @@ public class PartServiceImpl implements PartService
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deletePartByPartIds(Long[] partIds) public int deletePartByPartIds(List<Long> partIds)
{ {
return partMapper.deletePartByPartIds(partIds); return partMapper.deletePartByPartIds(partIds);
} }
@ -94,4 +114,9 @@ public class PartServiceImpl implements PartService
{ {
return partMapper.deletePartByPartId(partId); return partMapper.deletePartByPartId(partId);
} }
@Override
public Long getUserId(Part part) {
return storeService.selectStoreById(part.getFloorId()).getUserId();
}
} }

View File

@ -0,0 +1,59 @@
package com.ruoyi.bst.part.service.impl;
import com.ruoyi.bst.part.domain.PartQuery;
import com.ruoyi.bst.part.mapper.PartMapper;
import com.ruoyi.bst.part.service.PartValidator;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.collection.CollectionUtils;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
@Service
public class PartValidatorImpl implements PartValidator {
private final PartMapper partMapper;
public PartValidatorImpl(PartMapper partMapper) {
this.partMapper = partMapper;
}
@Override
public boolean canCheckForPart(Long partId) {
return canOperate(Arrays.asList(partId));
}
@Override
public boolean canEdit(Long partId) {
return canOperate(Arrays.asList(partId));
}
@Override
public boolean canDeleteAll(List<Long> partIds) {
return canOperate(partIds);
}
// 是否可以操作运营区
private boolean canOperate(List<Long> partIds) {
return hasPermission(partIds);
}
// 是否有运营区权限
private boolean hasPermission(List<Long> partIds) {
if (SecurityUtils.isSysAdmin()) {
return true;
}
if (CollectionUtils.isEmptyElement(partIds)) {
return true;
}
// 查询运营区
PartQuery query = new PartQuery();
query.setIds(partIds);
query.setScope(true);
List<Long> partIdList = partMapper.selectIdByQuery(query);
return new HashSet<>(partIdList).containsAll(partIds);
}
}

View File

@ -5,6 +5,7 @@ import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.Date; import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.validate.ValidGroup;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
@ -12,6 +13,9 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity; import com.ruoyi.common.core.domain.BaseEntity;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/** /**
* 店铺对象 bst_store * 店铺对象 bst_store
* *
@ -31,24 +35,29 @@ public class Store extends BaseEntity
@Excel(name = "店铺名称") @Excel(name = "店铺名称")
@ApiModelProperty("店铺名称") @ApiModelProperty("店铺名称")
@NotBlank(message = "店铺名称不能为空",groups = {ValidGroup.Create.class})
private String storeName; private String storeName;
@Excel(name = "联系人") @Excel(name = "联系人")
@ApiModelProperty("联系人") @ApiModelProperty("联系人")
@NotBlank(message = "联系人不能为空",groups = {ValidGroup.Create.class})
private String userName; private String userName;
@Excel(name = "联系电话") @Excel(name = "联系电话")
@ApiModelProperty("联系电话") @ApiModelProperty("联系电话")
@NotBlank(message = "联系电话不能为空",groups = {ValidGroup.Create.class})
private String phone; private String phone;
@JsonFormat(pattern = "HH:mm") @JsonFormat(pattern = "HH:mm")
@Excel(name = "营业开始时间", width = 30, dateFormat = "HH:mm") @Excel(name = "营业开始时间", width = 30, dateFormat = "HH:mm")
@ApiModelProperty("营业开始时间") @ApiModelProperty("营业开始时间")
@NotNull(message = "营业开始时间不能为空",groups = {ValidGroup.Create.class})
private LocalTime startTime; private LocalTime startTime;
@JsonFormat(pattern = "HH:mm") @JsonFormat(pattern = "HH:mm")
@Excel(name = "营业结束时间", width = 30, dateFormat = "HH:mm") @Excel(name = "营业结束时间", width = 30, dateFormat = "HH:mm")
@ApiModelProperty("营业结束时间") @ApiModelProperty("营业结束时间")
@NotNull(message = "营业结束时间不能为空",groups = {ValidGroup.Create.class})
private LocalTime endTime; private LocalTime endTime;
@Excel(name = "经度") @Excel(name = "经度")
@ -61,6 +70,7 @@ public class Store extends BaseEntity
@Excel(name = "详细地址") @Excel(name = "详细地址")
@ApiModelProperty("详细地址") @ApiModelProperty("详细地址")
@NotBlank(message = "详细地址不能为空",groups = {ValidGroup.Create.class})
private String address; private String address;
@Excel(name = "门店照片") @Excel(name = "门店照片")

View File

@ -1,7 +1,15 @@
package com.ruoyi.bst.store.domain; package com.ruoyi.bst.store.domain;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.util.List;
@Data @Data
public class StoreQuery extends Store{ public class StoreQuery extends StoreVO{
@ApiModelProperty("店铺ID列表")
private List<Long> storeIds;
} }

View File

@ -0,0 +1,15 @@
package com.ruoyi.bst.store.domain.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum StorePermission {
STORE_EDIT("store:edit", "操作店铺");
private final String code;
private final String name;
}

View File

@ -5,6 +5,7 @@ import com.ruoyi.bst.store.domain.Store;
import com.ruoyi.bst.store.domain.StoreVO; import com.ruoyi.bst.store.domain.StoreVO;
import com.ruoyi.bst.store.domain.StoreQuery; import com.ruoyi.bst.store.domain.StoreQuery;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.security.core.parameters.P;
/** /**
* 店铺Mapper接口 * 店铺Mapper接口
@ -71,4 +72,6 @@ public interface StoreMapper
* @return 结果 * @return 结果
*/ */
public int deleteStoreByStoreIds(Long[] storeIds); public int deleteStoreByStoreIds(Long[] storeIds);
int logicDel(@Param("ids") List<Long> ids);
} }

View File

@ -17,26 +17,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="address" column="address" /> <result property="address" column="address" />
<result property="picture" column="picture" /> <result property="picture" column="picture" />
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time" />
<result property="deleted" column="deleted" />
</resultMap> </resultMap>
<sql id="selectStoreVo"> <sql id="selectStoreVo">
select select
store_id, bs.store_id,
user_id, bs.user_id,
store_name, bs.store_name,
user_name, bs.user_name,
phone, bs.phone,
start_time, bs.start_time,
end_time, bs.end_time,
longitude, bs.longitude,
latitude, bs.latitude,
address, bs.address,
picture, bs.picture,
create_time bs.create_time
from bst_store from bst_store bs
</sql> </sql>
<sql id="searchCondition"> <sql id="searchCondition">
<if test="query.storeId != null "> and store_id = #{query.storeId}</if>
<if test="query.userId != null "> and user_id = #{query.userId}</if> <if test="query.userId != null "> and user_id = #{query.userId}</if>
<if test="query.storeName != null and query.storeName != ''"> and store_name like concat('%', #{query.storeName}, '%')</if> <if test="query.storeName != null and query.storeName != ''"> and store_name like concat('%', #{query.storeName}, '%')</if>
<if test="query.userName != null and query.userName != ''"> and user_name like concat('%', #{query.userName}, '%')</if> <if test="query.userName != null and query.userName != ''"> and user_name like concat('%', #{query.userName}, '%')</if>
@ -47,6 +49,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="query.latitude != null "> and latitude = #{query.latitude}</if> <if test="query.latitude != null "> and latitude = #{query.latitude}</if>
<if test="query.address != null and query.address != ''"> and address like concat('%', #{query.address}, '%')</if> <if test="query.address != null and query.address != ''"> and address like concat('%', #{query.address}, '%')</if>
<if test="query.picture != null and query.picture != ''"> and picture = #{query.picture}</if> <if test="query.picture != null and query.picture != ''"> and picture = #{query.picture}</if>
<if test="query.deleted != null"> and deleted = #{query.deleted}</if>
${@com.ruoyi.framework.util.DataScopeUtil@create(query.scope)
.userSetAlias("bs.user_id")
.build()
}
${query.params.dataScope} ${query.params.dataScope}
</sql> </sql>
@ -288,4 +295,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{storeId} #{storeId}
</foreach> </foreach>
</delete> </delete>
<!--logicDel-->
<update id="logicDel">
update bst_store
set deleted = true
where store_id in
<foreach item="id" collection="ids" open="(" separator="," close=")">
#{id}
</foreach>
and deleted = false
</update>
</mapper> </mapper>

View File

@ -0,0 +1,4 @@
package com.ruoyi.bst.store.service;
public interface StoreConverter {
}

View File

@ -16,10 +16,16 @@ public interface StoreService
/** /**
* 查询店铺 * 查询店铺
* *
* @param storeId 店铺主键 * @param id 店铺主键
* @return 店铺 * @return 店铺
*/ */
public StoreVO selectStoreByStoreId(Long storeId); public StoreVO selectStoreById(Long id, boolean scope);
default StoreVO selectStoreById(Long id) {
return this.selectStoreById(id, false);
}
public StoreVO selectOne(StoreQuery query);
/** /**
* 查询店铺列表 * 查询店铺列表
@ -60,4 +66,6 @@ public interface StoreService
* @return 结果 * @return 结果
*/ */
public int deleteStoreByStoreId(Long storeId); public int deleteStoreByStoreId(Long storeId);
public int logicDel(List<Long> ids);
} }

View File

@ -0,0 +1,29 @@
package com.ruoyi.bst.store.service;
import java.util.List;
public interface StoreValidator {
/**
* 判断当前用户是否可以编辑店铺
* @param storeId 分区ID
* @return 是否允许
*/
boolean canEdit(Long storeId);
/**
* 判断当前用户是否可以删除店铺
* @param storeIds 分区ID
* @return 是否允许
*/
boolean canDeleteAll(List<Long> storeIds);
/**
* 判断当前用户是否可以选择制定分区
* @param storeId 分区ID
* @return 是否允许
*/
boolean canCheckForStore(Long storeId);
}

View File

@ -1,7 +1,11 @@
package com.ruoyi.bst.store.service.impl; package com.ruoyi.bst.store.service.impl;
import java.util.List; import java.util.List;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.collection.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ruoyi.bst.store.mapper.StoreMapper; import com.ruoyi.bst.store.mapper.StoreMapper;
@ -29,9 +33,25 @@ public class StoreServiceImpl implements StoreService
* @return 店铺 * @return 店铺
*/ */
@Override @Override
public StoreVO selectStoreByStoreId(Long storeId) public StoreVO selectStoreById(Long storeId,boolean scope)
{ {
return storeMapper.selectStoreByStoreId(storeId); if (storeId == null) {
return null;
}
StoreQuery query = new StoreQuery();
query.setStoreId(storeId);
query.setScope(scope);
return this.selectOne(query);
}
@Override
public StoreVO selectOne(StoreQuery query) {
PageHelper.startPage(1, 1);
List<StoreVO> list = storeMapper.selectStoreList(query);
if(list.isEmpty()) {
ServiceUtil.assertion(true,"当前店铺信息不属于您");
}
return CollectionUtils.firstElement(list);
} }
/** /**
@ -94,4 +114,9 @@ public class StoreServiceImpl implements StoreService
{ {
return storeMapper.deleteStoreByStoreId(storeId); return storeMapper.deleteStoreByStoreId(storeId);
} }
@Override
public int logicDel(List<Long> ids) {
return storeMapper.logicDel(ids);
}
} }

View File

@ -0,0 +1,73 @@
package com.ruoyi.bst.store.service.impl;
import com.ruoyi.bst.store.domain.StoreQuery;
import com.ruoyi.bst.store.domain.StoreVO;
import com.ruoyi.bst.store.domain.enums.StorePermission;
import com.ruoyi.bst.store.service.StoreService;
import com.ruoyi.bst.store.service.StoreValidator;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.collection.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
@Service
public class StoreValidatorImpl implements StoreValidator {
@Autowired
private StoreService storeService;
@Override
public boolean canEdit(Long storeId) {
return canOperate(Arrays.asList(storeId));
}
@Override
public boolean canDeleteAll(List<Long> storeIds) {
return canOperate(storeIds);
}
@Override
public boolean canCheckForStore(Long storeId) {
return canOperate(Arrays.asList(storeId));
}
// 是否可以操作店铺
private boolean canOperate(List<Long> storeIds) {
if (SecurityUtils.isSysAdmin()) {
return true;
}
if (CollectionUtils.isEmptyElement(storeIds)) {
return true;
}
// 查询店铺
StoreQuery query = new StoreQuery();
query.setStoreIds(storeIds);
query.setScope(true);
List<StoreVO> storeVOList = storeService.selectStoreList(query);
Long userId = SecurityUtils.getUserId();
// 判断是否可以操作店铺
for (Long storeId : storeIds) {
StoreVO store = storeVOList.stream()
.filter(item -> item.getStoreId().equals(storeId))
.findFirst().orElse(null);
if (store == null) {
return false;
}
boolean canOperate = isCreater(store, userId);
if (!canOperate) {
return false;
}
}
return true;
}
private boolean isCreater(StoreVO store, Long userId) {
return store != null && store.getUserId() != null && store.getUserId().equals(userId);
}
}

View File

@ -1,14 +1,18 @@
package com.ruoyi.web.bst; package com.ruoyi.web.bst;
import com.ruoyi.bst.floor.service.FloorValidator;
import com.ruoyi.bst.part.domain.Part; import com.ruoyi.bst.part.domain.Part;
import com.ruoyi.bst.part.domain.PartQuery; import com.ruoyi.bst.part.domain.PartQuery;
import com.ruoyi.bst.part.domain.PartVO; import com.ruoyi.bst.part.domain.PartVO;
import com.ruoyi.bst.part.service.PartService; import com.ruoyi.bst.part.service.PartService;
import com.ruoyi.bst.part.service.PartValidator;
import com.ruoyi.bst.store.service.StoreValidator;
import com.ruoyi.common.annotation.Log; import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.user.service.UserValidator;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -28,15 +32,22 @@ public class PartController extends BaseController
{ {
@Autowired @Autowired
private PartService partService; private PartService partService;
@Autowired
private PartValidator partValidator;
@Autowired
private StoreValidator storeValidator;
@Autowired
private FloorValidator floorValidator;
/** /**
* 查询分区列表 * 查询分区列表
*/ */
@PreAuthorize("@ss.hasPermi('bst:part:list')") @PreAuthorize("@ss.hasPermi('bst:part:list')")
@GetMapping("/list") @GetMapping("/list")
public AjaxResult list(PartQuery partQuery) public AjaxResult list(PartQuery query)
{ {
List<PartVO> list = partService.selectPartList(partQuery); query.setScope(true);
List<PartVO> list = partService.selectPartList(query);
return success(list); return success(list);
} }
@ -48,6 +59,7 @@ public class PartController extends BaseController
@PostMapping("/export") @PostMapping("/export")
public void export(HttpServletResponse response, PartQuery query) public void export(HttpServletResponse response, PartQuery query)
{ {
query.setScope(true);
List<PartVO> list = partService.selectPartList(query); List<PartVO> list = partService.selectPartList(query);
ExcelUtil<PartVO> util = new ExcelUtil<PartVO>(PartVO.class); ExcelUtil<PartVO> util = new ExcelUtil<PartVO>(PartVO.class);
util.exportExcel(response, list, "分区数据"); util.exportExcel(response, list, "分区数据");
@ -60,7 +72,7 @@ public class PartController extends BaseController
@GetMapping(value = "/{partId}") @GetMapping(value = "/{partId}")
public AjaxResult getInfo(@PathVariable("partId") Long partId) public AjaxResult getInfo(@PathVariable("partId") Long partId)
{ {
return success(partService.selectPartByPartId(partId)); return success(partService.selectPartById(partId,true));
} }
/** /**
@ -71,6 +83,10 @@ public class PartController extends BaseController
@PostMapping @PostMapping
public AjaxResult add(@RequestBody Part part) public AjaxResult add(@RequestBody Part part)
{ {
// 判断能否选择楼层
if (!floorValidator.canCheckForFloor(part.getFloorId())) {
return AjaxResult.error("您无权选择ID为" + part.getFloorId() + "的店铺");
}
return toAjax(partService.insertPart(part)); return toAjax(partService.insertPart(part));
} }
@ -82,6 +98,9 @@ public class PartController extends BaseController
@PutMapping @PutMapping
public AjaxResult edit(@RequestBody Part part) public AjaxResult edit(@RequestBody Part part)
{ {
if (!partValidator.canEdit(part.getPartId())) {
return AjaxResult.error("您没有权限修改ID为" + part.getPartId() + "的分区");
}
return toAjax(partService.updatePart(part)); return toAjax(partService.updatePart(part));
} }
@ -90,9 +109,12 @@ public class PartController extends BaseController
*/ */
@PreAuthorize("@ss.hasPermi('bst:part:remove')") @PreAuthorize("@ss.hasPermi('bst:part:remove')")
@Log(title = "分区", businessType = BusinessType.DELETE) @Log(title = "分区", businessType = BusinessType.DELETE)
@DeleteMapping("/{partIds}") @DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] partIds) public AjaxResult remove(@PathVariable List<Long> ids)
{ {
return toAjax(partService.deletePartByPartIds(partIds)); if (!partValidator.canDeleteAll(ids)) {
return AjaxResult.error("您没有权限删除ID为" + ids + "的分区");
}
return toAjax(partService.deletePartByPartIds(ids));
} }
} }

View File

@ -4,12 +4,14 @@ import com.ruoyi.bst.store.domain.Store;
import com.ruoyi.bst.store.domain.StoreQuery; import com.ruoyi.bst.store.domain.StoreQuery;
import com.ruoyi.bst.store.domain.StoreVO; import com.ruoyi.bst.store.domain.StoreVO;
import com.ruoyi.bst.store.service.StoreService; import com.ruoyi.bst.store.service.StoreService;
import com.ruoyi.bst.store.service.StoreValidator;
import com.ruoyi.common.annotation.Log; import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.user.service.UserValidator;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -30,6 +32,11 @@ public class StoreController extends BaseController
@Autowired @Autowired
private StoreService storeService; private StoreService storeService;
@Autowired
private UserValidator userValidator;
@Autowired
private StoreValidator storeValidator;
/** /**
* 查询店铺列表 * 查询店铺列表
*/ */
@ -39,6 +46,8 @@ public class StoreController extends BaseController
{ {
startPage(); startPage();
startOrderBy(); startOrderBy();
query.setScope(true);
query.setDeleted(false);
List<StoreVO> list = storeService.selectStoreList(query); List<StoreVO> list = storeService.selectStoreList(query);
return getDataTable(list); return getDataTable(list);
} }
@ -51,6 +60,7 @@ public class StoreController extends BaseController
@PostMapping("/export") @PostMapping("/export")
public void export(HttpServletResponse response, StoreQuery query) public void export(HttpServletResponse response, StoreQuery query)
{ {
query.setScope(true);
List<StoreVO> list = storeService.selectStoreList(query); List<StoreVO> list = storeService.selectStoreList(query);
ExcelUtil<StoreVO> util = new ExcelUtil<StoreVO>(StoreVO.class); ExcelUtil<StoreVO> util = new ExcelUtil<StoreVO>(StoreVO.class);
util.exportExcel(response, list, "店铺数据"); util.exportExcel(response, list, "店铺数据");
@ -63,7 +73,7 @@ public class StoreController extends BaseController
@GetMapping(value = "/{storeId}") @GetMapping(value = "/{storeId}")
public AjaxResult getInfo(@PathVariable("storeId") Long storeId) public AjaxResult getInfo(@PathVariable("storeId") Long storeId)
{ {
return success(storeService.selectStoreByStoreId(storeId)); return success(storeService.selectStoreById(storeId,true));
} }
/** /**
@ -74,6 +84,11 @@ public class StoreController extends BaseController
@PostMapping @PostMapping
public AjaxResult add(@RequestBody Store store) public AjaxResult add(@RequestBody Store store)
{ {
// 若不能操作他人则设置为当前用户
if (!userValidator.canView(store.getUserId())) {
store.setUserId(getUserId());
}
store.setUserId(getUserId());
return toAjax(storeService.insertStore(store)); return toAjax(storeService.insertStore(store));
} }
@ -85,6 +100,13 @@ public class StoreController extends BaseController
@PutMapping @PutMapping
public AjaxResult edit(@RequestBody Store store) public AjaxResult edit(@RequestBody Store store)
{ {
if (!storeValidator.canEdit(store.getStoreId())){
return AjaxResult.error("您没有权限修改ID为" + store.getStoreId() + "的商铺信息");
}
// 若不能操作他人则不修改用户ID
if (!userValidator.canView(store.getUserId())) {
store.setUserId(null);
}
return toAjax(storeService.updateStore(store)); return toAjax(storeService.updateStore(store));
} }
@ -93,9 +115,12 @@ public class StoreController extends BaseController
*/ */
@PreAuthorize("@ss.hasPermi('bst:store:remove')") @PreAuthorize("@ss.hasPermi('bst:store:remove')")
@Log(title = "店铺", businessType = BusinessType.DELETE) @Log(title = "店铺", businessType = BusinessType.DELETE)
@DeleteMapping("/{storeIds}") @DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] storeIds) public AjaxResult remove(@PathVariable List<Long> ids)
{ {
return toAjax(storeService.deleteStoreByStoreIds(storeIds)); if (!storeValidator.canDeleteAll(ids)) {
return AjaxResult.error("您没有权限删除ID为" + ids + "的店铺信息");
}
return toAjax(storeService.logicDel(ids));
} }
} }