diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/booth/domain/Booth.java b/ruoyi-service/src/main/java/com/ruoyi/bst/booth/domain/Booth.java index 9f25c13..eb9acf9 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/booth/domain/Booth.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/booth/domain/Booth.java @@ -7,6 +7,9 @@ import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.core.domain.BaseEntity; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + /** * 卡座对象 bst_booth * @@ -22,10 +25,12 @@ public class Booth extends BaseEntity @Excel(name = "分区ID") @ApiModelProperty("分区ID") + @NotNull(message = "分区ID不能为空") private Long partId; @Excel(name = "卡座名称") @ApiModelProperty("卡座名称") + @NotBlank(message = "卡座名称不能为空") private String boothName; @Excel(name = "分区图片") diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/booth/domain/BoothQuery.java b/ruoyi-service/src/main/java/com/ruoyi/bst/booth/domain/BoothQuery.java index ae4960d..c75ca4c 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/booth/domain/BoothQuery.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/booth/domain/BoothQuery.java @@ -1,7 +1,15 @@ package com.ruoyi.bst.booth.domain; +import com.ruoyi.common.annotation.Excel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.util.List; + @Data -public class BoothQuery extends Booth { +public class BoothQuery extends BoothVO { + + @ApiModelProperty("卡座ID列表") + private List ids; + } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/booth/domain/BoothVO.java b/ruoyi-service/src/main/java/com/ruoyi/bst/booth/domain/BoothVO.java index 2bd9c33..b19a07f 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/booth/domain/BoothVO.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/booth/domain/BoothVO.java @@ -1,7 +1,14 @@ package com.ruoyi.bst.booth.domain; +import com.ruoyi.common.annotation.Excel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data public class BoothVO extends Booth{ + + @Excel(name = "分区名称") + @ApiModelProperty("分区名称") + private String partName; + } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/booth/mapper/BoothMapper.xml b/ruoyi-service/src/main/java/com/ruoyi/bst/booth/mapper/BoothMapper.xml index 30a312b..192ebcb 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/booth/mapper/BoothMapper.xml +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/booth/mapper/BoothMapper.xml @@ -14,18 +14,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select - booth_id, - part_id, - booth_name, - picture, - create_time - from bst_booth + bb.booth_id, + bb.part_id, + bb.booth_name, + bb.picture, + bb.create_time, + bp.part_name as partName, + bs.user_id + + + + + 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 and part_id = #{query.partId} and booth_name like concat('%', #{query.boothName}, '%') and picture = #{query.picture} + and bp.part_name like concat('%', #{query.partName}, '%') + ${@com.ruoyi.framework.util.DataScopeUtil@create(query.scope) + .userSetAlias("bs.user_id") + .build() + } ${query.params.dataScope} @@ -41,6 +55,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where booth_id = #{boothId} + + + insert into bst_booth @@ -151,7 +173,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" delete from bst_booth where booth_id in - + #{boothId} diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/part/domain/Part.java b/ruoyi-service/src/main/java/com/ruoyi/bst/part/domain/Part.java index fbef0ce..3e444b2 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/part/domain/Part.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/part/domain/Part.java @@ -7,6 +7,9 @@ import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.core.domain.TreeEntity; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + /** * 分区对象 bst_part * @@ -20,12 +23,14 @@ public class Part extends TreeEntity private Long partId; - @Excel(name = "店铺ID") - @ApiModelProperty("店铺ID") - private Long storeId; + @Excel(name = "楼层ID") + @ApiModelProperty("楼层ID") + @NotNull(message = "楼层ID不能为空") + private Long floorId; @Excel(name = "分区名称") @ApiModelProperty("分区名称") + @NotBlank(message = "分区名称不能为空") private String partName; @Excel(name = "分区图片") diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/part/domain/PartQuery.java b/ruoyi-service/src/main/java/com/ruoyi/bst/part/domain/PartQuery.java index 23e999a..826b07b 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/part/domain/PartQuery.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/part/domain/PartQuery.java @@ -1,7 +1,15 @@ package com.ruoyi.bst.part.domain; +import com.ruoyi.common.annotation.Excel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.util.List; + @Data -public class PartQuery extends Part { +public class PartQuery extends PartVO { + + @ApiModelProperty("分区ID列表") + private List ids; + } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/part/domain/PartVO.java b/ruoyi-service/src/main/java/com/ruoyi/bst/part/domain/PartVO.java index 10e51c7..0e08290 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/part/domain/PartVO.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/part/domain/PartVO.java @@ -7,8 +7,8 @@ import lombok.Data; @Data public class PartVO extends Part{ - @Excel(name = "店铺名称") - @ApiModelProperty("店铺名称") - private Long storeName; + @Excel(name = "楼层名称") + @ApiModelProperty("楼层名称") + private String floorName; } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/part/mapper/PartMapper.java b/ruoyi-service/src/main/java/com/ruoyi/bst/part/mapper/PartMapper.java index d973ecf..31ce752 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/part/mapper/PartMapper.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/part/mapper/PartMapper.java @@ -70,5 +70,7 @@ public interface PartMapper * @param partIds 需要删除的数据主键集合 * @return 结果 */ - public int deletePartByPartIds(Long[] partIds); + public int deletePartByPartIds(@Param("ids") List partIds); + + public List selectIdByQuery(@Param("query") PartQuery query); } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/part/mapper/PartMapper.xml b/ruoyi-service/src/main/java/com/ruoyi/bst/part/mapper/PartMapper.xml index a0383ee..0b711cd 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/part/mapper/PartMapper.xml +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/part/mapper/PartMapper.xml @@ -6,8 +6,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - + @@ -16,21 +15,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select bp.part_id, - bp.parent_id, - bp.store_id, + bp.floor_id, bp.part_name, bp.picture, bp.create_time, - bs.store_name + bs.store_name, + bs.user_id, + bf.floor_name as floorName + + + + 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 - and parent_id = #{query.parentId} - and store_id = #{query.storeId} + + and floor_id = #{query.floor_id} and part_name like concat('%', #{query.partName}, '%') and picture = #{query.picture} + and bf.floor_name like concat('%', #{query.floorName}, '%') + ${@com.ruoyi.framework.util.DataScopeUtil@create(query.scope) + .userSetAlias("bs.user_id") + .build() + } ${query.params.dataScope} @@ -43,21 +53,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + insert into bst_part - parent_id, - store_id, + floor_id, part_name, picture, create_time, - #{parentId}, - #{storeId}, + #{floorId}, #{partName}, #{picture}, #{createTime}, @@ -67,7 +83,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" insert into bst_part - parent_id, + floor_id store_id, part_name, picture, @@ -76,10 +92,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" values - #{i.parentId}, - default, - #{i.storeId}, - default, + #{i.floorId}, + default, #{i.partName}, default, #{i.picture}, @@ -93,20 +107,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update bst_part - - - - WHEN #{item.part_id} THEN #{item.parentId} - - - WHEN #{item.part_id} THEN `parent_id` - - - - - WHEN #{item.part_id} THEN #{item.storeId} + + WHEN #{item.part_id} THEN #{item.floorId} WHEN #{item.part_id} THEN `store_id` @@ -159,8 +163,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - parent_id = #{data.parentId}, - store_id = #{data.storeId}, + store_id = #{data.floorId}, part_name = #{data.partName}, picture = #{data.picture}, create_time = #{data.createTime}, @@ -172,7 +175,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" delete from bst_part where part_id in - + #{partId} diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/part/service/PartService.java b/ruoyi-service/src/main/java/com/ruoyi/bst/part/service/PartService.java index 9f410ef..7b3c7ae 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/part/service/PartService.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/part/service/PartService.java @@ -16,10 +16,16 @@ public interface PartService /** * 查询分区 * - * @param partId 分区主键 + * @param id 分区主键 * @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 需要删除的分区主键集合 * @return 结果 */ - public int deletePartByPartIds(Long[] partIds); + public int deletePartByPartIds(List partIds); /** * 删除分区信息 @@ -60,4 +66,6 @@ public interface PartService * @return 结果 */ public int deletePartByPartId(Long partId); + + Long getUserId(Part part); } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/part/service/PartValidator.java b/ruoyi-service/src/main/java/com/ruoyi/bst/part/service/PartValidator.java new file mode 100644 index 0000000..77a70ce --- /dev/null +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/part/service/PartValidator.java @@ -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 partIds); +} diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/part/service/impl/PartServiceImpl.java b/ruoyi-service/src/main/java/com/ruoyi/bst/part/service/impl/PartServiceImpl.java index 41528b0..6316e05 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/part/service/impl/PartServiceImpl.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/part/service/impl/PartServiceImpl.java @@ -1,7 +1,12 @@ package com.ruoyi.bst.part.service.impl; 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.ServiceUtil; +import com.ruoyi.common.utils.collection.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.bst.part.mapper.PartMapper; @@ -21,17 +26,32 @@ public class PartServiceImpl implements PartService { @Autowired private PartMapper partMapper; + @Autowired + private StoreService storeService; /** * 查询分区 * - * @param partId 分区主键 + * @param id 分区主键 * @return 分区 */ @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 list = partMapper.selectPartList(query); + return CollectionUtils.firstElement(list); } /** @@ -78,7 +98,7 @@ public class PartServiceImpl implements PartService * @return 结果 */ @Override - public int deletePartByPartIds(Long[] partIds) + public int deletePartByPartIds(List partIds) { return partMapper.deletePartByPartIds(partIds); } @@ -94,4 +114,9 @@ public class PartServiceImpl implements PartService { return partMapper.deletePartByPartId(partId); } + + @Override + public Long getUserId(Part part) { + return storeService.selectStoreById(part.getFloorId()).getUserId(); + } } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/part/service/impl/PartValidatorImpl.java b/ruoyi-service/src/main/java/com/ruoyi/bst/part/service/impl/PartValidatorImpl.java new file mode 100644 index 0000000..6c7e291 --- /dev/null +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/part/service/impl/PartValidatorImpl.java @@ -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 partIds) { + return canOperate(partIds); + } + + // 是否可以操作运营区 + private boolean canOperate(List partIds) { + return hasPermission(partIds); + } + + // 是否有运营区权限 + private boolean hasPermission(List partIds) { + if (SecurityUtils.isSysAdmin()) { + return true; + } + if (CollectionUtils.isEmptyElement(partIds)) { + return true; + } + // 查询运营区 + PartQuery query = new PartQuery(); + query.setIds(partIds); + query.setScope(true); + List partIdList = partMapper.selectIdByQuery(query); + return new HashSet<>(partIdList).containsAll(partIds); + } + +} diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/store/domain/Store.java b/ruoyi-service/src/main/java/com/ruoyi/bst/store/domain/Store.java index d1d34f0..86749b8 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/store/domain/Store.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/store/domain/Store.java @@ -5,6 +5,7 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.util.Date; import com.fasterxml.jackson.annotation.JsonFormat; +import com.ruoyi.common.core.validate.ValidGroup; import io.swagger.annotations.ApiModelProperty; import lombok.Data; 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.core.domain.BaseEntity; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + /** * 店铺对象 bst_store * @@ -31,24 +35,29 @@ public class Store extends BaseEntity @Excel(name = "店铺名称") @ApiModelProperty("店铺名称") + @NotBlank(message = "店铺名称不能为空",groups = {ValidGroup.Create.class}) private String storeName; @Excel(name = "联系人") @ApiModelProperty("联系人") + @NotBlank(message = "联系人不能为空",groups = {ValidGroup.Create.class}) private String userName; @Excel(name = "联系电话") @ApiModelProperty("联系电话") + @NotBlank(message = "联系电话不能为空",groups = {ValidGroup.Create.class}) private String phone; @JsonFormat(pattern = "HH:mm") @Excel(name = "营业开始时间", width = 30, dateFormat = "HH:mm") @ApiModelProperty("营业开始时间") + @NotNull(message = "营业开始时间不能为空",groups = {ValidGroup.Create.class}) private LocalTime startTime; @JsonFormat(pattern = "HH:mm") @Excel(name = "营业结束时间", width = 30, dateFormat = "HH:mm") @ApiModelProperty("营业结束时间") + @NotNull(message = "营业结束时间不能为空",groups = {ValidGroup.Create.class}) private LocalTime endTime; @Excel(name = "经度") @@ -61,6 +70,7 @@ public class Store extends BaseEntity @Excel(name = "详细地址") @ApiModelProperty("详细地址") + @NotBlank(message = "详细地址不能为空",groups = {ValidGroup.Create.class}) private String address; @Excel(name = "门店照片") diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/store/domain/StoreQuery.java b/ruoyi-service/src/main/java/com/ruoyi/bst/store/domain/StoreQuery.java index de89b24..977d8a5 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/store/domain/StoreQuery.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/store/domain/StoreQuery.java @@ -1,7 +1,15 @@ package com.ruoyi.bst.store.domain; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.util.List; + @Data -public class StoreQuery extends Store{ +public class StoreQuery extends StoreVO{ + + @ApiModelProperty("店铺ID列表") + private List storeIds; + + } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/store/domain/enums/StorePermission.java b/ruoyi-service/src/main/java/com/ruoyi/bst/store/domain/enums/StorePermission.java new file mode 100644 index 0000000..b6ecb0a --- /dev/null +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/store/domain/enums/StorePermission.java @@ -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; + +} diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/store/mapper/StoreMapper.java b/ruoyi-service/src/main/java/com/ruoyi/bst/store/mapper/StoreMapper.java index 1e102cd..e49fef8 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/store/mapper/StoreMapper.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/store/mapper/StoreMapper.java @@ -5,6 +5,7 @@ import com.ruoyi.bst.store.domain.Store; import com.ruoyi.bst.store.domain.StoreVO; import com.ruoyi.bst.store.domain.StoreQuery; import org.apache.ibatis.annotations.Param; +import org.springframework.security.core.parameters.P; /** * 店铺Mapper接口 @@ -71,4 +72,6 @@ public interface StoreMapper * @return 结果 */ public int deleteStoreByStoreIds(Long[] storeIds); + + int logicDel(@Param("ids") List ids); } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/store/mapper/StoreMapper.xml b/ruoyi-service/src/main/java/com/ruoyi/bst/store/mapper/StoreMapper.xml index 92b71e8..38bb4d0 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/store/mapper/StoreMapper.xml +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/store/mapper/StoreMapper.xml @@ -17,26 +17,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + select - store_id, - user_id, - store_name, - user_name, - phone, - start_time, - end_time, - longitude, - latitude, - address, - picture, - create_time - from bst_store + bs.store_id, + bs.user_id, + bs.store_name, + bs.user_name, + bs.phone, + bs.start_time, + bs.end_time, + bs.longitude, + bs.latitude, + bs.address, + bs.picture, + bs.create_time + from bst_store bs + and store_id = #{query.storeId} and user_id = #{query.userId} and store_name like concat('%', #{query.storeName}, '%') and user_name like concat('%', #{query.userName}, '%') @@ -47,6 +49,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and latitude = #{query.latitude} and address like concat('%', #{query.address}, '%') and picture = #{query.picture} + and deleted = #{query.deleted} + ${@com.ruoyi.framework.util.DataScopeUtil@create(query.scope) + .userSetAlias("bs.user_id") + .build() + } ${query.params.dataScope} @@ -288,4 +295,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{storeId} + + + + update bst_store + set deleted = true + where store_id in + + #{id} + + and deleted = false + diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/store/service/StoreConverter.java b/ruoyi-service/src/main/java/com/ruoyi/bst/store/service/StoreConverter.java new file mode 100644 index 0000000..60e7339 --- /dev/null +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/store/service/StoreConverter.java @@ -0,0 +1,4 @@ +package com.ruoyi.bst.store.service; + +public interface StoreConverter { +} diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/store/service/StoreService.java b/ruoyi-service/src/main/java/com/ruoyi/bst/store/service/StoreService.java index 24456f1..c83bf90 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/store/service/StoreService.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/store/service/StoreService.java @@ -16,10 +16,16 @@ public interface StoreService /** * 查询店铺 * - * @param storeId 店铺主键 + * @param id 店铺主键 * @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 结果 */ public int deleteStoreByStoreId(Long storeId); + + public int logicDel(List ids); } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/store/service/StoreValidator.java b/ruoyi-service/src/main/java/com/ruoyi/bst/store/service/StoreValidator.java new file mode 100644 index 0000000..946e8f9 --- /dev/null +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/store/service/StoreValidator.java @@ -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 storeIds); + + /** + * 判断当前用户是否可以选择制定分区 + * @param storeId 分区ID + * @return 是否允许 + */ + boolean canCheckForStore(Long storeId); + +} diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/store/service/impl/StoreServiceImpl.java b/ruoyi-service/src/main/java/com/ruoyi/bst/store/service/impl/StoreServiceImpl.java index 462214c..4e3871f 100644 --- a/ruoyi-service/src/main/java/com/ruoyi/bst/store/service/impl/StoreServiceImpl.java +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/store/service/impl/StoreServiceImpl.java @@ -1,7 +1,11 @@ package com.ruoyi.bst.store.service.impl; import java.util.List; + +import com.github.pagehelper.PageHelper; 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.stereotype.Service; import com.ruoyi.bst.store.mapper.StoreMapper; @@ -29,9 +33,25 @@ public class StoreServiceImpl implements StoreService * @return 店铺 */ @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 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); } + + @Override + public int logicDel(List ids) { + return storeMapper.logicDel(ids); + } } diff --git a/ruoyi-service/src/main/java/com/ruoyi/bst/store/service/impl/StoreValidatorImpl.java b/ruoyi-service/src/main/java/com/ruoyi/bst/store/service/impl/StoreValidatorImpl.java new file mode 100644 index 0000000..ba9c0fc --- /dev/null +++ b/ruoyi-service/src/main/java/com/ruoyi/bst/store/service/impl/StoreValidatorImpl.java @@ -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 storeIds) { + return canOperate(storeIds); + } + + @Override + public boolean canCheckForStore(Long storeId) { + return canOperate(Arrays.asList(storeId)); + } + + // 是否可以操作店铺 + private boolean canOperate(List storeIds) { + if (SecurityUtils.isSysAdmin()) { + return true; + } + if (CollectionUtils.isEmptyElement(storeIds)) { + return true; + } + // 查询店铺 + StoreQuery query = new StoreQuery(); + query.setStoreIds(storeIds); + query.setScope(true); + List 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); + } +} + diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/bst/PartController.java b/ruoyi-web/src/main/java/com/ruoyi/web/bst/PartController.java index 9aab6c7..eb73d32 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/web/bst/PartController.java +++ b/ruoyi-web/src/main/java/com/ruoyi/web/bst/PartController.java @@ -1,14 +1,18 @@ 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.PartQuery; import com.ruoyi.bst.part.domain.PartVO; 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.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.system.user.service.UserValidator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; @@ -28,15 +32,22 @@ public class PartController extends BaseController { @Autowired private PartService partService; + @Autowired + private PartValidator partValidator; + @Autowired + private StoreValidator storeValidator; + @Autowired + private FloorValidator floorValidator; /** * 查询分区列表 */ @PreAuthorize("@ss.hasPermi('bst:part:list')") @GetMapping("/list") - public AjaxResult list(PartQuery partQuery) + public AjaxResult list(PartQuery query) { - List list = partService.selectPartList(partQuery); + query.setScope(true); + List list = partService.selectPartList(query); return success(list); } @@ -48,6 +59,7 @@ public class PartController extends BaseController @PostMapping("/export") public void export(HttpServletResponse response, PartQuery query) { + query.setScope(true); List list = partService.selectPartList(query); ExcelUtil util = new ExcelUtil(PartVO.class); util.exportExcel(response, list, "分区数据"); @@ -60,7 +72,7 @@ public class PartController extends BaseController @GetMapping(value = "/{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 public AjaxResult add(@RequestBody Part part) { + // 判断能否选择楼层 + if (!floorValidator.canCheckForFloor(part.getFloorId())) { + return AjaxResult.error("您无权选择ID为" + part.getFloorId() + "的店铺"); + } return toAjax(partService.insertPart(part)); } @@ -82,6 +98,9 @@ public class PartController extends BaseController @PutMapping public AjaxResult edit(@RequestBody Part part) { + if (!partValidator.canEdit(part.getPartId())) { + return AjaxResult.error("您没有权限修改ID为" + part.getPartId() + "的分区"); + } return toAjax(partService.updatePart(part)); } @@ -90,9 +109,12 @@ public class PartController extends BaseController */ @PreAuthorize("@ss.hasPermi('bst:part:remove')") @Log(title = "分区", businessType = BusinessType.DELETE) - @DeleteMapping("/{partIds}") - public AjaxResult remove(@PathVariable Long[] partIds) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable List ids) { - return toAjax(partService.deletePartByPartIds(partIds)); + if (!partValidator.canDeleteAll(ids)) { + return AjaxResult.error("您没有权限删除ID为" + ids + "的分区"); + } + return toAjax(partService.deletePartByPartIds(ids)); } } diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/bst/StoreController.java b/ruoyi-web/src/main/java/com/ruoyi/web/bst/StoreController.java index 34a658c..2fc7caf 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/web/bst/StoreController.java +++ b/ruoyi-web/src/main/java/com/ruoyi/web/bst/StoreController.java @@ -4,12 +4,14 @@ import com.ruoyi.bst.store.domain.Store; import com.ruoyi.bst.store.domain.StoreQuery; import com.ruoyi.bst.store.domain.StoreVO; import com.ruoyi.bst.store.service.StoreService; +import com.ruoyi.bst.store.service.StoreValidator; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.system.user.service.UserValidator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; @@ -30,6 +32,11 @@ public class StoreController extends BaseController @Autowired private StoreService storeService; + @Autowired + private UserValidator userValidator; + @Autowired + private StoreValidator storeValidator; + /** * 查询店铺列表 */ @@ -39,6 +46,8 @@ public class StoreController extends BaseController { startPage(); startOrderBy(); + query.setScope(true); + query.setDeleted(false); List list = storeService.selectStoreList(query); return getDataTable(list); } @@ -51,6 +60,7 @@ public class StoreController extends BaseController @PostMapping("/export") public void export(HttpServletResponse response, StoreQuery query) { + query.setScope(true); List list = storeService.selectStoreList(query); ExcelUtil util = new ExcelUtil(StoreVO.class); util.exportExcel(response, list, "店铺数据"); @@ -63,7 +73,7 @@ public class StoreController extends BaseController @GetMapping(value = "/{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 public AjaxResult add(@RequestBody Store store) { + // 若不能操作他人,则设置为当前用户 + if (!userValidator.canView(store.getUserId())) { + store.setUserId(getUserId()); + } + store.setUserId(getUserId()); return toAjax(storeService.insertStore(store)); } @@ -85,6 +100,13 @@ public class StoreController extends BaseController @PutMapping 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)); } @@ -93,9 +115,12 @@ public class StoreController extends BaseController */ @PreAuthorize("@ss.hasPermi('bst:store:remove')") @Log(title = "店铺", businessType = BusinessType.DELETE) - @DeleteMapping("/{storeIds}") - public AjaxResult remove(@PathVariable Long[] storeIds) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable List ids) { - return toAjax(storeService.deleteStoreByStoreIds(storeIds)); + if (!storeValidator.canDeleteAll(ids)) { + return AjaxResult.error("您没有权限删除ID为" + ids + "的店铺信息"); + } + return toAjax(storeService.logicDel(ids)); } }