激活码相关接口
This commit is contained in:
@@ -0,0 +1,56 @@
|
|||||||
|
package com.czg.controller;
|
||||||
|
|
||||||
|
import com.czg.annotation.SaAdminCheckPermission;
|
||||||
|
import com.czg.annotation.SaAdminCheckRole;
|
||||||
|
import com.czg.resp.CzgResult;
|
||||||
|
import com.czg.service.account.dto.PageDTO;
|
||||||
|
import com.czg.service.account.dto.register.MerchantRegisterDTO;
|
||||||
|
import com.czg.service.account.entity.MerchantRegister;
|
||||||
|
import com.czg.service.account.service.MerchantRegisterService;
|
||||||
|
import com.mybatisflex.core.paginate.Page;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 激活码管理
|
||||||
|
* @author Administrator
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/merchantRegister")
|
||||||
|
public class MerchantRegisterController {
|
||||||
|
@Resource
|
||||||
|
private MerchantRegisterService merchantRegisterService;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 激活码列表
|
||||||
|
*
|
||||||
|
* @param pageDTO 分页参数
|
||||||
|
* @param state 状态 0未激活 1已激活
|
||||||
|
* @param startTime 开始时间
|
||||||
|
* @param endTime 结束时间
|
||||||
|
* @return 激活码列表
|
||||||
|
*/
|
||||||
|
@SaAdminCheckRole("管理员")
|
||||||
|
@SaAdminCheckPermission("merchantRegister:add")
|
||||||
|
@GetMapping
|
||||||
|
public CzgResult<Page<MerchantRegister>> get(PageDTO pageDTO, Integer state, LocalDateTime startTime, LocalDateTime endTime) {
|
||||||
|
return CzgResult.success(merchantRegisterService.get(pageDTO, state, startTime, endTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成激活码
|
||||||
|
* 权限标识: merchantRegister:add
|
||||||
|
* @param merchantRegisterDTO 激活码信息
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
@SaAdminCheckRole("管理员")
|
||||||
|
@SaAdminCheckPermission("merchantRegister:add")
|
||||||
|
@PostMapping
|
||||||
|
public CzgResult<Boolean> add(@RequestBody @Validated MerchantRegisterDTO merchantRegisterDTO) {
|
||||||
|
return CzgResult.success(merchantRegisterService.add(merchantRegisterDTO));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.czg.exception;
|
package com.czg.exception;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.exception.NotLoginException;
|
||||||
import cn.dev33.satoken.exception.NotPermissionException;
|
import cn.dev33.satoken.exception.NotPermissionException;
|
||||||
import cn.hutool.core.exceptions.ValidateException;
|
import cn.hutool.core.exceptions.ValidateException;
|
||||||
import com.czg.resp.CzgRespCode;
|
import com.czg.resp.CzgRespCode;
|
||||||
@@ -31,6 +32,14 @@ public class CzgControllerAdvice {
|
|||||||
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR);
|
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ResponseBody
|
||||||
|
@ExceptionHandler(value = NotLoginException.class)
|
||||||
|
@ResponseStatus(HttpStatus.OK)
|
||||||
|
public CzgResult<Object> notLoginErrorHandler(NotLoginException ex) {
|
||||||
|
setErrorLog(ex);
|
||||||
|
return CzgResult.failure(CzgRespCode.NOT_LOGIN);
|
||||||
|
}
|
||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@ExceptionHandler(value = NotPermissionException.class)
|
@ExceptionHandler(value = NotPermissionException.class)
|
||||||
@ResponseStatus(HttpStatus.OK)
|
@ResponseStatus(HttpStatus.OK)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import lombok.Getter;
|
|||||||
public enum CzgRespCode {
|
public enum CzgRespCode {
|
||||||
SUCCESS(200, "操作成功"),
|
SUCCESS(200, "操作成功"),
|
||||||
FAILURE(500, "操作失败"),
|
FAILURE(500, "操作失败"),
|
||||||
|
NOT_LOGIN(501, "登录失效"),
|
||||||
SYSTEM_ERROR(555, "系统内部错误"),
|
SYSTEM_ERROR(555, "系统内部错误"),
|
||||||
RECORD_NOT_EXIST(601, "记录不存在"),
|
RECORD_NOT_EXIST(601, "记录不存在"),
|
||||||
RECORD_EXISTED(602, "记录已存在"),
|
RECORD_EXISTED(602, "记录已存在"),
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.czg.service.account.dto.register;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.Max;
|
||||||
|
import jakarta.validation.constraints.Min;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
public record MerchantRegisterDTO(
|
||||||
|
@NotNull(message = "激活时长不能为空")
|
||||||
|
@Min(1)
|
||||||
|
Integer periodMonth,
|
||||||
|
@NotNull(message = "数量不为空")
|
||||||
|
@Min(1)
|
||||||
|
@Max(10)
|
||||||
|
Integer num
|
||||||
|
) {
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@ public record ShopInfoAddDTO(
|
|||||||
String shopName,
|
String shopName,
|
||||||
@NotEmpty(message = "店铺类型不为空")
|
@NotEmpty(message = "店铺类型不为空")
|
||||||
String shopType,
|
String shopType,
|
||||||
String subTitle,
|
String chainName,
|
||||||
@NotEmpty(message = "店铺logo不为空")
|
@NotEmpty(message = "店铺logo不为空")
|
||||||
String logo,
|
String logo,
|
||||||
@NotEmpty(message = "门头照不为空")
|
@NotEmpty(message = "门头照不为空")
|
||||||
@@ -33,7 +33,6 @@ public record ShopInfoAddDTO(
|
|||||||
@NotNull(message = "角色id不为空")
|
@NotNull(message = "角色id不为空")
|
||||||
Long roleId,
|
Long roleId,
|
||||||
String address,
|
String address,
|
||||||
Integer status,
|
|
||||||
String phone
|
String phone
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
package com.czg.service.account.service;
|
package com.czg.service.account.service;
|
||||||
|
|
||||||
|
import com.czg.service.account.dto.PageDTO;
|
||||||
|
import com.czg.service.account.dto.register.MerchantRegisterDTO;
|
||||||
|
import com.mybatisflex.core.paginate.Page;
|
||||||
import com.mybatisflex.core.service.IService;
|
import com.mybatisflex.core.service.IService;
|
||||||
import com.czg.service.account.entity.MerchantRegister;
|
import com.czg.service.account.entity.MerchantRegister;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 激活码 服务层。
|
* 激活码 服务层。
|
||||||
*
|
*
|
||||||
@@ -11,4 +16,7 @@ import com.czg.service.account.entity.MerchantRegister;
|
|||||||
*/
|
*/
|
||||||
public interface MerchantRegisterService extends IService<MerchantRegister> {
|
public interface MerchantRegisterService extends IService<MerchantRegister> {
|
||||||
|
|
||||||
|
Page<MerchantRegister> get(PageDTO pageDTO, Integer state, LocalDateTime startTime, LocalDateTime endTime);
|
||||||
|
|
||||||
|
Boolean add(MerchantRegisterDTO merchantRegisterDTO);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,22 @@
|
|||||||
package com.czg.service.account.service.impl;
|
package com.czg.service.account.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import com.czg.service.account.dto.PageDTO;
|
||||||
|
import com.czg.service.account.dto.register.MerchantRegisterDTO;
|
||||||
|
import com.czg.service.account.entity.SysRole;
|
||||||
|
import com.mybatisflex.core.paginate.Page;
|
||||||
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
import com.czg.service.account.entity.MerchantRegister;
|
import com.czg.service.account.entity.MerchantRegister;
|
||||||
import com.czg.service.account.mapper.MerchantRegisterMapper;
|
import com.czg.service.account.mapper.MerchantRegisterMapper;
|
||||||
import com.czg.service.account.service.MerchantRegisterService;
|
import com.czg.service.account.service.MerchantRegisterService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import static com.mybatisflex.core.query.QueryMethods.column;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 激活码 服务层实现。
|
* 激活码 服务层实现。
|
||||||
*
|
*
|
||||||
@@ -15,4 +26,35 @@ import org.springframework.stereotype.Service;
|
|||||||
@Service
|
@Service
|
||||||
public class MerchantRegisterServiceImpl extends ServiceImpl<MerchantRegisterMapper, MerchantRegister> implements MerchantRegisterService{
|
public class MerchantRegisterServiceImpl extends ServiceImpl<MerchantRegisterMapper, MerchantRegister> implements MerchantRegisterService{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<MerchantRegister> get(PageDTO pageDTO, Integer state, LocalDateTime startTime, LocalDateTime endTime) {
|
||||||
|
QueryWrapper queryWrapper = new QueryWrapper();
|
||||||
|
|
||||||
|
if (state != null) {
|
||||||
|
queryWrapper.eq(MerchantRegister::getStatus, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startTime != null) {
|
||||||
|
queryWrapper.ge(SysRole::getCreateTime, startTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (endTime != null) {
|
||||||
|
queryWrapper.le(SysRole::getCreateTime, endTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
return page(new Page<>(pageDTO.page(), pageDTO.size()), queryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean add(MerchantRegisterDTO merchantRegisterDTO) {
|
||||||
|
ArrayList<MerchantRegister> registers = new ArrayList<>();
|
||||||
|
for (int i = 0; i < merchantRegisterDTO.num(); i++) {
|
||||||
|
MerchantRegister tbMerchantRegister = new MerchantRegister();
|
||||||
|
tbMerchantRegister.setRegisterCode(IdUtil.simpleUUID());
|
||||||
|
tbMerchantRegister.setStatus(0);
|
||||||
|
tbMerchantRegister.setPeriodMonth(merchantRegisterDTO.periodMonth());
|
||||||
|
registers.add(tbMerchantRegister);
|
||||||
|
}
|
||||||
|
return saveBatch(registers);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
|||||||
shopInfo.setId(sysUser.getId());
|
shopInfo.setId(sysUser.getId());
|
||||||
//设置激活码
|
//设置激活码
|
||||||
shopInfo.setStatus(1);
|
shopInfo.setStatus(1);
|
||||||
|
shopInfo.setProfiles("release");
|
||||||
shopInfo.setExpireTime(DateUtil.offsetMonth(DateUtil.date(), merchantRegister.getPeriodMonth()).toLocalDateTime());
|
shopInfo.setExpireTime(DateUtil.offsetMonth(DateUtil.date(), merchantRegister.getPeriodMonth()).toLocalDateTime());
|
||||||
return save(shopInfo);
|
return save(shopInfo);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
<!DOCTYPE mapper
|
<!DOCTYPE mapper
|
||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.czg.service.account.mapper.TbShopInfoMapper">
|
<mapper namespace="com.czg.service.account.mapper.ShopInfoMapper">
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -2,6 +2,6 @@
|
|||||||
<!DOCTYPE mapper
|
<!DOCTYPE mapper
|
||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.czg.service.account.mapper.TbShopUserMapper">
|
<mapper namespace="com.czg.service.account.mapper.ShopStaffMapper">
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -2,6 +2,6 @@
|
|||||||
<!DOCTYPE mapper
|
<!DOCTYPE mapper
|
||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.czg.service.account.mapper.TbShopStaffMapper">
|
<mapper namespace="com.czg.service.account.mapper.ShopUserMapper">
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user