From 672637fa4a4914ec9667cb15f70b67482b8a0e5e Mon Sep 17 00:00:00 2001 From: peng <peng.com> Date: 星期四, 25 九月 2025 17:16:42 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/send_coupon' into user_action --- framework/src/main/java/cn/lili/modules/lmk/service/impl/ShareActionServiceImpl.java | 127 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 127 insertions(+), 0 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/lmk/service/impl/ShareActionServiceImpl.java b/framework/src/main/java/cn/lili/modules/lmk/service/impl/ShareActionServiceImpl.java new file mode 100644 index 0000000..acb7525 --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/service/impl/ShareActionServiceImpl.java @@ -0,0 +1,127 @@ +package cn.lili.modules.lmk.service.impl; + +import cn.lili.common.security.AuthUser; +import cn.lili.common.security.context.UserContext; +import com.baomidou.mybatisplus.core.metadata.IPage; +import cn.lili.modules.lmk.domain.entity.ShareAction; +import cn.lili.modules.lmk.mapper.ShareActionMapper; +import cn.lili.modules.lmk.service.ShareActionService; +import cn.lili.base.Result; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import cn.lili.modules.lmk.domain.form.ShareActionForm; +import cn.lili.modules.lmk.domain.vo.ShareActionVO; +import cn.lili.modules.lmk.domain.query.ShareActionQuery; +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 peng + * @since 2025-09-25 + */ +@Service +@RequiredArgsConstructor +public class ShareActionServiceImpl extends ServiceImpl<ShareActionMapper, ShareAction> implements ShareActionService { + + private final ShareActionMapper shareActionMapper; + + /** + * 娣诲姞 + * @param form + * @return + */ + @Override + public Result add(ShareActionForm form) { + AuthUser currentUser = UserContext.getCurrentUser(); + if (currentUser == null) { + return Result.ok(); + } + + ShareAction entity = ShareActionForm.getEntityByForm(form, null); + entity.setUserId(currentUser.getId()); + baseMapper.insert(entity); + return Result.ok("娣诲姞鎴愬姛").data(entity.getId()); + } + + /** + * 淇敼 + * @param form + * @return + */ + @Override + public Result update(ShareActionForm form) { + ShareAction 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(ShareActionQuery query) { + IPage<ShareActionVO> page = PageUtil.getPage(query, ShareActionVO.class); + baseMapper.getPage(page, query); + return Result.ok().data(page.getRecords()).total(page.getTotal()); + } + + /** + * 鏍规嵁id鏌ユ壘 + * @param id + * @return + */ + @Override + public Result detail(String id) { + ShareActionVO vo = baseMapper.getById(id); + Assert.notNull(vo, "璁板綍涓嶅瓨鍦�"); + return Result.ok().data(vo); + } + + /** + * 鍒楄〃 + * @return + */ + @Override + public Result all() { + List<ShareAction> entities = baseMapper.selectList(null); + List<ShareActionVO> vos = entities.stream() + .map(entity -> ShareActionVO.getVoByEntity(entity, null)) + .collect(Collectors.toList()); + return Result.ok().data(vos); + } +} -- Gitblit v1.8.0