From 56224037cde5a381dbdce941bfc3a4f555584e3b Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期一, 16 六月 2025 20:25:37 +0800 Subject: [PATCH] 视频分享、静默登录 --- framework/src/main/java/cn/lili/modules/lmk/domain/query/ShareClickRecordQuery.java | 22 + framework/src/main/java/cn/lili/mybatis/BaseIdAndDeleteEntity.java | 40 ++ framework/src/main/resources/mapper/lmk/ShareMapper.xml | 47 ++ buyer-api/src/main/java/cn/lili/controller/lmk/ShareController.java | 44 ++ framework/src/main/java/cn/lili/modules/connect/service/ConnectService.java | 11 framework/src/main/resources/mapper/lmk/ShareClickRecordMapper.xml | 44 ++ framework/src/main/java/cn/lili/modules/connect/serviceimpl/ConnectServiceImpl.java | 24 + framework/src/main/java/cn/lili/modules/lmk/service/impl/ShareClickRecordServiceImpl.java | 119 +++++++ framework/src/main/java/cn/lili/modules/lmk/domain/vo/ShareClickRecordVO.java | 43 ++ framework/src/main/java/cn/lili/modules/lmk/domain/entity/Share.java | 40 ++ framework/src/main/java/cn/lili/modules/lmk/domain/query/ShareQuery.java | 22 + framework/src/main/java/cn/lili/modules/lmk/service/impl/ShareServiceImpl.java | 151 ++++++++ framework/src/main/java/cn/lili/modules/member/service/MemberService.java | 4 framework/src/main/java/cn/lili/modules/lmk/domain/form/ShareForm.java | 49 ++ buyer-api/src/main/java/cn/lili/controller/passport/connect/MiniProgramBuyerController.java | 7 framework/src/main/java/cn/lili/modules/lmk/domain/entity/ShareClickRecord.java | 35 ++ framework/src/main/java/cn/lili/modules/lmk/mapper/ShareMapper.java | 34 ++ framework/src/main/java/cn/lili/modules/lmk/service/ShareClickRecordService.java | 65 +++ framework/src/main/java/cn/lili/modules/lmk/service/ShareService.java | 74 ++++ framework/src/main/java/cn/lili/modules/lmk/domain/form/ShareClickRecordForm.java | 38 ++ framework/src/main/java/cn/lili/modules/lmk/domain/vo/ShareVO.java | 47 ++ framework/src/main/java/cn/lili/modules/member/serviceimpl/MemberServiceImpl.java | 1 framework/src/main/java/cn/lili/modules/lmk/mapper/ShareClickRecordMapper.java | 34 ++ 23 files changed, 992 insertions(+), 3 deletions(-) diff --git a/buyer-api/src/main/java/cn/lili/controller/lmk/ShareController.java b/buyer-api/src/main/java/cn/lili/controller/lmk/ShareController.java new file mode 100644 index 0000000..f620ab8 --- /dev/null +++ b/buyer-api/src/main/java/cn/lili/controller/lmk/ShareController.java @@ -0,0 +1,44 @@ +package cn.lili.controller.lmk; + +import cn.lili.base.Result; +import cn.lili.group.Add; +import cn.lili.modules.lmk.domain.form.ShareClickRecordForm; +import cn.lili.modules.lmk.domain.form.ShareForm; +import cn.lili.modules.lmk.service.ShareService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * 鍒嗕韩璁板綍 鍓嶇鎺у埗鍣� + * + * @author xp + * @since 2025-06-16 + */ +@Validated +@RequiredArgsConstructor +@Api(value = "鍒嗕韩璁板綍", tags = "鍒嗕韩璁板綍绠$悊") +@RestController +@RequestMapping("/buyer/lmk/share") +public class ShareController { + + private final ShareService shareService; + + + @PostMapping + @ApiOperation(value = "娣诲姞鍒嗕韩", notes = "娣诲姞鍒嗕韩") + public Result add(@RequestBody @Validated(Add.class) ShareForm form) { + return shareService.add(form); + } + + @PostMapping("/click/record") + @ApiOperation(value = "娣诲姞鍒嗕韩璁块棶璁板綍", notes = "娣诲姞鍒嗕韩璁块棶璁板綍") + public Result addShareClick(@RequestBody @Validated(Add.class) ShareClickRecordForm form) { + return shareService.addShareClick(form); + } +} diff --git a/buyer-api/src/main/java/cn/lili/controller/passport/connect/MiniProgramBuyerController.java b/buyer-api/src/main/java/cn/lili/controller/passport/connect/MiniProgramBuyerController.java index a3c1a6a..1e3b9e7 100644 --- a/buyer-api/src/main/java/cn/lili/controller/passport/connect/MiniProgramBuyerController.java +++ b/buyer-api/src/main/java/cn/lili/controller/passport/connect/MiniProgramBuyerController.java @@ -1,5 +1,6 @@ package cn.lili.controller.passport.connect; +import cn.lili.base.Result; import cn.lili.common.enums.ResultUtil; import cn.lili.common.security.token.Token; import cn.lili.common.vo.ResultMessage; @@ -47,6 +48,12 @@ return ResultUtil.data(this.connectService.miniProgramAutoLogin(params)); } + @GetMapping("/silent-login") + @ApiOperation(value = "灏忕▼搴忛潤榛樼櫥褰�--涓嶈幏鍙栫敤鎴蜂俊鎭�") + public Result silentLogin(String code) { + return this.connectService.silentLogin(code); + } + @GetMapping("/subscribeMessage") @ApiOperation(value = "娑堟伅璁㈤槄") public ResultMessage<List<WechatMPMessage>> autoLogin() { diff --git a/framework/src/main/java/cn/lili/modules/connect/service/ConnectService.java b/framework/src/main/java/cn/lili/modules/connect/service/ConnectService.java index 94fc569..a9356e8 100644 --- a/framework/src/main/java/cn/lili/modules/connect/service/ConnectService.java +++ b/framework/src/main/java/cn/lili/modules/connect/service/ConnectService.java @@ -1,5 +1,6 @@ package cn.lili.modules.connect.service; +import cn.lili.base.Result; import cn.lili.cache.CachePrefix; import cn.lili.common.security.token.Token; import cn.lili.modules.connect.entity.Connect; @@ -105,4 +106,12 @@ * @param type 骞冲彴绫诲瀷 */ void loginBindUser(String userId, String unionId, String type); -} \ No newline at end of file + + /** + * 灏忕▼搴忛潤榛樼櫥褰� + * + * @param code + * @return + */ + Result silentLogin(String code); +} diff --git a/framework/src/main/java/cn/lili/modules/connect/serviceimpl/ConnectServiceImpl.java b/framework/src/main/java/cn/lili/modules/connect/serviceimpl/ConnectServiceImpl.java index 6758887..b281073 100644 --- a/framework/src/main/java/cn/lili/modules/connect/serviceimpl/ConnectServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/connect/serviceimpl/ConnectServiceImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; +import cn.lili.base.Result; import cn.lili.cache.Cache; import cn.lili.common.enums.ClientTypeEnum; import cn.lili.common.enums.ResultCode; @@ -81,6 +82,8 @@ */ @Autowired private RocketmqCustomProperties rocketmqCustomProperties; + + static String DEFAULT_PASSWORD = "111111"; @Override @Transactional(rollbackFor = Exception.class) @@ -243,6 +246,25 @@ } } + @Override + public Result silentLogin(String code) { + JSONObject res = this.getConnect(code); + String unionId = res.getStr("unionid"); + String openId = res.getStr("openid"); + Member user = memberService.findByUUID(openId); + // 涓嶅瓨鍦ㄥ氨娉ㄥ唽 + if (Objects.isNull(user)) { + user = new Member(); + user.setUuId(openId); + user.setUsername(UuidUtils.getUUID()); + user.setNickName("寰俊鐢ㄦ埛"); + user.setPassword(DEFAULT_PASSWORD); + user.setFace("https://i.loli.net/2020/11/19/LyN6JF7zZRskdIe.png"); + memberService.registerHandler(user); + } + Token token = memberTokenGenerate.createToken(user, Boolean.TRUE); + return Result.ok().data(token); + } /** * 绗笁鏂硅仈鍚堢櫥闄� @@ -389,4 +411,4 @@ } -} \ No newline at end of file +} diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/entity/Share.java b/framework/src/main/java/cn/lili/modules/lmk/domain/entity/Share.java new file mode 100644 index 0000000..84e057d --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/domain/entity/Share.java @@ -0,0 +1,40 @@ +package cn.lili.modules.lmk.domain.entity; + +import cn.lili.mybatis.BaseIdAndDeleteEntity; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.time.LocalDateTime; +import java.util.Date; + +/** + * 鍒嗕韩璁板綍 + * + * @author xp + * @since 2025-06-16 + */ +@Data +@TableName("lmk_share") +public class Share extends BaseIdAndDeleteEntity { + + private static final long serialVersionUID = 1L; + + @TableField("share_type") + /** 鍝釜涓氬姟鐨勫垎浜� */ + private String shareType; + + @TableField("ref_id") + /** 涓氬姟id */ + private String refId; + + @TableField("share_user") + /** 鍒嗕韩浜� */ + private String shareUser; + + @TableField("share_time") + /** 鍒嗕韩鏃堕棿 */ + private Date shareTime; + + +} diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/entity/ShareClickRecord.java b/framework/src/main/java/cn/lili/modules/lmk/domain/entity/ShareClickRecord.java new file mode 100644 index 0000000..52c8a04 --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/domain/entity/ShareClickRecord.java @@ -0,0 +1,35 @@ +package cn.lili.modules.lmk.domain.entity; + +import cn.lili.mybatis.BaseIdAndDeleteEntity; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +/** + * 鍒嗕韩鐐瑰嚮璁板綍 + * + * @author xp + * @since 2025-06-16 + */ +@Data +@TableName("lmk_share_click_record") +public class ShareClickRecord extends BaseIdAndDeleteEntity { + + private static final long serialVersionUID = 1L; + + @TableField("share_id") + /** 鍒嗕韩id */ + private String shareId; + + @TableField("user_id") + /** 璋佺偣浜嗚繖涓垎浜� */ + private String userId; + + @TableField("click_time") + /** 鐐瑰嚮鏃堕棿 */ + private Date clickTime; + + +} diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/form/ShareClickRecordForm.java b/framework/src/main/java/cn/lili/modules/lmk/domain/form/ShareClickRecordForm.java new file mode 100644 index 0000000..a8b6aff --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/domain/form/ShareClickRecordForm.java @@ -0,0 +1,38 @@ +package cn.lili.modules.lmk.domain.form; + +import cn.lili.group.Update; +import cn.lili.group.Add; +import cn.lili.base.AbsForm; +import cn.lili.modules.lmk.domain.entity.ShareClickRecord; +import org.springframework.beans.BeanUtils; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import org.springframework.lang.NonNull; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import java.util.Date; + +/** + * 鍒嗕韩鐐瑰嚮璁板綍琛ㄥ崟 + * + * @author xp + * @since 2025-06-16 + */ +@Data +@ApiModel(value = "ShareClickRecord琛ㄥ崟", description = "鍒嗕韩鐐瑰嚮璁板綍琛ㄥ崟") +public class ShareClickRecordForm extends AbsForm { + + @NotBlank(message = "鍒嗕韩id涓嶈兘涓虹┖", groups = {Add.class, Update.class}) + @ApiModelProperty("鍒嗕韩id") + private String shareId; + + public static ShareClickRecord getEntityByForm(@NonNull ShareClickRecordForm form, ShareClickRecord entity) { + if(entity == null) { + entity = new ShareClickRecord(); + } + BeanUtils.copyProperties(form, entity); + return entity; + } + +} diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/form/ShareForm.java b/framework/src/main/java/cn/lili/modules/lmk/domain/form/ShareForm.java new file mode 100644 index 0000000..5eca51f --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/domain/form/ShareForm.java @@ -0,0 +1,49 @@ +package cn.lili.modules.lmk.domain.form; + +import cn.lili.group.Update; +import cn.lili.group.Add; +import cn.lili.base.AbsForm; +import cn.lili.modules.lmk.domain.entity.Share; +import org.springframework.beans.BeanUtils; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import org.springframework.lang.NonNull; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import java.util.Date; + +/** + * 鍒嗕韩璁板綍琛ㄥ崟 + * + * @author xp + * @since 2025-06-16 + */ +@Data +@ApiModel(value = "Share琛ㄥ崟", description = "鍒嗕韩璁板綍琛ㄥ崟") +public class ShareForm extends AbsForm { + + @NotBlank(message = "涓氬姟绫诲瀷涓嶈兘涓虹┖", groups = {Add.class, Update.class}) + @ApiModelProperty("鍝釜涓氬姟鐨勫垎浜�") + private String shareType; + + @NotBlank(message = "涓氬姟id涓嶈兘涓虹┖", groups = {Add.class, Update.class}) + @ApiModelProperty("涓氬姟id") + private String refId; + + @NotBlank(message = "鍒嗕韩浜轰笉鑳戒负绌�", groups = {Add.class, Update.class}) + @ApiModelProperty("鍒嗕韩浜�") + private String shareUser; + + @ApiModelProperty("鍒嗕韩鏃堕棿") + private Date shareTime; + + public static Share getEntityByForm(@NonNull ShareForm form, Share entity) { + if(entity == null) { + entity = new Share(); + } + BeanUtils.copyProperties(form, entity); + return entity; + } + +} diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/query/ShareClickRecordQuery.java b/framework/src/main/java/cn/lili/modules/lmk/domain/query/ShareClickRecordQuery.java new file mode 100644 index 0000000..9b1a36c --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/domain/query/ShareClickRecordQuery.java @@ -0,0 +1,22 @@ +package cn.lili.modules.lmk.domain.query; + +import cn.lili.base.AbsQuery; +import java.util.List; +import org.springframework.lang.NonNull; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 鍒嗕韩鐐瑰嚮璁板綍鏌ヨ + * + * @author xp + * @since 2025-06-16 + */ +@Data +@ApiModel(value = "ShareClickRecord鏌ヨ鍙傛暟", description = "鍒嗕韩鐐瑰嚮璁板綍鏌ヨ鍙傛暟") +public class ShareClickRecordQuery extends AbsQuery { +} + diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/query/ShareQuery.java b/framework/src/main/java/cn/lili/modules/lmk/domain/query/ShareQuery.java new file mode 100644 index 0000000..4f0d067 --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/domain/query/ShareQuery.java @@ -0,0 +1,22 @@ +package cn.lili.modules.lmk.domain.query; + +import cn.lili.base.AbsQuery; +import java.util.List; +import org.springframework.lang.NonNull; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 鍒嗕韩璁板綍鏌ヨ + * + * @author xp + * @since 2025-06-16 + */ +@Data +@ApiModel(value = "Share鏌ヨ鍙傛暟", description = "鍒嗕韩璁板綍鏌ヨ鍙傛暟") +public class ShareQuery extends AbsQuery { +} + diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/vo/ShareClickRecordVO.java b/framework/src/main/java/cn/lili/modules/lmk/domain/vo/ShareClickRecordVO.java new file mode 100644 index 0000000..bcfea1b --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/domain/vo/ShareClickRecordVO.java @@ -0,0 +1,43 @@ +package cn.lili.modules.lmk.domain.vo; + +import cn.lili.base.AbsVo; +import cn.lili.modules.lmk.domain.entity.ShareClickRecord; +import java.util.List; +import org.springframework.lang.NonNull; +import org.springframework.beans.BeanUtils; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import java.util.Date; + +/** + * 鍒嗕韩鐐瑰嚮璁板綍灞曠ず + * + * @author xp + * @since 2025-06-16 + */ +@Data +@ApiModel(value = "鍒嗕韩鐐瑰嚮璁板綍鍝嶅簲鏁版嵁", description = "鍒嗕韩鐐瑰嚮璁板綍鍝嶅簲鏁版嵁") +public class ShareClickRecordVO extends AbsVo { + + /** 鍒嗕韩id */ + @ApiModelProperty("鍒嗕韩id") + private String shareId; + + /** 璋佺偣浜嗚繖涓垎浜� */ + @ApiModelProperty("璋佺偣浜嗚繖涓垎浜�") + private String userId; + + /** 鐐瑰嚮鏃堕棿 */ + @ApiModelProperty("鐐瑰嚮鏃堕棿") + private Date clickTime; + + public static ShareClickRecordVO getVoByEntity(@NonNull ShareClickRecord entity, ShareClickRecordVO vo) { + if(vo == null) { + vo = new ShareClickRecordVO(); + } + BeanUtils.copyProperties(entity, vo); + return vo; + } + +} diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/vo/ShareVO.java b/framework/src/main/java/cn/lili/modules/lmk/domain/vo/ShareVO.java new file mode 100644 index 0000000..0efdae6 --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/domain/vo/ShareVO.java @@ -0,0 +1,47 @@ +package cn.lili.modules.lmk.domain.vo; + +import cn.lili.base.AbsVo; +import cn.lili.modules.lmk.domain.entity.Share; +import java.util.List; +import org.springframework.lang.NonNull; +import org.springframework.beans.BeanUtils; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import java.util.Date; + +/** + * 鍒嗕韩璁板綍灞曠ず + * + * @author xp + * @since 2025-06-16 + */ +@Data +@ApiModel(value = "鍒嗕韩璁板綍鍝嶅簲鏁版嵁", description = "鍒嗕韩璁板綍鍝嶅簲鏁版嵁") +public class ShareVO extends AbsVo { + + /** 鍝釜涓氬姟鐨勫垎浜� */ + @ApiModelProperty("鍝釜涓氬姟鐨勫垎浜�") + private String shareType; + + /** 涓氬姟id */ + @ApiModelProperty("涓氬姟id") + private String refId; + + /** 鍒嗕韩浜� */ + @ApiModelProperty("鍒嗕韩浜�") + private String shareUser; + + /** 鍒嗕韩鏃堕棿 */ + @ApiModelProperty("鍒嗕韩鏃堕棿") + private Date shareTime; + + public static ShareVO getVoByEntity(@NonNull Share entity, ShareVO vo) { + if(vo == null) { + vo = new ShareVO(); + } + BeanUtils.copyProperties(entity, vo); + return vo; + } + +} diff --git a/framework/src/main/java/cn/lili/modules/lmk/mapper/ShareClickRecordMapper.java b/framework/src/main/java/cn/lili/modules/lmk/mapper/ShareClickRecordMapper.java new file mode 100644 index 0000000..88772b7 --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/mapper/ShareClickRecordMapper.java @@ -0,0 +1,34 @@ +package cn.lili.modules.lmk.mapper; + +import cn.lili.modules.lmk.domain.entity.ShareClickRecord; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import cn.lili.modules.lmk.domain.vo.ShareClickRecordVO; +import cn.lili.modules.lmk.domain.form.ShareClickRecordForm; +import cn.lili.modules.lmk.domain.query.ShareClickRecordQuery; +import java.util.List; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * 鍒嗕韩鐐瑰嚮璁板綍 Mapper 鎺ュ彛 + * + * @author xp + * @since 2025-06-16 + */ +@Mapper +public interface ShareClickRecordMapper extends BaseMapper<ShareClickRecord> { + + /** + * id鏌ユ壘鍒嗕韩鐐瑰嚮璁板綍 + * @param id + * @return + */ + ShareClickRecordVO getById(String id); + + /** + * 鍒嗛〉 + */ + IPage getPage(IPage page, @Param("query") ShareClickRecordQuery query); + +} diff --git a/framework/src/main/java/cn/lili/modules/lmk/mapper/ShareMapper.java b/framework/src/main/java/cn/lili/modules/lmk/mapper/ShareMapper.java new file mode 100644 index 0000000..932837b --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/mapper/ShareMapper.java @@ -0,0 +1,34 @@ +package cn.lili.modules.lmk.mapper; + +import cn.lili.modules.lmk.domain.entity.Share; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import cn.lili.modules.lmk.domain.vo.ShareVO; +import cn.lili.modules.lmk.domain.form.ShareForm; +import cn.lili.modules.lmk.domain.query.ShareQuery; +import java.util.List; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * 鍒嗕韩璁板綍 Mapper 鎺ュ彛 + * + * @author xp + * @since 2025-06-16 + */ +@Mapper +public interface ShareMapper extends BaseMapper<Share> { + + /** + * id鏌ユ壘鍒嗕韩璁板綍 + * @param id + * @return + */ + ShareVO getById(String id); + + /** + * 鍒嗛〉 + */ + IPage getPage(IPage page, @Param("query") ShareQuery query); + +} diff --git a/framework/src/main/java/cn/lili/modules/lmk/service/ShareClickRecordService.java b/framework/src/main/java/cn/lili/modules/lmk/service/ShareClickRecordService.java new file mode 100644 index 0000000..e5e4891 --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/service/ShareClickRecordService.java @@ -0,0 +1,65 @@ +package cn.lili.modules.lmk.service; + +import cn.lili.modules.lmk.domain.entity.ShareClickRecord; +import com.baomidou.mybatisplus.extension.service.IService; +import cn.lili.base.Result; +import cn.lili.modules.lmk.domain.form.ShareClickRecordForm; +import cn.lili.modules.lmk.domain.query.ShareClickRecordQuery; +import java.util.List; + +/** + * 鍒嗕韩鐐瑰嚮璁板綍 鏈嶅姟绫� + * + * @author xp + * @since 2025-06-16 + */ +public interface ShareClickRecordService extends IService<ShareClickRecord> { + + /** + * 娣诲姞 + * @param form + * @return + */ + Result add(ShareClickRecordForm form); + + /** + * 淇敼 + * @param form + * @return + */ + Result update(ShareClickRecordForm form); + + /** + * 鎵归噺鍒犻櫎 + * @param ids + * @return + */ + Result remove(List<String> ids); + + /** + * id鍒犻櫎 + * @param id + * @return + */ + Result removeById(String id); + + /** + * 鍒嗛〉鏌ヨ + * @param query + * @return + */ + Result page(ShareClickRecordQuery query); + + /** + * 鏍规嵁id鏌ユ壘 + * @param id + * @return + */ + Result detail(String id); + + /** + * 鍒楄〃 + * @return + */ + Result all(); +} diff --git a/framework/src/main/java/cn/lili/modules/lmk/service/ShareService.java b/framework/src/main/java/cn/lili/modules/lmk/service/ShareService.java new file mode 100644 index 0000000..3cf7753 --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/service/ShareService.java @@ -0,0 +1,74 @@ +package cn.lili.modules.lmk.service; + +import cn.lili.modules.lmk.domain.entity.Share; +import cn.lili.modules.lmk.domain.form.ShareClickRecordForm; +import com.baomidou.mybatisplus.extension.service.IService; +import cn.lili.base.Result; +import cn.lili.modules.lmk.domain.form.ShareForm; +import cn.lili.modules.lmk.domain.query.ShareQuery; +import java.util.List; + +/** + * 鍒嗕韩璁板綍 鏈嶅姟绫� + * + * @author xp + * @since 2025-06-16 + */ +public interface ShareService extends IService<Share> { + + /** + * 娣诲姞 + * @param form + * @return + */ + Result add(ShareForm form); + + /** + * 淇敼 + * @param form + * @return + */ + Result update(ShareForm form); + + /** + * 鎵归噺鍒犻櫎 + * @param ids + * @return + */ + Result remove(List<String> ids); + + /** + * id鍒犻櫎 + * @param id + * @return + */ + Result removeById(String id); + + /** + * 鍒嗛〉鏌ヨ + * @param query + * @return + */ + Result page(ShareQuery query); + + /** + * 鏍规嵁id鏌ユ壘 + * @param id + * @return + */ + Result detail(String id); + + /** + * 鍒楄〃 + * @return + */ + Result all(); + + /** + * 娣诲姞鍒嗕韩璁块棶璁板綍 + * + * @param form + * @return + */ + Result addShareClick(ShareClickRecordForm form); +} diff --git a/framework/src/main/java/cn/lili/modules/lmk/service/impl/ShareClickRecordServiceImpl.java b/framework/src/main/java/cn/lili/modules/lmk/service/impl/ShareClickRecordServiceImpl.java new file mode 100644 index 0000000..a3fd375 --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/service/impl/ShareClickRecordServiceImpl.java @@ -0,0 +1,119 @@ +package cn.lili.modules.lmk.service.impl; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import cn.lili.modules.lmk.domain.entity.ShareClickRecord; +import cn.lili.modules.lmk.mapper.ShareClickRecordMapper; +import cn.lili.modules.lmk.service.ShareClickRecordService; +import cn.lili.base.Result; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import cn.lili.modules.lmk.domain.form.ShareClickRecordForm; +import cn.lili.modules.lmk.domain.vo.ShareClickRecordVO; +import cn.lili.modules.lmk.domain.query.ShareClickRecordQuery; +import org.springframework.stereotype.Service; +import lombok.RequiredArgsConstructor; +import cn.lili.utils.PageUtil; +import org.springframework.beans.BeanUtils; +import org.springframework.util.Assert; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * 鍒嗕韩鐐瑰嚮璁板綍 鏈嶅姟瀹炵幇绫� + * + * @author xp + * @since 2025-06-16 + */ +@Service +@RequiredArgsConstructor +public class ShareClickRecordServiceImpl extends ServiceImpl<ShareClickRecordMapper, ShareClickRecord> implements ShareClickRecordService { + + private final ShareClickRecordMapper shareClickRecordMapper; + + /** + * 娣诲姞 + * @param form + * @return + */ + @Override + public Result add(ShareClickRecordForm form) { + ShareClickRecord entity = ShareClickRecordForm.getEntityByForm(form, null); + baseMapper.insert(entity); + return Result.ok("娣诲姞鎴愬姛"); + } + + /** + * 淇敼 + * @param form + * @return + */ + @Override + public Result update(ShareClickRecordForm form) { + ShareClickRecord entity = baseMapper.selectById(form.getId()); + + // 涓虹┖鎶汭llegalArgumentException锛屽仛鍏ㄥ眬寮傚父澶勭悊 + Assert.notNull(entity, "璁板綍涓嶅瓨鍦�"); + BeanUtils.copyProperties(form, entity); + baseMapper.updateById(entity); + return Result.ok("淇敼鎴愬姛"); + } + + /** + * 鎵归噺鍒犻櫎 + * @param ids + * @return + */ + @Override + public Result remove(List<String> ids) { + baseMapper.deleteBatchIds(ids); + return Result.ok("鍒犻櫎鎴愬姛"); + } + + /** + * id鍒犻櫎 + * @param id + * @return + */ + @Override + public Result removeById(String id) { + baseMapper.deleteById(id); + return Result.ok("鍒犻櫎鎴愬姛"); + } + + /** + * 鍒嗛〉鏌ヨ + * @param query + * @return + */ + @Override + public Result page(ShareClickRecordQuery query) { + IPage<ShareClickRecordVO> page = PageUtil.getPage(query, ShareClickRecordVO.class); + baseMapper.getPage(page, query); + return Result.ok().data(page.getRecords()).total(page.getTotal()); + } + + /** + * 鏍规嵁id鏌ユ壘 + * @param id + * @return + */ + @Override + public Result detail(String id) { + ShareClickRecordVO vo = baseMapper.getById(id); + Assert.notNull(vo, "璁板綍涓嶅瓨鍦�"); + return Result.ok().data(vo); + } + + /** + * 鍒楄〃 + * @return + */ + @Override + public Result all() { + List<ShareClickRecord> entities = baseMapper.selectList(null); + List<ShareClickRecordVO> vos = entities.stream() + .map(entity -> ShareClickRecordVO.getVoByEntity(entity, null)) + .collect(Collectors.toList()); + return Result.ok().data(vos); + } +} diff --git a/framework/src/main/java/cn/lili/modules/lmk/service/impl/ShareServiceImpl.java b/framework/src/main/java/cn/lili/modules/lmk/service/impl/ShareServiceImpl.java new file mode 100644 index 0000000..bf52b55 --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/service/impl/ShareServiceImpl.java @@ -0,0 +1,151 @@ +package cn.lili.modules.lmk.service.impl; + +import cn.lili.common.security.context.UserContext; +import cn.lili.modules.lmk.domain.entity.ShareClickRecord; +import cn.lili.modules.lmk.domain.form.ShareClickRecordForm; +import cn.lili.modules.lmk.service.ShareClickRecordService; +import com.baomidou.mybatisplus.core.metadata.IPage; +import cn.lili.modules.lmk.domain.entity.Share; +import cn.lili.modules.lmk.mapper.ShareMapper; +import cn.lili.modules.lmk.service.ShareService; +import cn.lili.base.Result; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import cn.lili.modules.lmk.domain.form.ShareForm; +import cn.lili.modules.lmk.domain.vo.ShareVO; +import cn.lili.modules.lmk.domain.query.ShareQuery; +import org.springframework.stereotype.Service; +import lombok.RequiredArgsConstructor; +import cn.lili.utils.PageUtil; +import org.springframework.beans.BeanUtils; +import org.springframework.util.Assert; + +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 鍒嗕韩璁板綍 鏈嶅姟瀹炵幇绫� + * + * @author xp + * @since 2025-06-16 + */ +@Service +@RequiredArgsConstructor +public class ShareServiceImpl extends ServiceImpl<ShareMapper, Share> implements ShareService { + + private final ShareMapper shareMapper; + private final ShareClickRecordService shareClickRecordService; + + /** + * 娣诲姞 + * @param form + * @return + */ + @Override + public Result add(ShareForm form) { + // 娌″垎浜繃鎵嶆柊澧� + boolean exists = new LambdaQueryChainWrapper<>(baseMapper) + .eq(Share::getShareType, form.getShareType()) + .eq(Share::getRefId, form.getRefId()) + .eq(Share::getShareUser, form.getShareUser()) + .exists(); + if (! exists) { + Share entity = ShareForm.getEntityByForm(form, null); + entity.setShareTime(new Date()); + baseMapper.insert(entity); + } + return Result.ok(); + } + + /** + * 淇敼 + * @param form + * @return + */ + @Override + public Result update(ShareForm form) { + Share entity = baseMapper.selectById(form.getId()); + + // 涓虹┖鎶汭llegalArgumentException锛屽仛鍏ㄥ眬寮傚父澶勭悊 + Assert.notNull(entity, "璁板綍涓嶅瓨鍦�"); + BeanUtils.copyProperties(form, entity); + baseMapper.updateById(entity); + return Result.ok("淇敼鎴愬姛"); + } + + /** + * 鎵归噺鍒犻櫎 + * @param ids + * @return + */ + @Override + public Result remove(List<String> ids) { + baseMapper.deleteBatchIds(ids); + return Result.ok("鍒犻櫎鎴愬姛"); + } + + /** + * id鍒犻櫎 + * @param id + * @return + */ + @Override + public Result removeById(String id) { + baseMapper.deleteById(id); + return Result.ok("鍒犻櫎鎴愬姛"); + } + + /** + * 鍒嗛〉鏌ヨ + * @param query + * @return + */ + @Override + public Result page(ShareQuery query) { + IPage<ShareVO> page = PageUtil.getPage(query, ShareVO.class); + baseMapper.getPage(page, query); + return Result.ok().data(page.getRecords()).total(page.getTotal()); + } + + /** + * 鏍规嵁id鏌ユ壘 + * @param id + * @return + */ + @Override + public Result detail(String id) { + ShareVO vo = baseMapper.getById(id); + Assert.notNull(vo, "璁板綍涓嶅瓨鍦�"); + return Result.ok().data(vo); + } + + /** + * 鍒楄〃 + * @return + */ + @Override + public Result all() { + List<Share> entities = baseMapper.selectList(null); + List<ShareVO> vos = entities.stream() + .map(entity -> ShareVO.getVoByEntity(entity, null)) + .collect(Collectors.toList()); + return Result.ok().data(vos); + } + + @Override + public Result addShareClick(ShareClickRecordForm form) { + // 娌℃湁璁块棶杩囨墠娣诲姞 + boolean exists = new LambdaQueryChainWrapper<>(shareClickRecordService.getBaseMapper()) + .eq(ShareClickRecord::getUserId, UserContext.getCurrentUserId()) + .eq(ShareClickRecord::getShareId, form.getShareId()) + .exists(); + if (! exists) { + ShareClickRecord record = ShareClickRecordForm.getEntityByForm(form, null); + record.setUserId(UserContext.getCurrentUserId()); + record.setClickTime(new Date()); + shareClickRecordService.save(record); + } + return Result.ok(); + } +} diff --git a/framework/src/main/java/cn/lili/modules/member/service/MemberService.java b/framework/src/main/java/cn/lili/modules/member/service/MemberService.java index 20983da..a3ba9b1 100644 --- a/framework/src/main/java/cn/lili/modules/member/service/MemberService.java +++ b/framework/src/main/java/cn/lili/modules/member/service/MemberService.java @@ -338,4 +338,6 @@ QRLoginResultVo loginWithSession(String token); Member findByUUID(String uuid); -} \ No newline at end of file + + void registerHandler(Member user); +} diff --git a/framework/src/main/java/cn/lili/modules/member/serviceimpl/MemberServiceImpl.java b/framework/src/main/java/cn/lili/modules/member/serviceimpl/MemberServiceImpl.java index 5cf289a..489d7ea 100644 --- a/framework/src/main/java/cn/lili/modules/member/serviceimpl/MemberServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/member/serviceimpl/MemberServiceImpl.java @@ -313,6 +313,7 @@ * @param member */ @Transactional + @Override public void registerHandler(Member member) { member.setId(SnowFlake.getIdStr()); //淇濆瓨浼氬憳 diff --git a/framework/src/main/java/cn/lili/mybatis/BaseIdAndDeleteEntity.java b/framework/src/main/java/cn/lili/mybatis/BaseIdAndDeleteEntity.java new file mode 100644 index 0000000..7ca9902 --- /dev/null +++ b/framework/src/main/java/cn/lili/mybatis/BaseIdAndDeleteEntity.java @@ -0,0 +1,40 @@ +package cn.lili.mybatis; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + + +/** + * 鏁版嵁搴撳熀纭�瀹炰綋绫� + * + * @author Chopper + * @version v1.0 + * @since 2020/8/20 14:34 + */ +@Data +@JsonIgnoreProperties(value = { "handler", "fieldHandler"}) +@AllArgsConstructor +@NoArgsConstructor +public abstract class BaseIdAndDeleteEntity implements Serializable { + + private static final long serialVersionUID = 1L; + + + @TableId + @ApiModelProperty(value = "鍞竴鏍囪瘑", hidden = true) + private String id; + + + @TableField(fill = FieldFill.INSERT) + @ApiModelProperty(value = "鍒犻櫎鏍囧織 true/false 鍒犻櫎/鏈垹闄�", hidden = true) + private Boolean deleteFlag; + +} diff --git a/framework/src/main/resources/mapper/lmk/ShareClickRecordMapper.xml b/framework/src/main/resources/mapper/lmk/ShareClickRecordMapper.xml new file mode 100644 index 0000000..d55f048 --- /dev/null +++ b/framework/src/main/resources/mapper/lmk/ShareClickRecordMapper.xml @@ -0,0 +1,44 @@ +<?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="cn.lili.modules.lmk.mapper.ShareClickRecordMapper"> + + <!-- 閫氱敤鏌ヨ鏄犲皠缁撴灉 --> + <resultMap id="BaseResultMap" type="cn.lili.modules.lmk.domain.vo.ShareClickRecordVO"> + <id column="id" property="id"/> + <result column="share_id" property="shareId" /> + <result column="user_id" property="userId" /> + <result column="click_time" property="clickTime" /> + </resultMap> + + + + + + + + <select id="getById" resultMap="BaseResultMap"> + SELECT + LSCR.share_id, + LSCR.user_id, + LSCR.click_time, + LSCR.id + FROM + lmk_share_click_record LSCR + WHERE + LSCR.id = #{id} AND LSCR.delete_flag = 0 + </select> + + + <select id="getPage" resultMap="BaseResultMap"> + SELECT + LSCR.share_id, + LSCR.user_id, + LSCR.click_time, + LSCR.id + FROM + lmk_share_click_record LSCR + WHERE + LSCR.delete_flag = 0 + </select> + +</mapper> diff --git a/framework/src/main/resources/mapper/lmk/ShareMapper.xml b/framework/src/main/resources/mapper/lmk/ShareMapper.xml new file mode 100644 index 0000000..a16a2cb --- /dev/null +++ b/framework/src/main/resources/mapper/lmk/ShareMapper.xml @@ -0,0 +1,47 @@ +<?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="cn.lili.modules.lmk.mapper.ShareMapper"> + + <!-- 閫氱敤鏌ヨ鏄犲皠缁撴灉 --> + <resultMap id="BaseResultMap" type="cn.lili.modules.lmk.domain.vo.ShareVO"> + <id column="id" property="id"/> + <result column="share_type" property="shareType" /> + <result column="ref_id" property="refId" /> + <result column="share_user" property="shareUser" /> + <result column="share_time" property="shareTime" /> + </resultMap> + + + + + + + + <select id="getById" resultMap="BaseResultMap"> + SELECT + LS.share_type, + LS.ref_id, + LS.share_user, + LS.share_time, + LS.id + FROM + lmk_share LS + WHERE + LS.id = #{id} AND LS.delete_flag = 0 + </select> + + + <select id="getPage" resultMap="BaseResultMap"> + SELECT + LS.share_type, + LS.ref_id, + LS.share_user, + LS.share_time, + LS.id + FROM + lmk_share LS + WHERE + LS.delete_flag = 0 + </select> + +</mapper> -- Gitblit v1.8.0