feat:用户协议/隐私政策

master
ChenYan 2025-02-14 10:33:56 +08:00
parent b4ae47cf28
commit 367c359b5e
9 changed files with 214 additions and 1 deletions

View File

@ -25,6 +25,9 @@ import javax.validation.constraints.NotNull;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
/***
*
*/
@RestController @RestController
@RequestMapping("member") @RequestMapping("member")
@RequiredArgsConstructor @RequiredArgsConstructor

View File

@ -16,6 +16,9 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/***
*
*/
@RestController @RestController
@RequestMapping("memberLevel") @RequestMapping("memberLevel")
@RequiredArgsConstructor @RequiredArgsConstructor

View File

@ -7,7 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
/** /**
* @AuthorChenYan * @AuthorChenYan
* @ProjectMcWl * @ProjectMcWl
* @Packagecom.mcwl.common.config * @Packagecom.mcwl.common.config

View File

@ -0,0 +1,62 @@
package com.mcwl.web.controller.system;
import com.mcwl.common.core.controller.BaseController;
import com.mcwl.system.domain.Policy;
import com.mcwl.system.service.PolicyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* @AuthorChenYan
* @Projectmcwl-ai
* @Packagecom.mcwl.web.controller.system
* @FilenamePerController
* @Description TODO
* @Date2025/2/14 10:11
*/
@Api(tags = "隐私政策/用户协议")
@RestController
@RequestMapping("Policy")
@RequiredArgsConstructor
public class PerController extends BaseController {
@Autowired
private PolicyService policyService;
/**
*
*
* @param type
* @return
*/
@ApiOperation(value = "获取指定类型的政策内容")
@GetMapping("/{type}")
public ResponseEntity<?> getPolicy(@PathVariable("type") String type) {
Policy policy = policyService.getPolicyByType(type);
if (policy == null) {
return new ResponseEntity<>("Policy not found", HttpStatus.NOT_FOUND);
}
return new ResponseEntity<>(policy.getContent(), HttpStatus.OK);
}
/**
*
*
* @param type
* @param content
* @return
*/
@ApiOperation(value = "更新指定类型的政策内容")
@PutMapping("/{type}")
public ResponseEntity<?> updatePolicy(@PathVariable("type") String type, @RequestBody String content) {
try {
policyService.updatePolicyContent(type, content);
return new ResponseEntity<>("Policy updated successfully", HttpStatus.OK);
} catch (RuntimeException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
}
}
}

View File

@ -0,0 +1,48 @@
package com.mcwl.system.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.mcwl.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @AuthorChenYan
* @Projectmcwl-ai
* @Packagecom.mcwl.system.domain
* @FilenamePer
* @Description /
* @Date2025/2/14 10:05
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
@ApiModel(description = "用户协议/隐私政策表")
@TableName("mcwl_policies")
public class Policy extends BaseEntity {
@TableId
/**
*
*/
@ApiModelProperty(value = "id")
private Long id;
/**
*
*/
@ApiModelProperty(value = "标题")
private String title;
/**
*
*/
@ApiModelProperty(value = "内容")
private String content;
/**
* /
*/
@ApiModelProperty(value = "类型 用户协议/隐私政策")
private Integer type;
}

View File

@ -0,0 +1,24 @@
package com.mcwl.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mcwl.system.domain.Policy;
import org.apache.ibatis.annotations.Mapper;
/**
* @AuthorChenYan
* @Projectmcwl-ai
* @Packagecom.mcwl.system.mapper
* @FilenamePolicyMapper
* @Description TODO
* @Date2025/2/14 10:21
*/
@Mapper
public interface PolicyMapper extends BaseMapper<Policy> {
/**
*
* @param type
* @return
*/
Policy findByType(String type);
}

View File

@ -0,0 +1,24 @@
package com.mcwl.system.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.mcwl.system.domain.Policy;
import static com.qcloud.cos.exception.CosServiceException.ErrorType.Service;
/**
* @AuthorChenYan
* @Projectmcwl-ai
* @Packagecom.mcwl.system.service
* @FilenamePolicyService
* @Description TODO
* @Date2025/2/14 10:13
*/
public interface PolicyService extends IService<Policy> {
Policy getPolicyByType(String type);
void updatePolicyContent(String type, String content);
}

View File

@ -0,0 +1,36 @@
package com.mcwl.system.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mcwl.system.domain.Policy;
import com.mcwl.system.mapper.PolicyMapper;
import com.mcwl.system.service.PolicyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @AuthorChenYan
* @Projectmcwl-ai
* @Packagecom.mcwl.system.service.impl
* @FilenamePolicyServiceImpl
* @Description TODO
* @Date2025/2/14 10:13
*/
@Service
public class PolicyServiceImpl extends ServiceImpl<PolicyMapper, Policy> implements PolicyService {
@Autowired
private PolicyMapper policyMapper;
public Policy getPolicyByType(String type) {
return policyMapper.findByType(type);
}
public void updatePolicyContent(String type, String content) {
Policy policy = policyMapper.findByType(type);
if (policy != null) {
policy.setContent(content);
policyMapper.insert(policy);
} else {
throw new RuntimeException("Policy not found for type: " + type);
}
}
}

View File

@ -0,0 +1,13 @@
<?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.mcwl.system.mapper.PolicyMapper">
<!-- 根据类型查找策略 -->
<select id="findByType" parameterType="String" resultType="com.mcwl.system.domain.Policy">
SELECT id, title, content, type, created_at, updated_at
FROM policies
WHERE type = #{type}
</select>
</mapper>