This commit is contained in:
张良(004796)
2024-01-23 12:36:36 +08:00
parent 424a0447ab
commit c0ef9da677
11 changed files with 285 additions and 55 deletions

View File

@@ -0,0 +1,57 @@
package com.ruoyi.cai.controller.app;
import com.ruoyi.cai.domain.Adolescent;
import com.ruoyi.cai.dto.app.query.user.AdolescentSetting;
import com.ruoyi.cai.dto.app.query.user.AdolescentSwitch;
import com.ruoyi.cai.dto.app.vo.user.AdolescentVo;
import com.ruoyi.cai.service.AdolescentService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.helper.LoginHelper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/adolescent")
@Tag(name = "青少年模式接口")
public class AdolescentAppController {
@Autowired
private AdolescentService adolescentService;
@PostMapping("/set")
@Operation(summary = "设置青少年模式")
@Log(title = "设置青少年模式", businessType = BusinessType.OTHER, isSaveDb = false)
public R<Void> set(@RequestBody AdolescentSetting setting){
adolescentService.setAdolescent(setting);
return R.ok();
}
@GetMapping("/get")
@Operation(summary = "获取用户青少年模式状态")
@Log(title = "获取用户青少年模式状态", businessType = BusinessType.OTHER, isSaveDb = false)
public R<AdolescentVo> get(){
Long userId = LoginHelper.getUserId();
Adolescent adolescent = adolescentService.getByUserId(userId);
AdolescentVo vo = new AdolescentVo();
if(adolescent != null){
vo.setIsSetAdolescent(1);
vo.setIsSetPwd(1);
vo.setIsOpen(adolescent.getOpen());
}
return R.ok(vo);
}
@GetMapping("/switch")
@Operation(summary = "青少年模式开关")
@Log(title = "青少年模式开关", businessType = BusinessType.OTHER, isSaveDb = false)
public R<Void> switchAdolescent(@RequestBody AdolescentSwitch adolescentSwitch){
adolescentService.switchAdolescent(adolescentSwitch);
return R.ok();
}
}

View File

@@ -1,53 +0,0 @@
package com.ruoyi.cai.controller.app;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.cai.domain.AgreementSetting;
import com.ruoyi.cai.dto.app.vo.AgreementDTO;
import com.ruoyi.cai.service.AgreementSettingService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* 协议设置
*
* @author 77
* @date 2024-01-14
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/agreementSetting")
@Tag(name = "协议相关接口")
public class AgreementSettingAppController extends BaseController {
private final AgreementSettingService agreementSettingService;
@GetMapping("/userAgreement")
@Operation(summary = "获取用户协议")
@Log(title = "获取用户协议", businessType = BusinessType.OTHER, isSaveDb = false)
public R<AgreementDTO> userAgreement() {
String userAgreement = agreementSettingService.getAgreementSetting().getUserAgreement();
return R.ok(new AgreementDTO(userAgreement));
}
@GetMapping("/anchorJoinAgreement")
@Operation(summary = "用户主播入驻协议")
@Log(title = "用户主播入驻协议", businessType = BusinessType.OTHER, isSaveDb = false)
public R<AgreementDTO> anchorJoinAgreement() {
String anchorJoinAgreement = agreementSettingService.getAgreementSetting().getAnchorJoinAgreement();
return R.ok(new AgreementDTO(anchorJoinAgreement));
}
}

View File

@@ -1,7 +1,11 @@
package com.ruoyi.cai.controller.app;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.cai.domain.*;
import com.ruoyi.cai.domain.Gift;
import com.ruoyi.cai.domain.Goods;
import com.ruoyi.cai.domain.ReportCate;
import com.ruoyi.cai.domain.WithdrawExchange;
import com.ruoyi.cai.dto.app.vo.AgreementDTO;
import com.ruoyi.cai.dto.app.vo.GiftVo;
import com.ruoyi.cai.service.*;
import com.ruoyi.common.annotation.Log;
@@ -16,7 +20,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/api/setting")
@@ -31,6 +34,8 @@ public class SettingAppController {
private ReportCateService reportCateService;
@Autowired
private GiftService giftService;
@Autowired
private AgreementSettingService agreementSettingService;
@GetMapping("/goods")
@Operation(summary = "充值配置")
@@ -68,4 +73,20 @@ public class SettingAppController {
return R.ok(BeanConvertUtil.convertListTo(res, GiftVo::new));
}
@GetMapping("/agreement/user")
@Operation(summary = "获取用户协议")
@Log(title = "获取用户协议", businessType = BusinessType.OTHER, isSaveDb = false)
public R<AgreementDTO> userAgreement() {
String userAgreement = agreementSettingService.getAgreementSetting().getUserAgreement();
return R.ok(new AgreementDTO(userAgreement));
}
@GetMapping("/agreement/user")
@Operation(summary = "用户主播入驻协议")
@Log(title = "用户主播入驻协议", businessType = BusinessType.OTHER, isSaveDb = false)
public R<AgreementDTO> anchorJoinAgreement() {
String anchorJoinAgreement = agreementSettingService.getAgreementSetting().getAnchorJoinAgreement();
return R.ok(new AgreementDTO(anchorJoinAgreement));
}
}

View File

@@ -0,0 +1,46 @@
package com.ruoyi.cai.domain;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;
import java.math.BigDecimal;
import com.ruoyi.common.core.domain.BaseEntity;
/**
* 青少年模式对象 cai_adolescent
*
* @author 77
* @date 2024-01-23
*/
@Data
@TableName("cai_adolescent")
public class Adolescent implements Serializable {
private static final long serialVersionUID=1L;
/**
* ID
*/
private Long id;
/**
* 用户user_id
*/
@TableId(value = "user_id")
private Long userId;
/**
* 青少年模式密码
*/
private String password;
/**
* 是否开启0未开启1已开启
*/
private Integer open;
private LocalDateTime createTime;
private LocalDateTime updateTime;
}

View File

@@ -0,0 +1,8 @@
package com.ruoyi.cai.dto.app.query.user;
import lombok.Data;
@Data
public class AdolescentSetting {
private String password;
}

View File

@@ -0,0 +1,9 @@
package com.ruoyi.cai.dto.app.query.user;
import lombok.Data;
@Data
public class AdolescentSwitch {
private Integer isOpen;
private String password;
}

View File

@@ -0,0 +1,15 @@
package com.ruoyi.cai.dto.app.vo.user;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class AdolescentVo {
@Schema(description = "是否青少年模式")
private Integer isSetAdolescent = 0;
@Schema(description = "是否设置密码")
private Integer isSetPwd = 0;
@Schema(description = "是否开启")
private Integer isOpen = 0;
}

View File

@@ -0,0 +1,14 @@
package com.ruoyi.cai.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.cai.domain.Adolescent;
/**
* 青少年模式Mapper接口
*
* @author 77
* @date 2024-01-23
*/
public interface AdolescentMapper extends BaseMapper<Adolescent> {
}

View File

@@ -0,0 +1,21 @@
package com.ruoyi.cai.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.cai.domain.Adolescent;
import com.ruoyi.cai.dto.app.query.user.AdolescentSetting;
import com.ruoyi.cai.dto.app.query.user.AdolescentSwitch;
/**
* 青少年模式Service接口
*
* @author 77
* @date 2024-01-23
*/
public interface AdolescentService extends IService<Adolescent> {
void setAdolescent(AdolescentSetting setting);
Adolescent getByUserId(Long userId);
void switchAdolescent(AdolescentSwitch adolescentSwitch);
}

View File

@@ -0,0 +1,75 @@
package com.ruoyi.cai.service.impl;
import cn.dev33.satoken.secure.BCrypt;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.cai.domain.Adolescent;
import com.ruoyi.cai.dto.app.query.user.AdolescentSetting;
import com.ruoyi.cai.dto.app.query.user.AdolescentSwitch;
import com.ruoyi.cai.mapper.AdolescentMapper;
import com.ruoyi.cai.service.AdolescentService;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.helper.LoginHelper;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.concurrent.locks.ReentrantLock;
/**
* 青少年模式Service业务层处理
*
* @author 77
* @date 2024-01-23
*/
@RequiredArgsConstructor
@Service
public class AdolescentServiceImpl extends ServiceImpl<AdolescentMapper,Adolescent> implements AdolescentService {
@Override
public void setAdolescent(AdolescentSetting setting) {
if(StringUtils.isEmpty(setting.getPassword())){
throw new ServiceException("密码不能为空");
}
Long userId = LoginHelper.getUserId();
ReentrantLock lock = new ReentrantLock();
try {
lock.lock();
Adolescent adolescent = this.getByUserId(userId);
if(adolescent == null){
adolescent = new Adolescent();
}
adolescent.setOpen(1);
adolescent.setPassword(BCrypt.hashpw(setting.getPassword()));
this.saveOrUpdate(adolescent);
}finally {
lock.unlock();
}
}
@Override
public Adolescent getByUserId(Long userId){
return this.getOne(Wrappers.lambdaQuery(Adolescent.class).eq(Adolescent::getUserId,userId).last("limit 1"));
}
@Override
public void switchAdolescent(AdolescentSwitch adolescentSwitch) {
if(adolescentSwitch.getIsOpen() == null) {
throw new ServiceException("参数不正确");
}else if(adolescentSwitch.getIsOpen() != 0 && adolescentSwitch.getIsOpen() != 1){
throw new ServiceException("参数不正确");
}
Adolescent adolescent = this.getByUserId(LoginHelper.getUserId());
String hashpw = BCrypt.hashpw(adolescentSwitch.getPassword());
if(adolescent == null || !adolescent.getPassword().equals(hashpw)){
throw new ServiceException("密码错误");
}
if(adolescentSwitch.getIsOpen() == 0){
this.removeById(adolescent);
}else {
adolescent.setOpen(1);
this.updateById(adolescent);
}
}
}

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.cai.mapper.AdolescentMapper">
<resultMap type="com.ruoyi.cai.domain.Adolescent" id="AdolescentResult">
<result property="id" column="id"/>
<result property="userId" column="user_id"/>
<result property="password" column="password"/>
<result property="open" column="open"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
</resultMap>
</mapper>