diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/store/domain/Store.java b/smart-switch-service/src/main/java/com/ruoyi/ss/store/domain/Store.java index 790fb2fd..9945d487 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/store/domain/Store.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/store/domain/Store.java @@ -136,16 +136,19 @@ public class Store extends BaseEntity @ApiModelProperty("联系人") @NotNull(message = "联系人不允许为空", groups = {ValidGroup.Create.class, ValidGroup.FrontCreate.class}) @Size(max = 60, message = "联系人长度不能超过60个字符") + @JsonView(JsonViewProfile.App.class) private String contactName; @ApiModelProperty("联系电话") @NotNull(message = "联系电话不允许为空", groups = {ValidGroup.Create.class, ValidGroup.FrontCreate.class}) @Size(min = 11, max = 11, message = "联系电话长度必须为11位") @Pattern(regexp = RegexpUtils.MOBILE_PHONE_REGEXP, message = "联系电话格式不符合要求") + @JsonView(JsonViewProfile.App.class) private String contactMobile; @ApiModelProperty("是否展示店铺") @NotNull(message = "是否展示店铺不允许为空", groups = {ValidGroup.Create.class, ValidGroup.FrontCreate.class}) + @JsonView(JsonViewProfile.AppMch.class) private Boolean show; @ApiModelProperty("状态") diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/store/mapper/StoreMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/store/mapper/StoreMapper.xml index e85b604b..c4157bd1 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/store/mapper/StoreMapper.xml +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/store/mapper/StoreMapper.xml @@ -197,7 +197,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" user_id = #{data.userId}, group_sort = #{data.groupSort}, picture = #{data.picture}, - address = #{data.address}, + address = #{data.address}, lng = #{data.lng}, lat = #{data.lat}, business_time_start = #{data.businessTimeStart}, @@ -216,7 +216,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - update sm_store + update sm_store ss diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/store/service/StoreValidator.java b/smart-switch-service/src/main/java/com/ruoyi/ss/store/service/StoreValidator.java index a42045c1..2a18c684 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/store/service/StoreValidator.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/store/service/StoreValidator.java @@ -78,7 +78,12 @@ public interface StoreValidator { ValidateResult preSetDefaultByApp(Long userId, Long storeId); /** - * 是否正在变更中 + * 是否正在审核中 */ boolean isApproving(Store store); + + /** + * 是否正在审核中 + */ + boolean hasApproving(List ids); } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/store/service/impl/StoreValidatorImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/store/service/impl/StoreValidatorImpl.java index 8073bac9..5a6a1fa3 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/store/service/impl/StoreValidatorImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/store/service/impl/StoreValidatorImpl.java @@ -55,6 +55,11 @@ public class StoreValidatorImpl extends BaseValidator implements StoreValidator return error("当前店铺存在设备,不能删除"); } + // 判断是否正在审核中 + if (this.hasApproving(ids)) { + return error("当前有店铺正在审核中,请稍后重试"); + } + return success(); } @@ -267,6 +272,22 @@ public class StoreValidatorImpl extends BaseValidator implements StoreValidator return store != null && StoreStatus.APPROVING.getStatus().equals(store.getStatus()); } + /** + * 是否正在审核中 + * + * @param ids + */ + @Override + public boolean hasApproving(List ids) { + List list = storeService.selectStoreByIds(ids); + for (StoreVo store : list) { + if (this.isApproving(store)) { + return true; + } + } + return false; + } + /** * 校验时间是符合规则 diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/domain/StoreApply.java b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/domain/StoreApply.java index f68b2ef9..3cd047f9 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/domain/StoreApply.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/domain/StoreApply.java @@ -1,5 +1,7 @@ package com.ruoyi.ss.storeApply.domain; +import com.fasterxml.jackson.annotation.JsonView; +import com.ruoyi.common.core.domain.JsonViewProfile; import com.ruoyi.ss.store.domain.Store; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -8,6 +10,8 @@ import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.core.domain.BaseEntity; +import java.time.LocalDateTime; + /** * 店铺审核对象 ss_store_apply * @@ -19,23 +23,27 @@ public class StoreApply extends BaseEntity { private static final long serialVersionUID = 1L; - @ApiModelProperty("${comment}") + @JsonView(JsonViewProfile.AppMch.class) private Long id; @Excel(name = "审核类型") @ApiModelProperty("审核类型") + @JsonView(JsonViewProfile.AppMch.class) private String applyType; @Excel(name = "审核状态") @ApiModelProperty("审核状态") + @JsonView(JsonViewProfile.AppMch.class) private String status; @Excel(name = "店铺id") @ApiModelProperty("店铺id") + @JsonView(JsonViewProfile.AppMch.class) private Long storeId; @Excel(name = "提交人id") @ApiModelProperty("提交人id") + @JsonView(JsonViewProfile.AppMch.class) private Long userId; @Excel(name = "审核人id") @@ -44,18 +52,22 @@ public class StoreApply extends BaseEntity @Excel(name = "审核时间") @ApiModelProperty("审核时间") - private Long verifyTime; + @JsonView(JsonViewProfile.AppMch.class) + private LocalDateTime verifyTime; @Excel(name = "审核意见") @ApiModelProperty("审核意见") + @JsonView(JsonViewProfile.AppMch.class) private String verifyRemark; @Excel(name = "旧数据json") @ApiModelProperty("旧数据json") + @JsonView(JsonViewProfile.AppMch.class) private Store oldData; @Excel(name = "新数据json") @ApiModelProperty("新数据json") + @JsonView(JsonViewProfile.AppMch.class) private Store newData; } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/domain/StoreApplyVO.java b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/domain/StoreApplyVO.java index f0fe317e..eeba3f1e 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/domain/StoreApplyVO.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/domain/StoreApplyVO.java @@ -1,5 +1,7 @@ package com.ruoyi.ss.storeApply.domain; +import com.fasterxml.jackson.annotation.JsonView; +import com.ruoyi.common.core.domain.JsonViewProfile; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -11,11 +13,14 @@ import lombok.Data; public class StoreApplyVO extends StoreApply { @ApiModelProperty("店铺名称") + @JsonView(JsonViewProfile.AppMch.class) private String storeName; @ApiModelProperty("提交人名称") + @JsonView(JsonViewProfile.AppMch.class) private String userName; @ApiModelProperty("审核人名称") + @JsonView(JsonViewProfile.AppMch.class) private String verifyName; } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/domain/bo/StoreApplyApprovalBO.java b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/domain/bo/StoreApplyApprovalBO.java new file mode 100644 index 00000000..c6cfb3ff --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/domain/bo/StoreApplyApprovalBO.java @@ -0,0 +1,38 @@ +package com.ruoyi.ss.storeApply.domain.bo; + +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.ss.store.domain.StoreVo; +import com.ruoyi.ss.storeApply.domain.StoreApply; +import com.ruoyi.ss.storeApply.domain.StoreApplyVO; +import com.ruoyi.ss.storeApply.domain.dto.StoreApplyApprovalDTO; +import lombok.Data; + +/** + * 店铺申请审核BO + * @author wjh + * 2024/8/5 + */ +@Data +public class StoreApplyApprovalBO { + + /** + * 原参数 + */ + private StoreApplyApprovalDTO dto; + + /** + * 审核单 + */ + private StoreApplyVO apply; + + /** + * 审核人 + */ + private SysUser verifyUser; + + /** + * 店铺信息 + */ + private StoreVo store; + +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/domain/dto/StoreApplyApprovalDTO.java b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/domain/dto/StoreApplyApprovalDTO.java new file mode 100644 index 00000000..aa03c9a4 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/domain/dto/StoreApplyApprovalDTO.java @@ -0,0 +1,27 @@ +package com.ruoyi.ss.storeApply.domain.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +/** + * @author wjh + * 2024/8/5 + */ +@Data +public class StoreApplyApprovalDTO { + + @ApiModelProperty("申请id") + @NotNull(message = "申请ID不允许为空") + private Long id; + + @ApiModelProperty("申请是否通过") + @NotNull(message = "是否通过不允许为空") + private Boolean pass; + + @ApiModelProperty("审核意见") + @Size(max = 200, message = "审核意见长度不能超过200个字符") + private String verifyRemark; +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/mapper/StoreApplyMapper.java b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/mapper/StoreApplyMapper.java index 1d9110c4..81f58bf4 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/mapper/StoreApplyMapper.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/mapper/StoreApplyMapper.java @@ -61,4 +61,14 @@ public interface StoreApplyMapper * @return 结果 */ public int deleteStoreApplyByIds(Long[] ids); + + /** + * 条件更新 + */ + int updateByQuery(@Param("data") StoreApply data, @Param("query") StoreApplyQuery query); + + /** + * 查询一个 + */ + StoreApplyVO selectOne(@Param("query") StoreApplyQuery query); } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/mapper/StoreApplyMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/mapper/StoreApplyMapper.xml index a39da005..a7b70f8f 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/mapper/StoreApplyMapper.xml +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/mapper/StoreApplyMapper.xml @@ -56,6 +56,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where id = #{id} + + insert into ss_store_apply @@ -87,20 +94,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update ss_store_apply - apply_type = #{data.applyType}, - `status` = #{data.status}, - store_id = #{data.storeId}, - create_time = #{data.createTime}, - user_id = #{data.userId}, - verify_id = #{data.verifyId}, - verify_time = #{data.verifyTime}, - verify_remark = #{data.verifyRemark}, - old_data = #{data.oldData,typeHandler=com.ruoyi.ss.storeApply.mapper.typehandler.StoreJsonTypeHandler}, - new_data = #{data.newData,typeHandler=com.ruoyi.ss.storeApply.mapper.typehandler.StoreJsonTypeHandler}, + where id = #{data.id} + + apply_type = #{data.applyType}, + `status` = #{data.status}, + store_id = #{data.storeId}, + create_time = #{data.createTime}, + user_id = #{data.userId}, + verify_id = #{data.verifyId}, + verify_time = #{data.verifyTime}, + verify_remark = #{data.verifyRemark}, + old_data = #{data.oldData,typeHandler=com.ruoyi.ss.storeApply.mapper.typehandler.StoreJsonTypeHandler}, + new_data = #{data.newData,typeHandler=com.ruoyi.ss.storeApply.mapper.typehandler.StoreJsonTypeHandler}, + + + + update ss_store_apply ssa + + + + + + + + delete from ss_store_apply where id = #{id} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/StoreApplyConverter.java b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/StoreApplyConverter.java index 0272b4e7..c996e3ba 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/StoreApplyConverter.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/StoreApplyConverter.java @@ -2,6 +2,8 @@ package com.ruoyi.ss.storeApply.service; import com.ruoyi.ss.store.domain.StoreBO; import com.ruoyi.ss.storeApply.domain.StoreApply; +import com.ruoyi.ss.storeApply.domain.bo.StoreApplyApprovalBO; +import com.ruoyi.ss.storeApply.domain.dto.StoreApplyApprovalDTO; import com.ruoyi.ss.storeApply.domain.enums.StoreApplyType; /** @@ -15,4 +17,9 @@ public interface StoreApplyConverter { */ StoreApply toPo(StoreBO store, Long userId, StoreApplyType type); + /** + * 审核DTO 转为 BO + */ + StoreApplyApprovalBO toBO(StoreApplyApprovalDTO dto); + } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/StoreApplyService.java b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/StoreApplyService.java index fd06ccc8..6a6ac71d 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/StoreApplyService.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/StoreApplyService.java @@ -6,6 +6,7 @@ import com.ruoyi.ss.store.domain.StoreBO; import com.ruoyi.ss.storeApply.domain.StoreApply; import com.ruoyi.ss.storeApply.domain.StoreApplyVO; import com.ruoyi.ss.storeApply.domain.StoreApplyQuery; +import com.ruoyi.ss.storeApply.domain.bo.StoreApplyApprovalBO; /** * 店铺审核Service接口 @@ -62,4 +63,24 @@ public interface StoreApplyService * @return 结果 */ public int deleteStoreApplyById(Long id); + + /** + * 审核 + */ + int approval(StoreApplyApprovalBO bo); + + /** + * 条件更新 + */ + int updateByQuery(StoreApply data, StoreApplyQuery query); + + /** + * 查询一个 + */ + StoreApplyVO selectOne(StoreApplyQuery query); + + /** + * 取消申请 + */ + int cancel(Long id); } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/StoreApplyValidator.java b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/StoreApplyValidator.java new file mode 100644 index 00000000..d1ab4977 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/StoreApplyValidator.java @@ -0,0 +1,16 @@ +package com.ruoyi.ss.storeApply.service; + +import com.ruoyi.ss.storeApply.domain.StoreApplyVO; + +/** + * @author wjh + * 2024/8/5 + */ +public interface StoreApplyValidator { + + /** + * 申请是否属于用户 + */ + boolean isBelong(StoreApplyVO apply, Long userId); + +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/impl/StoreApplyConverterImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/impl/StoreApplyConverterImpl.java index ccb88bdc..79705b30 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/impl/StoreApplyConverterImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/impl/StoreApplyConverterImpl.java @@ -1,13 +1,18 @@ package com.ruoyi.ss.storeApply.service.impl; +import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.ServiceUtil; import com.ruoyi.ss.store.domain.StoreBO; import com.ruoyi.ss.store.domain.StoreVo; import com.ruoyi.ss.store.service.StoreService; import com.ruoyi.ss.storeApply.domain.StoreApply; +import com.ruoyi.ss.storeApply.domain.StoreApplyVO; +import com.ruoyi.ss.storeApply.domain.bo.StoreApplyApprovalBO; +import com.ruoyi.ss.storeApply.domain.dto.StoreApplyApprovalDTO; import com.ruoyi.ss.storeApply.domain.enums.StoreApplyStatus; import com.ruoyi.ss.storeApply.domain.enums.StoreApplyType; import com.ruoyi.ss.storeApply.service.StoreApplyConverter; +import com.ruoyi.ss.storeApply.service.StoreApplyService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -21,6 +26,9 @@ public class StoreApplyConverterImpl implements StoreApplyConverter { @Autowired private StoreService storeService; + @Autowired + private StoreApplyService storeApplyService; + /** * 创建变更申请 * @@ -50,4 +58,27 @@ public class StoreApplyConverterImpl implements StoreApplyConverter { return po; } + + /** + * 审核DTO 转为 BO + * + * @param dto + */ + @Override + public StoreApplyApprovalBO toBO(StoreApplyApprovalDTO dto) { + if (dto == null) { + return null; + } + StoreApplyVO apply = storeApplyService.selectStoreApplyById(dto.getId()); + ServiceUtil.assertion(apply == null, "申请不存在"); + + StoreVo store = storeService.selectSmStoreById(apply.getStoreId()); + + StoreApplyApprovalBO bo = new StoreApplyApprovalBO(); + bo.setApply(apply); + bo.setDto(dto); + bo.setVerifyUser(SecurityUtils.getLoginUser().getUser()); + bo.setStore(store); + return bo; + } } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/impl/StoreApplyServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/impl/StoreApplyServiceImpl.java index de683c80..5798d41b 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/impl/StoreApplyServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/impl/StoreApplyServiceImpl.java @@ -1,8 +1,19 @@ package com.ruoyi.ss.storeApply.service.impl; +import java.time.LocalDateTime; import java.util.List; + +import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.common.utils.ServiceUtil; +import com.ruoyi.ss.store.domain.Store; import com.ruoyi.ss.store.domain.StoreBO; +import com.ruoyi.ss.store.domain.StoreQuery; +import com.ruoyi.ss.store.domain.enums.StoreStatus; +import com.ruoyi.ss.store.service.StoreService; +import com.ruoyi.ss.storeApply.domain.bo.StoreApplyApprovalBO; +import com.ruoyi.ss.storeApply.domain.dto.StoreApplyApprovalDTO; +import com.ruoyi.ss.storeApply.domain.enums.StoreApplyStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.ss.storeApply.mapper.StoreApplyMapper; @@ -10,6 +21,7 @@ import com.ruoyi.ss.storeApply.domain.StoreApply; import com.ruoyi.ss.storeApply.domain.StoreApplyVO; import com.ruoyi.ss.storeApply.domain.StoreApplyQuery; import com.ruoyi.ss.storeApply.service.StoreApplyService; +import org.springframework.transaction.support.TransactionTemplate; /** * 店铺审核Service业务层处理 @@ -23,6 +35,12 @@ public class StoreApplyServiceImpl implements StoreApplyService @Autowired private StoreApplyMapper storeApplyMapper; + @Autowired + private TransactionTemplate transactionTemplate; + + @Autowired + private StoreService storeService; + /** * 查询店铺审核 * @@ -96,4 +114,106 @@ public class StoreApplyServiceImpl implements StoreApplyService return storeApplyMapper.deleteStoreApplyById(id); } + @Override + public int approval(StoreApplyApprovalBO bo) { + ServiceUtil.assertion(bo == null, "参数错误"); + + StoreApplyApprovalDTO dto = bo.getDto(); + ServiceUtil.assertion(dto == null, "原参数不存在"); + + StoreApplyVO apply = bo.getApply(); + ServiceUtil.assertion(apply == null, "申请不存在"); + ServiceUtil.assertion(apply.getId() == null, "申请参数有误"); + + SysUser verifyUser = bo.getVerifyUser(); + ServiceUtil.assertion(verifyUser == null, "审核人不存在"); + + Integer result = transactionTemplate.execute(status -> { + // 修改状态 + StoreApply data = new StoreApply(); + data.setStatus(dto.getPass() ? StoreApplyStatus.PASS.getStatus() : StoreApplyStatus.REJECT.getStatus()); + data.setVerifyId(verifyUser.getUserId()); + data.setVerifyTime(LocalDateTime.now()); + data.setVerifyRemark(dto.getVerifyRemark()); + StoreApplyQuery query = new StoreApplyQuery(); + query.setId(apply.getId()); + query.setStatus(StoreApplyStatus.WAIT_AUDIT.getStatus()); + int update = this.updateByQuery(data, query); + ServiceUtil.assertion(update != 1, "当前申请数据发生变化,请刷新后重试"); + + if (dto.getPass()) { + // 通过,应用到设备中 + int applyCount = this.applyToStore(apply); + ServiceUtil.assertion(applyCount != 1, "应用到店铺失败,请刷新后重试"); + } else { + // 驳回,店铺修改状态为正常 + Store store = new Store(); + store.setStoreId(apply.getStoreId()); + store.setStatus(StoreStatus.NORMAL.getStatus()); + int storeUpdate = storeService.updateSmStore(store); + ServiceUtil.assertion(storeUpdate != 1, "店铺状态修改失败,请刷新后重试"); + } + + return update; + }); + + return result == null ? 0 : result; + } + + /** + * 应用到设备中 + */ + private int applyToStore(StoreApply apply) { + Store newData = apply.getNewData(); + if (newData == null) { + return 0; + } + newData.setStoreId(apply.getStoreId()); + newData.setStatus(StoreStatus.NORMAL.getStatus()); + newData.setEnabled(true); + return storeService.updateSmStore(newData); + } + + @Override + public int updateByQuery(StoreApply data, StoreApplyQuery query) { + if (query == null) { + return 0; + } + return storeApplyMapper.updateByQuery(data, query); + } + + @Override + public StoreApplyVO selectOne(StoreApplyQuery query) { + return storeApplyMapper.selectOne(query); + } + + @Override + public int cancel(Long id) { + StoreApplyVO apply = selectStoreApplyById(id); + ServiceUtil.assertion(apply == null, "申请不存在"); + + Integer result = transactionTemplate.execute(status -> { + // 修改申请状态 + StoreApply data = new StoreApply(); + data.setStatus(StoreApplyStatus.CANCEL.getStatus()); + StoreApplyQuery query = new StoreApplyQuery(); + query.setId(id); + query.setStatus(StoreApplyStatus.WAIT_AUDIT.getStatus()); + int update = this.updateByQuery(data, query); + ServiceUtil.assertion(update != 1, "当前申请数据发生变化,请刷新后重试"); + + // 修改店铺状态 + Store storeData = new Store(); + storeData.setStatus(StoreStatus.NORMAL.getStatus()); + StoreQuery storeQuery = new StoreQuery(); + storeQuery.setStoreId(apply.getStoreId()); + int storeUpdate = storeService.updateByQuery(storeData, storeQuery); + ServiceUtil.assertion(storeUpdate != 1, "店铺状态修改失败,请刷新后重试"); + + return update; + }); + + return result == null ? 0 : result; + } + } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/impl/StoreApplyValidatorImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/impl/StoreApplyValidatorImpl.java new file mode 100644 index 00000000..df2132e6 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/storeApply/service/impl/StoreApplyValidatorImpl.java @@ -0,0 +1,22 @@ +package com.ruoyi.ss.storeApply.service.impl; + +import com.ruoyi.ss.storeApply.domain.StoreApplyVO; +import com.ruoyi.ss.storeApply.service.StoreApplyValidator; +import org.springframework.stereotype.Service; + +/** + * @author wjh + * 2024/8/5 + */ +@Service +public class StoreApplyValidatorImpl implements StoreApplyValidator { + + + /** + * 申请是否属于用户 + */ + @Override + public boolean isBelong(StoreApplyVO apply, Long userId) { + return apply != null && apply.getUserId() != null && apply.getUserId().equals(userId); + } +} diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppStoreController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppStoreController.java index 3267e205..ff1052db 100644 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppStoreController.java +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppStoreController.java @@ -123,6 +123,7 @@ public class AppStoreController extends BaseController { @Anonymous public AjaxResult listNearBy(@Validated(ValidGroup.Query.class) StoreQuery query) { query.setShow(true); + query.setEnabled(true); List list = storeService.listNearBy(query); storeAssembler.assembleDeviceCount(list); return success(list); diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/mch/MchStoreApplyController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/mch/MchStoreApplyController.java new file mode 100644 index 00000000..371a62c2 --- /dev/null +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/mch/MchStoreApplyController.java @@ -0,0 +1,60 @@ +package com.ruoyi.web.controller.mch; + +import com.fasterxml.jackson.annotation.JsonView; +import com.github.pagehelper.PageHelper; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.JsonViewProfile; +import com.ruoyi.ss.store.service.StoreValidator; +import com.ruoyi.ss.storeApply.domain.StoreApplyQuery; +import com.ruoyi.ss.storeApply.domain.StoreApplyVO; +import com.ruoyi.ss.storeApply.service.StoreApplyService; +import com.ruoyi.ss.storeApply.service.StoreApplyValidator; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Collections; + +/** + * @author wjh + * 2024/8/5 + */ +@RestController +@RequestMapping("/mch/storeApply") +public class MchStoreApplyController extends BaseController { + + @Autowired + private StoreApplyService storeApplyService; + + @Autowired + private StoreValidator storeValidator; + + @Autowired + private StoreApplyValidator storeApplyValidator; + + @ApiOperation("查询店铺最后一条申请信息") + @JsonView(JsonViewProfile.AppMch.class) + @GetMapping("/getLastByStore/{storeId}") + public AjaxResult getLastByStore(@PathVariable Long storeId) { + if (!storeValidator.isStoreBelongUser(Collections.singletonList(storeId), getUserId())) { + return error("这不是您的店铺"); + } + PageHelper.orderBy(" create_time desc "); + StoreApplyQuery query = new StoreApplyQuery(); + query.setStoreId(storeId); + return success(storeApplyService.selectOne(query)); + } + + @ApiOperation("取消申请") + @PutMapping("/{id}/cancel") + public AjaxResult cancel(@PathVariable @ApiParam("申请ID") Long id) { + StoreApplyVO apply = storeApplyService.selectStoreApplyById(id); + if (!storeApplyValidator.isBelong(apply, getUserId())) { + return error("这不是您的申请,无权取消"); + } + return toAjax(storeApplyService.cancel(id)); + } + +} diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/StoreApplyController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/StoreApplyController.java index 10595c5b..dd55192e 100644 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/StoreApplyController.java +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/StoreApplyController.java @@ -2,8 +2,13 @@ package com.ruoyi.web.controller.ss; import java.util.List; import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; + +import com.ruoyi.ss.storeApply.domain.dto.StoreApplyApprovalDTO; +import com.ruoyi.ss.storeApply.service.StoreApplyConverter; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -36,6 +41,9 @@ public class StoreApplyController extends BaseController @Autowired private StoreApplyService storeApplyService; + @Autowired + private StoreApplyConverter storeApplyConverter; + /** * 查询店铺审核列表 */ @@ -104,4 +112,16 @@ public class StoreApplyController extends BaseController { return toAjax(storeApplyService.deleteStoreApplyByIds(ids)); } + + /** + * 审核店铺 + */ + @PreAuthorize("@ss.hasPermi('ss:storeApply:approval')") + @Log(title = "店铺审核", businessType = BusinessType.OTHER) + @PutMapping("/approval") + public AjaxResult approval(@RequestBody @Validated StoreApplyApprovalDTO dto) { + return toAjax(storeApplyService.approval(storeApplyConverter.toBO(dto))); + } + + } diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/StoreController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/StoreController.java index 824055eb..2a866ecb 100644 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/StoreController.java +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/StoreController.java @@ -59,6 +59,8 @@ public class StoreController extends BaseController { startPage(); List list = storeService.selectSmStoreList(store); + storeAssembler.assembleDeviceCount(list); + storeAssembler.assembleRevenue(list); return getDataTable(list); }