Merge branch 'feature/comment' of https://gitea.qinmian.online/CY/mcwl-ai into preview

feature/comment
ChenYan 2025-01-06 16:05:11 +08:00
commit a045ab58b6
22 changed files with 1111 additions and 20 deletions

View File

@ -46,7 +46,12 @@
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- 评论区模块-->
<dependency>
<groupId>com.mcwl</groupId>
<artifactId>mcwl-comment</artifactId>
<version>3.8.8</version>
</dependency>
<!-- 核心模块-->
<dependency>
<groupId>com.mcwl</groupId>

View File

@ -0,0 +1,77 @@
package com.mcwl.web.controller.comment;
import com.mcwl.comment.domain.ProductCommentConditionEntity;
import com.mcwl.comment.domain.ProductCommentEntity;
import com.mcwl.comment.service.impl.CommentServiceImpl;
import com.mcwl.common.utils.ResponsePageEntity;
import com.mcwl.resource.domain.MallProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.web.controller.comment
* @FilenameCommentController
* @Description TODO
* @Date2025/1/4 18:56
*/
@RestController
@RequestMapping("/comment")
public class CommentController {
@Autowired
private CommentServiceImpl commentService;
/**
* id
*
* @param id ID
* @return
*/
@GetMapping("/findById")
public MallProduct findById(Long id) {
return commentService.findById(id);
}
/**
*
*
* @param productCommentEntity
* @return
*/
@PostMapping("/insert")
public int insert(@RequestBody ProductCommentEntity productCommentEntity) {
return commentService.insert(productCommentEntity);
}
/**
*
*
* @param productCommentEntity
* @return
*/
@PostMapping("/update")
public int update(@RequestBody ProductCommentEntity productCommentEntity) {
return commentService.update(productCommentEntity);
}
/**
*
*
* @param ids ID
* @return
*/
@PostMapping("/deleteByIds")
public int deleteByIds(@RequestBody @NotNull List<Long> ids) {
return commentService.deleteByIds(ids);
}
}

View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mcwl</groupId>
<artifactId>mcwl</artifactId>
<version>3.8.8</version>
</parent>
<artifactId>mcwl-comment</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<description>
评论模块
</description>
<dependencies>
<!-- 通用工具-->
<dependency>
<groupId>com.mcwl</groupId>
<artifactId>mcwl-common</artifactId>
</dependency>
<!-- &lt;!&ndash; 资源中心&ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>com.mcwl</groupId>-->
<!-- <artifactId>mcwl-resource</artifactId>-->
<!-- <version>3.8.8</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<dependency>
<groupId>com.mcwl</groupId>
<artifactId>mcwl-resource</artifactId>
<version>3.8.8</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,4 +1,4 @@
package com.mcwl.resource.domain;
package com.mcwl.comment.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
@ -7,41 +7,37 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.common.domain.resource
* @FilenameMallProductComment
* @Description TODO
* @Date2024/12/30 17:22
* @Packagecom.mcwl.comment.domain
* @FilenameComment
* @Description
* @Date2025/1/4 18:47
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
@TableName("mall_product_comment")
public class MallProductComment extends BaseEntity {
private static final long serialVersionUID = 1L;
public class Comment extends BaseEntity {
/**
* ID
*/
@TableId
private Long Id;
private Long id;
/**
* ID
*/
private Integer parentId;
private String parentId;
/**
* ID
*/
private Integer productId;
private String productId;
/**
* ID
*/
private Integer userId;
private String userId;
/**
*
*/
@ -49,13 +45,9 @@ public class MallProductComment extends BaseEntity {
/**
*
*/
private Integer rating;
private String rating;
/**
* 0 2
*/
private String delFlag;
}

View File

@ -0,0 +1,56 @@
package com.mcwl.comment.domain;
import lombok.Data;
import java.util.List;
/**
*
*/
@Data
public class ProductCommentConditionEntity extends RequestConditionEntity {
/**
* ID
*/
private List<Long> idList;
/**
* ID
*/
private Long id;
/**
* ID
*/
private Long parentId;
/**
* ID
*/
private Long productId;
/**
* ID
*/
private List<Long> productIdList;
/**
* ID
*/
private Long userId;
/**
*
*/
private String content;
/**
*
*/
private Integer rating;
/**
* 0 2
*/
private String delFlag;
// /**
// * 评论类型
// */
// private Integer type;
}

View File

@ -0,0 +1,50 @@
package com.mcwl.comment.domain;
import com.mcwl.common.core.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.comment.domain
* @FilenameProductCommentEntity
* @Description
* @Date2025/1/6 13:21
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
public class ProductCommentEntity extends BaseEntity {
/**
* ID
*/
private Long parentId;
/**
* ID
*/
private Long productId;
/**
* ID
*/
private Long userId;
/**
*
*/
private String content;
/**
*
*/
private Integer rating;
// /**
// * 评论类型
// */
// private Integer type;
}

View File

@ -0,0 +1,41 @@
package com.mcwl.comment.domain;
import com.mcwl.common.utils.RequestPageEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
*
*/
@Data
public class RequestConditionEntity extends RequestPageEntity {
/**
*
*/
@ApiModelProperty("创建日期范围")
private List<String> betweenTime;
/**
*
*/
private String createBeginTime;
/**
*
*/
private String createEndTime;
/**
* excel
*/
private List<String> customizeColumnNameList;
/**
*
*/
private String blurry;
}

View File

@ -0,0 +1,72 @@
package com.mcwl.comment.domain;
import cn.hutool.core.collection.CollectionUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
/**
*
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
public class RequestPageEntity implements Serializable {
private static final int DEFAULT_PAGE_SIZE = 10;
/**
*
*/
private Integer pageNo = 1;
/**
* 10
*/
private Integer pageSize = DEFAULT_PAGE_SIZE;
/**
*
*/
private List<String> sortField;
/**
*
*
* @return
*/
public Integer getPageBegin() {
if (Objects.isNull(this.pageNo) || this.pageNo <= 0) {
this.pageNo = 1;
}
if (Objects.isNull(this.pageSize)) {
this.pageSize = DEFAULT_PAGE_SIZE;
}
return (this.pageNo - 1) * this.pageSize;
}
/**
*
*
* @return
*/
public String getSortString() {
List<String> sortField = this.getSortField();
if (CollectionUtil.isEmpty(sortField)) {
return null;
}
StringBuilder sortBuilder = new StringBuilder();
for (String field : sortField) {
String[] values = field.split(",");
sortBuilder.append(String.format("%s %s", values[0], values[1])).append(",");
}
return sortBuilder.deleteCharAt(sortBuilder.length() - 1).toString();
}
}

View File

@ -0,0 +1,31 @@
package com.mcwl.comment.mapper;
import com.mcwl.comment.domain.ProductCommentConditionEntity;
import com.mcwl.comment.domain.ProductCommentEntity;
import com.mcwl.common.web.BaseMapper;
import com.mcwl.resource.domain.MallProduct;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.comment.mapper
* @FilenameCommentMapper
* @Description TODO
* @Date2025/1/4 19:04
*/
public interface CommentMapper extends BaseMapper<ProductCommentEntity, ProductCommentConditionEntity> {
MallProduct findById(@Param("id") Long id);
int insert(ProductCommentEntity productCommentEntity);
int upda(ProductCommentEntity productCommentEntity);
List<ProductCommentEntity> findByIds(List<Long> ids);
int deleteByIds(List<Long> ids, ProductCommentEntity productCommentEntity);
}

View File

@ -0,0 +1,88 @@
package com.mcwl.comment.service.impl;
import com.mcwl.comment.domain.ProductCommentConditionEntity;
import com.mcwl.comment.domain.ProductCommentEntity;
import com.mcwl.comment.mapper.CommentMapper;
import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.common.utils.AssertUtil;
import com.mcwl.common.utils.FillUserUtil;
import com.mcwl.common.utils.ResponsePageEntity;
import com.mcwl.common.utils.SecurityUtils;
import com.mcwl.common.utils.bean.BaseService;
import com.mcwl.common.web.BaseMapper;
import com.mcwl.resource.domain.MallProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
import static com.mcwl.common.utils.SecurityUtils.getUsername;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.comment.service.impl
* @FilenameCommentServiceImpl
* @Description TODO
* @Date2025/1/4 19:04
*/
@Service
public class CommentServiceImpl extends BaseService<ProductCommentEntity, ProductCommentConditionEntity> {
@Autowired
private CommentMapper commentMapper;
public MallProduct findById(Long id) {
return commentMapper.findById(id);
}
public int insert(ProductCommentEntity productCommentEntity) {
// 获取当前用户
Long userId = SecurityUtils.getUserId();
productCommentEntity.setUserId(userId);
productCommentEntity.setCreateBy(getUsername());
checkParam(productCommentEntity);
return commentMapper.insert(productCommentEntity);
}
public int update(ProductCommentEntity productCommentEntity) {
// 获取当前用户
Long userId = SecurityUtils.getUserId();
productCommentEntity.setUserId(userId);
productCommentEntity.setUpdateBy(getUsername());
checkParam(productCommentEntity);
return commentMapper.upda(productCommentEntity);
}
public int deleteByIds(List<Long> ids) {
List<ProductCommentEntity> entities = commentMapper.findByIds(ids);
AssertUtil.notEmpty(entities, "商品评论已被删除");
ProductCommentEntity entity = new ProductCommentEntity();
FillUserUtil.fillUpdateUserInfo(entity);
return commentMapper.deleteByIds(ids, entity);
}
private void checkParam(ProductCommentEntity productCommentEntity) {
if (Objects.nonNull(productCommentEntity.getParentId()) && productCommentEntity.getParentId() > 0) {
MallProduct productEntity = commentMapper.findById(productCommentEntity.getParentId());
AssertUtil.notNull(productEntity, "该父评论在系统中不存在");
}
MallProduct userEntity = commentMapper.findById(productCommentEntity.getUserId());
AssertUtil.notNull(userEntity, "该用户在系统中不存在");
MallProduct productEntity = commentMapper.findById(productCommentEntity.getProductId());
AssertUtil.notNull(productEntity, "该商品在系统中不存在");
}
@Override
protected BaseMapper getBaseMapper() {
return commentMapper;
}
}

View File

@ -0,0 +1,95 @@
<?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.comment.mapper.CommentMapper">
<insert id="insert">
insert into mall_product_comment(id, parent_id, product_id, user_id, content, rating, create_by, create_time,
update_by, update_time, del_flag, remark)
values (#{id}, #{parentId}, #{productId}, #{userId}, #{content}, #{rating}, #{createBy}, #{createTime},
#{updateBy}, #{updateTime}, #{remark}, #{delFlag})
</insert>
<update id="upda">
update mall_product_comment
<set>
<if test="parentId != null">
parent_id = #{parentId},
</if>
<if test="productId != null">
product_id = #{productId},
</if>
<if test="userId != null">
user_id = #{userId},
</if>
<if test="content != null">
content = #{content},
</if>
<if test="rating !=null">
rating = #{rating},
</if>
<if test="createBy != null">
create_by = #{createBy},
</if>
<if test="createTime != null">
create_time = #{createTime},
</if>
<if test="updateBy != null">
update_by = #{updateBy},
</if>
<if test="updateTime != null">
update_time = #{updateTime},
</if>
<if test="remark != null">
remark = #{remark},
</if>
<if test="delFlag != null">
del_flag = #{delFlag},
</if>
</set>
where id = #{id}
</update>
<delete id="deleteByIds">
delete
from mall_product_comment
where id in
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="findById" resultType="com.mcwl.resource.domain.MallProduct">
select productId,
userId,
productName,
detail,
model,
amount,
status,
name,
url,
zipUrl,
delFlag
from mall_product
where id = #{id}
</select>
<select id="findByIds" resultType="com.mcwl.comment.domain.ProductCommentEntity">
select
id,
parent_id,
product_id,
user_id,
content,
rating,
create_by,
create_time,
update_by,
update_time,
remark,
del_flag
from mall_product_comment
where id in
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper>

View File

@ -0,0 +1,34 @@
package com.mcwl.common.constant;
/**
*
*/
public abstract class NumberConstant {
private NumberConstant() {
}
public static int NUMBER_1 = 1;
public static int NUMBER_2 = 2;
public static int NUMBER_3 = 3;
public static int NUMBER_4 = 4;
public static int NUMBER_5 = 5;
public static int NUMBER_6 = 6;
public static int NUMBER_7 = 7;
public static int NUMBER_8 = 8;
public static int NUMBER_9 = 9;
public static int NUMBER_10 = 10;
public static int NUMBER_20 = 20;
public static int NUMBER_30 = 30;
public static int NUMBER_40 = 40;
public static int NUMBER_50 = 50;
public static int NUMBER_60 = 60;
public static int NUMBER_70 = 70;
public static int NUMBER_80 = 80;
public static int NUMBER_90 = 90;
public static int NUMBER_100 = 100;
public static int NUMBER_200 = 200;
public static int NUMBER_500 = 500;
public static int NUMBER_1000 = 1000;
public static int NUMBER_10000 = 10000;
}

View File

@ -0,0 +1,41 @@
package com.mcwl.common.domain;
import com.mcwl.common.utils.RequestPageEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
*
*/
@Data
public class RequestConditionEntity extends RequestPageEntity {
/**
*
*/
@ApiModelProperty("创建日期范围")
private List<String> betweenTime;
/**
*
*/
private String createBeginTime;
/**
*
*/
private String createEndTime;
/**
* excel
*/
private List<String> customizeColumnNameList;
/**
*
*/
private String blurry;
}

View File

@ -0,0 +1,35 @@
package com.mcwl.common.exception;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.http.HttpStatus;
/**
*
*/
@
AllArgsConstructor
@Data
public class BusinessException extends RuntimeException {
public static final long serialVersionUID = -6735897190745766939L;
/**
*
*/
private int code;
/**
*
*/
private String message;
public BusinessException() {
super();
}
public BusinessException(String message) {
this.code = HttpStatus.INTERNAL_SERVER_ERROR.value();
this.message = message;
}
}

View File

@ -0,0 +1,48 @@
package com.mcwl.common.filter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import java.util.List;
/**
*/
@NoArgsConstructor
@AllArgsConstructor
@Data
public class JwtUserEntity implements UserDetails {
private Long id;
private String username;
@JsonIgnore
private String password;
private List<SimpleGrantedAuthority> authorities;
/**
*
*/
private List<String> roles;
@Override
public boolean isAccountNonExpired() {
return true;
}
@Override
public boolean isAccountNonLocked() {
return true;
}
@Override
public boolean isCredentialsNonExpired() {
return true;
}
@Override
public boolean isEnabled() {
return true;
}
}

View File

@ -0,0 +1,72 @@
package com.mcwl.common.utils;
import com.mcwl.common.exception.BusinessException;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.Collection;
/**
*
*
* @author java
* @date 2024/1/9 4:00
*/
public abstract class AssertUtil {
public static final int ASSERT_ERROR_CODE = 1;
private AssertUtil() {
}
public static void state(boolean expression, String message) {
if (!expression) {
throw new BusinessException(ASSERT_ERROR_CODE, message);
}
}
public static void isTrue(boolean expression, String message) {
if (!expression) {
throw new BusinessException(ASSERT_ERROR_CODE, message);
}
}
public static void isNull(@Nullable Object object, String message) {
if (object != null) {
throw new BusinessException(ASSERT_ERROR_CODE, message);
}
}
public static void notNull(@Nullable Object object, String message) {
if (object == null) {
throw new BusinessException(ASSERT_ERROR_CODE, message);
}
}
public static void hasLength(@Nullable String text, String message) {
if (!StringUtils.hasLength(text)) {
throw new BusinessException(ASSERT_ERROR_CODE, message);
}
}
public static void notEmpty(@Nullable Collection<?> collection, String message) {
if (CollectionUtils.isEmpty(collection)) {
throw new BusinessException(ASSERT_ERROR_CODE, message);
}
}
public static void notEmpty(@Nullable Object[] array, String message) {
if (ObjectUtils.isEmpty(array)) {
throw new BusinessException(ASSERT_ERROR_CODE, message);
}
}
public static void doesNotContain(@Nullable String textToSearch, String substring, String message) {
if (StringUtils.hasLength(textToSearch) && StringUtils.hasLength(substring) && textToSearch.contains(substring)) {
throw new BusinessException(ASSERT_ERROR_CODE, message);
}
}
}

View File

@ -0,0 +1,36 @@
package com.mcwl.common.utils;
import com.mcwl.common.domain.RequestConditionEntity;
import org.apache.commons.collections4.CollectionUtils;
import static com.mcwl.common.constant.NumberConstant.NUMBER_1;
import static com.mcwl.common.constant.NumberConstant.NUMBER_2;
/**
*
*/
public abstract class BetweenTimeUtil {
private BetweenTimeUtil() {
}
/**
*
*
* @param conditionEntity
*/
public static void parseTime(RequestConditionEntity conditionEntity) {
if (CollectionUtils.isEmpty(conditionEntity.getBetweenTime())) {
return;
}
if (conditionEntity.getBetweenTime().size() == NUMBER_1) {
conditionEntity.setCreateBeginTime(conditionEntity.getBetweenTime().get(0));
} else if (conditionEntity.getBetweenTime().size() == NUMBER_2) {
conditionEntity.setCreateBeginTime(conditionEntity.getBetweenTime().get(0));
conditionEntity.setCreateEndTime(conditionEntity.getBetweenTime().get(1));
}
}
}

View File

@ -0,0 +1,183 @@
package com.mcwl.common.utils;
import com.mcwl.common.core.domain.BaseEntity;
import com.mcwl.common.filter.JwtUserEntity;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import java.util.Date;
import java.util.Objects;
import java.util.function.Supplier;
/**
*
*/
public abstract class FillUserUtil {
private static final Long DEFAULT_USER_ID = 1L;
private static final String DEFAULT_USER_NAME = "系统管理员";
private static final String ANONYMOUS_USER = "anonymousUser";
private FillUserUtil() {
}
/**
*
*
* @param baseEntity
*/
public static void fillCreateDefaultUserInfo(BaseEntity baseEntity) {
baseEntity.setUpdateBy(DEFAULT_USER_NAME);
baseEntity.setCreateTime(new Date());
}
/**
*
*
* @param baseEntity
*/
public static void fillUpdateDefaultUserInfo(BaseEntity baseEntity) {
baseEntity.setUpdateBy(DEFAULT_USER_NAME);
baseEntity.setUpdateTime(new Date());
}
/**
*
*
* @param baseEntity
*/
public static void fillCreateUserInfo(BaseEntity baseEntity) {
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
AssertUtil.notNull(authentication, "当前登录状态过期");
if (authentication.getPrincipal() instanceof String) {
if (ANONYMOUS_USER.equals(authentication.getPrincipal())) {
baseEntity.setCreateBy(DEFAULT_USER_NAME);
baseEntity.setCreateTime(new Date());
}
} else {
JwtUserEntity jwtUserEntity = (JwtUserEntity) authentication.getPrincipal();
baseEntity.setCreateBy(DEFAULT_USER_NAME);
baseEntity.setCreateTime(new Date());
}
}
/**
*
*
* @param baseEntity
*/
public static void fillUpdateUserInfo(BaseEntity baseEntity) {
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
AssertUtil.notNull(authentication, "请先登录");
JwtUserEntity jwtUserEntity = (JwtUserEntity) authentication.getPrincipal();
baseEntity.setUpdateBy(DEFAULT_USER_NAME);
baseEntity.setUpdateTime(new Date());
}
/**
*
*
* @param baseEntity
*/
public static void fillUpdateUserInfoFromCreate(BaseEntity baseEntity) {
baseEntity.setUpdateBy(DEFAULT_USER_NAME);
baseEntity.setUpdateTime(new Date());
}
/**
*
*
* @return
*/
public static JwtUserEntity getCurrentUserInfoOrNull() {
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (Objects.isNull(authentication)) {
return null;
}
Object principal = authentication.getPrincipal();
if (principal instanceof String) {
return null;
}
return (JwtUserEntity) authentication.getPrincipal();
}
/**
*
*
* @return
*/
public static JwtUserEntity getCurrentUserInfo() {
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
AssertUtil.notNull(authentication, "当前登录状态过期");
Object principal = authentication.getPrincipal();
if (principal instanceof String) {
return null;
}
AssertUtil.notNull(authentication.getPrincipal(), "当前登录状态过期");
return (JwtUserEntity) authentication.getPrincipal();
}
/**
* mock
*/
public static void mockCurrentUser() {
JwtUserEntity jwtUserEntity = new JwtUserEntity();
jwtUserEntity.setId(DEFAULT_USER_ID);
jwtUserEntity.setUsername(DEFAULT_USER_NAME);
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(jwtUserEntity, null, jwtUserEntity.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authentication);
}
/**
*
*/
public static void setCurrentUser(Long userId, String userName) {
JwtUserEntity jwtUserEntity = new JwtUserEntity();
jwtUserEntity.setId(userId);
jwtUserEntity.setUsername(userName);
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(jwtUserEntity, null, jwtUserEntity.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authentication);
}
/**
* mock
*
* @param supplier
* @param <T>
* @return
*/
public static <T> T mockCurrentUser(Supplier<T> supplier) {
mockCurrentUser();
try {
return supplier.get();
} finally {
clearCurrentUser();
}
}
/**
* mock
*
* @param supplier
* @param <T>
* @return
*/
public static <T> T mockUser(Supplier<T> supplier, JwtUserEntity jwtUserEntity) {
try {
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(jwtUserEntity, null, jwtUserEntity.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authentication);
return supplier.get();
} finally {
clearCurrentUser();
}
}
/**
*
*/
public static void clearCurrentUser() {
SecurityContextHolder.getContext().setAuthentication(null);
}
}

View File

@ -0,0 +1,52 @@
package com.mcwl.common.utils.bean;
import com.mcwl.common.utils.BetweenTimeUtil;
import com.mcwl.common.domain.RequestConditionEntity;
import com.mcwl.common.utils.ResponsePageEntity;
import com.mcwl.common.web.BaseMapper;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
/**
* service
*/
@Slf4j
public abstract class BaseService<K, V> {
/**
* BaseMapper
*
* @return BaseMapper
*/
protected abstract BaseMapper getBaseMapper();
/**
*
*
* @param v
* @return
*/
public boolean customizeExport(V v) {
return false;
}
/**
*
*
* @return
* @param s
* @param <T>
*/
public <S extends RequestConditionEntity, T> ResponsePageEntity<T> searchByPage(S s) {
BetweenTimeUtil.parseTime(s);
int count = getBaseMapper().searchCount(s);
if (count == 0) {
return ResponsePageEntity.buildEmpty(s);
}
List<T> dataList = getBaseMapper().searchByCondition(s);
return ResponsePageEntity.build(s, count, dataList);
}
}

View File

@ -0,0 +1,31 @@
package com.mcwl.common.web;
import org.springframework.dao.DataAccessException;
import java.util.List;
/**
* mapper
*/
public interface BaseMapper<K, V> {
/**
*
*
* @param v
* @return
*/
int searchCount(V v);
/**
*
*
* @param v
* @return List<K>
* @throws DataAccessException 访
*/
List<K> searchByCondition(V v) throws DataAccessException;
}

View File

@ -15,6 +15,7 @@ import org.apache.ibatis.annotations.Param;
*/
@Mapper
public interface MallProductMapper extends BaseMapper<MallProduct> {
String selectMallProductById(@Param("mallProductId") Long mallProductId);
Long sumNumber(@Param("userId") Long userId);

View File

@ -240,6 +240,7 @@
<module>mcwl-resource</module>
<module>mcwl-memberCenter</module>
<module>mcwl-pay</module>
<module>mcwl-comment</module>
</modules>
<packaging>pom</packaging>