From f40914a35678266624c6dbf382b31b2db9ac6720 Mon Sep 17 00:00:00 2001
From: zxl <763096477@qq.com>
Date: 星期六, 11 十月 2025 09:17:09 +0800
Subject: [PATCH] 定制商品模板

---
 framework/src/main/java/cn/lili/modules/lmk/domain/query/GoodsCustomizeTemplateQuery.java       |    4 
 framework/src/main/java/cn/lili/modules/lmk/domain/vo/GoodsCustomizeTemplateVO.java             |    6 +
 framework/src/main/java/cn/lili/modules/lmk/service/impl/GoodsCustomizeTemplateServiceImpl.java |  112 ++++++++++++++++++++++
 framework/src/main/resources/mapper/lmk/VideoMapper.xml                                         |    1 
 seller-api/src/main/java/cn/lili/controller/template/GoodsCustomizeTemplateController.java      |   55 +++++++++++
 framework/src/main/java/cn/lili/modules/lmk/domain/form/GoodsCustomizeTemplateForm.java         |    7 +
 framework/src/main/java/cn/lili/modules/lmk/enums/general/TemplateContentTypeEnum.java          |   22 ++++
 framework/src/main/java/cn/lili/modules/lmk/domain/entity/GoodsCustomizeTemplate.java           |    5 
 framework/src/main/java/cn/lili/modules/lmk/domain/entity/TemplateImgs.java                     |    7 +
 framework/src/main/java/cn/lili/modules/lmk/service/GoodsCustomizeTemplateService.java          |    2 
 framework/src/main/java/cn/lili/modules/lmk/domain/entity/TemplateConstomizeTitle.java          |   11 ++
 framework/src/main/resources/mapper/lmk/GoodsCustomizeTemplateMapper.xml                        |   12 +-
 12 files changed, 236 insertions(+), 8 deletions(-)

diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/entity/GoodsCustomizeTemplate.java b/framework/src/main/java/cn/lili/modules/lmk/domain/entity/GoodsCustomizeTemplate.java
index 74bf2bd..06f5de1 100644
--- a/framework/src/main/java/cn/lili/modules/lmk/domain/entity/GoodsCustomizeTemplate.java
+++ b/framework/src/main/java/cn/lili/modules/lmk/domain/entity/GoodsCustomizeTemplate.java
@@ -22,7 +22,10 @@
     private String templateName;
 
     @TableField("status")
-    /** 鍚敤鐘舵�� */
+    /**
+     * 鍚敤鐘舵��
+     * @see cn.lili.modules.lmk.enums.general.EnableStatusEnums
+     */
     private String status;
 
 
diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/entity/TemplateConstomizeTitle.java b/framework/src/main/java/cn/lili/modules/lmk/domain/entity/TemplateConstomizeTitle.java
index c2f70b0..37c1e9e 100644
--- a/framework/src/main/java/cn/lili/modules/lmk/domain/entity/TemplateConstomizeTitle.java
+++ b/framework/src/main/java/cn/lili/modules/lmk/domain/entity/TemplateConstomizeTitle.java
@@ -3,7 +3,9 @@
 import cn.lili.mybatis.BaseEntity;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.AllArgsConstructor;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 
 /**
  * 妯℃澘鏍囬
@@ -12,6 +14,8 @@
  * @since 2025-10-09
  */
 @Data
+@NoArgsConstructor
+@AllArgsConstructor
 @TableName("lmk_template_constomize_title")
 public class TemplateConstomizeTitle extends BaseEntity {
 
@@ -27,7 +31,14 @@
 
     @TableField("content_type")
     /** 鏍囬绫诲瀷 */
+    /**
+     * @see cn.lili.modules.lmk.enums.general.TemplateContentTypeEnum
+     */
     private String contentType;
 
+    public TemplateConstomizeTitle(String templateTitle,String contentType) {
+        this.templateTitle = templateTitle;
+        this.contentType = contentType;
+    }
 
 }
diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/entity/TemplateImgs.java b/framework/src/main/java/cn/lili/modules/lmk/domain/entity/TemplateImgs.java
index dbbc967..2a4076a 100644
--- a/framework/src/main/java/cn/lili/modules/lmk/domain/entity/TemplateImgs.java
+++ b/framework/src/main/java/cn/lili/modules/lmk/domain/entity/TemplateImgs.java
@@ -3,7 +3,9 @@
 import cn.lili.mybatis.BaseEntity;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.AllArgsConstructor;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 
 /**
  * 妯℃澘鍥剧墖
@@ -12,6 +14,8 @@
  * @since 2025-10-09
  */
 @Data
+@NoArgsConstructor
+@AllArgsConstructor
 @TableName("lmk_template_imgs")
 public class TemplateImgs extends BaseEntity {
 
@@ -25,5 +29,8 @@
     /** 鍥剧墖鍦板潃 */
     private String imgUrl;
 
+    public TemplateImgs(String imgUrl) {
+        this.imgUrl = imgUrl; // 鍙祴鍊糹mgUrl锛屽叾浠栧瓧娈碉紙濡倀emplateId锛夊彲鍚庣画閫氳繃涓氬姟閫昏緫琛ュ厖
+    }
 
 }
diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/form/GoodsCustomizeTemplateForm.java b/framework/src/main/java/cn/lili/modules/lmk/domain/form/GoodsCustomizeTemplateForm.java
index 043deca..b6f55b3 100644
--- a/framework/src/main/java/cn/lili/modules/lmk/domain/form/GoodsCustomizeTemplateForm.java
+++ b/framework/src/main/java/cn/lili/modules/lmk/domain/form/GoodsCustomizeTemplateForm.java
@@ -4,6 +4,8 @@
 import cn.lili.group.Add;
 import cn.lili.base.AbsForm;
 import cn.lili.modules.lmk.domain.entity.GoodsCustomizeTemplate;
+import cn.lili.modules.lmk.domain.entity.TemplateConstomizeTitle;
+import cn.lili.modules.lmk.domain.entity.TemplateImgs;
 import org.springframework.beans.BeanUtils;
 import javax.validation.constraints.NotBlank;
 import javax.validation.constraints.NotNull;
@@ -12,6 +14,7 @@
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import java.util.Date;
+import java.util.List;
 
 /**
  * 瀹氬埗鍟嗗搧妯℃澘琛ㄥ崟
@@ -31,6 +34,10 @@
     @ApiModelProperty("鍚敤鐘舵��")
     private String status;
 
+    private List<TemplateConstomizeTitle> titles;
+
+    private List<TemplateImgs> listImages;
+
     public static GoodsCustomizeTemplate getEntityByForm(@NonNull GoodsCustomizeTemplateForm form, GoodsCustomizeTemplate entity) {
         if(entity == null) {
           entity = new GoodsCustomizeTemplate();
diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/query/GoodsCustomizeTemplateQuery.java b/framework/src/main/java/cn/lili/modules/lmk/domain/query/GoodsCustomizeTemplateQuery.java
index 9e30eda..dd5c816 100644
--- a/framework/src/main/java/cn/lili/modules/lmk/domain/query/GoodsCustomizeTemplateQuery.java
+++ b/framework/src/main/java/cn/lili/modules/lmk/domain/query/GoodsCustomizeTemplateQuery.java
@@ -18,5 +18,9 @@
 @Data
 @ApiModel(value = "GoodsCustomizeTemplate鏌ヨ鍙傛暟", description = "瀹氬埗鍟嗗搧妯℃澘鏌ヨ鍙傛暟")
 public class GoodsCustomizeTemplateQuery extends AbsQuery {
+    private String templateName;
+
+    private String status;
+
 }
 
diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/vo/GoodsCustomizeTemplateVO.java b/framework/src/main/java/cn/lili/modules/lmk/domain/vo/GoodsCustomizeTemplateVO.java
index f3f54f1..63e2b29 100644
--- a/framework/src/main/java/cn/lili/modules/lmk/domain/vo/GoodsCustomizeTemplateVO.java
+++ b/framework/src/main/java/cn/lili/modules/lmk/domain/vo/GoodsCustomizeTemplateVO.java
@@ -3,6 +3,9 @@
 import cn.lili.base.AbsVo;
 import cn.lili.modules.lmk.domain.entity.GoodsCustomizeTemplate;
 import java.util.List;
+
+import cn.lili.modules.lmk.domain.entity.TemplateConstomizeTitle;
+import cn.lili.modules.lmk.domain.entity.TemplateImgs;
 import org.springframework.lang.NonNull;
 import org.springframework.beans.BeanUtils;
 import io.swagger.annotations.ApiModel;
@@ -28,6 +31,9 @@
     @ApiModelProperty("鍚敤鐘舵��")
     private String status;
 
+    private List<TemplateImgs> listImages;
+    private List<TemplateConstomizeTitle> titles;
+
     public static GoodsCustomizeTemplateVO getVoByEntity(@NonNull GoodsCustomizeTemplate entity, GoodsCustomizeTemplateVO vo) {
         if(vo == null) {
             vo = new GoodsCustomizeTemplateVO();
diff --git a/framework/src/main/java/cn/lili/modules/lmk/enums/general/TemplateContentTypeEnum.java b/framework/src/main/java/cn/lili/modules/lmk/enums/general/TemplateContentTypeEnum.java
new file mode 100644
index 0000000..f1c53fc
--- /dev/null
+++ b/framework/src/main/java/cn/lili/modules/lmk/enums/general/TemplateContentTypeEnum.java
@@ -0,0 +1,22 @@
+package cn.lili.modules.lmk.enums.general;
+
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * lmk-shop-java
+ *
+ * @author : zxl
+ * @date : 2025-10-10 15:37
+ **/
+@Getter
+@AllArgsConstructor
+public enum TemplateContentTypeEnum {
+    /**
+     * 绫诲瀷
+     */
+    TEXT("鏂囨湰"),
+    IMAGE("鍥剧墖");
+    private final String description;
+}
diff --git a/framework/src/main/java/cn/lili/modules/lmk/service/GoodsCustomizeTemplateService.java b/framework/src/main/java/cn/lili/modules/lmk/service/GoodsCustomizeTemplateService.java
index d163c27..168d6ac 100644
--- a/framework/src/main/java/cn/lili/modules/lmk/service/GoodsCustomizeTemplateService.java
+++ b/framework/src/main/java/cn/lili/modules/lmk/service/GoodsCustomizeTemplateService.java
@@ -62,4 +62,6 @@
      * @return
      */
     Result all();
+
+    Result changeStatus(String id);
 }
diff --git a/framework/src/main/java/cn/lili/modules/lmk/service/impl/GoodsCustomizeTemplateServiceImpl.java b/framework/src/main/java/cn/lili/modules/lmk/service/impl/GoodsCustomizeTemplateServiceImpl.java
index 7a9c203..f5b3a18 100644
--- a/framework/src/main/java/cn/lili/modules/lmk/service/impl/GoodsCustomizeTemplateServiceImpl.java
+++ b/framework/src/main/java/cn/lili/modules/lmk/service/impl/GoodsCustomizeTemplateServiceImpl.java
@@ -1,10 +1,18 @@
 package cn.lili.modules.lmk.service.impl;
 
+import cn.lili.modules.lmk.domain.entity.TemplateConstomizeTitle;
+import cn.lili.modules.lmk.domain.entity.TemplateImgs;
+import cn.lili.modules.lmk.enums.general.EnableStatusEnums;
+import cn.lili.modules.lmk.service.TemplateConstomizeTitleService;
+import cn.lili.modules.lmk.service.TemplateImgsService;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import cn.lili.modules.lmk.domain.entity.GoodsCustomizeTemplate;
 import cn.lili.modules.lmk.mapper.GoodsCustomizeTemplateMapper;
 import cn.lili.modules.lmk.service.GoodsCustomizeTemplateService;
 import cn.lili.base.Result;
+import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
+import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import cn.lili.modules.lmk.domain.form.GoodsCustomizeTemplateForm;
 import cn.lili.modules.lmk.domain.vo.GoodsCustomizeTemplateVO;
@@ -13,6 +21,7 @@
 import lombok.RequiredArgsConstructor;
 import cn.lili.utils.PageUtil;
 import org.springframework.beans.BeanUtils;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.Assert;
 
 import java.util.List;
@@ -30,15 +39,32 @@
 
     private final GoodsCustomizeTemplateMapper goodsCustomizeTemplateMapper;
 
+    private final TemplateImgsService templateImgsService;
+    private final TemplateConstomizeTitleService templateConstomizeTitleService;
     /**
      * 娣诲姞
      * @param form
      * @return
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public Result add(GoodsCustomizeTemplateForm form) {
         GoodsCustomizeTemplate entity = GoodsCustomizeTemplateForm.getEntityByForm(form, null);
+        entity.setStatus(EnableStatusEnums.ENABLE.name());
         baseMapper.insert(entity);
+
+        String templateId = entity.getId();
+
+        List<TemplateImgs> listImages = form.getListImages();
+        for (TemplateImgs templateImgs : listImages) {
+            templateImgs.setTemplateId(templateId);
+        }
+        List<TemplateConstomizeTitle> titles = form.getTitles();
+        for (TemplateConstomizeTitle title : titles) {
+            title.setTemplateId(templateId);
+        }
+        templateImgsService.saveBatch(listImages);
+        templateConstomizeTitleService.saveBatch(titles);
         return Result.ok("娣诲姞鎴愬姛");
     }
 
@@ -48,12 +74,47 @@
      * @return
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public Result update(GoodsCustomizeTemplateForm form) {
         GoodsCustomizeTemplate entity = baseMapper.selectById(form.getId());
-
         // 涓虹┖鎶汭llegalArgumentException锛屽仛鍏ㄥ眬寮傚父澶勭悊
         Assert.notNull(entity, "璁板綍涓嶅瓨鍦�");
         BeanUtils.copyProperties(form, entity);
+
+        //鍏堝垹闄や箣鍓嶇殑妯℃澘淇℃伅鐒跺悗娣诲姞鏂颁俊鎭�
+        List<TemplateImgs> templateImgsList = new LambdaQueryChainWrapper<>(templateImgsService.getBaseMapper())
+                .eq(TemplateImgs::getTemplateId, entity.getId())
+                .eq(TemplateImgs::getDeleteFlag, Boolean.FALSE)
+                .list();
+
+        List<String> imgIds = templateImgsList.stream()
+                .map(TemplateImgs::getId)
+                .collect(Collectors.toList());
+
+        List<TemplateConstomizeTitle> templateConstomizeTitleList = new LambdaQueryChainWrapper<>(templateConstomizeTitleService.getBaseMapper())
+                .eq(TemplateConstomizeTitle::getTemplateId, entity.getId())
+                .eq(TemplateConstomizeTitle::getDeleteFlag, Boolean.FALSE)
+                .list();
+
+        List<String> titleIds = templateConstomizeTitleList.stream()
+                .map(TemplateConstomizeTitle::getId)
+                .collect(Collectors.toList());
+
+
+        templateImgsService.removeBatchByIds(imgIds);
+        templateConstomizeTitleService.removeBatchByIds(titleIds);
+        List<TemplateImgs> listImages = form.getListImages();
+        for (TemplateImgs templateImgs : listImages) {
+            templateImgs.setTemplateId(entity.getId());
+        }
+        List<TemplateConstomizeTitle> titles = form.getTitles();
+        for (TemplateConstomizeTitle title : titles) {
+            title.setTemplateId(entity.getId());
+        }
+        templateImgsService.saveBatch(listImages);
+        templateConstomizeTitleService.saveBatch(titles);
+
+
         baseMapper.updateById(entity);
         return Result.ok("淇敼鎴愬姛");
     }
@@ -75,8 +136,32 @@
      * @return
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public Result removeById(String id) {
+        List<TemplateImgs> templateImgsList = new LambdaQueryChainWrapper<>(templateImgsService.getBaseMapper())
+                .eq(TemplateImgs::getTemplateId, id)
+                .eq(TemplateImgs::getDeleteFlag, Boolean.FALSE)
+                .list();
+
+        List<String> imgIds = templateImgsList.stream()
+                .map(TemplateImgs::getId)
+                .collect(Collectors.toList());
+
+        List<TemplateConstomizeTitle> templateConstomizeTitleList = new LambdaQueryChainWrapper<>(templateConstomizeTitleService.getBaseMapper())
+                .eq(TemplateConstomizeTitle::getTemplateId, id)
+                .eq(TemplateConstomizeTitle::getDeleteFlag, Boolean.FALSE)
+                .list();
+
+        List<String> titleIds = templateConstomizeTitleList.stream()
+                .map(TemplateConstomizeTitle::getId)
+                .collect(Collectors.toList());
+
+
+        templateImgsService.removeBatchByIds(imgIds);
+        templateConstomizeTitleService.removeBatchByIds(titleIds);
+
         baseMapper.deleteById(id);
+
         return Result.ok("鍒犻櫎鎴愬姛");
     }
 
@@ -101,6 +186,19 @@
     public Result detail(String id) {
         GoodsCustomizeTemplateVO vo = baseMapper.getById(id);
         Assert.notNull(vo, "璁板綍涓嶅瓨鍦�");
+        //鏌ヨ鐩稿叧妯℃澘淇℃伅
+
+        List<TemplateImgs> templateImgsList = new LambdaQueryChainWrapper<>(templateImgsService.getBaseMapper())
+                .eq(TemplateImgs::getTemplateId, id)
+                .eq(TemplateImgs::getDeleteFlag, Boolean.FALSE)
+                .list();
+
+        List<TemplateConstomizeTitle> templateConstomizeTitleList = new LambdaQueryChainWrapper<>(templateConstomizeTitleService.getBaseMapper())
+                .eq(TemplateConstomizeTitle::getTemplateId, id)
+                .eq(TemplateConstomizeTitle::getDeleteFlag, Boolean.FALSE)
+                .list();
+        vo.setListImages(templateImgsList);
+        vo.setTitles(templateConstomizeTitleList);
         return Result.ok().data(vo);
     }
 
@@ -116,4 +214,16 @@
                 .collect(Collectors.toList());
         return Result.ok().data(vos);
     }
+
+    @Override
+    public Result changeStatus(String id) {
+        GoodsCustomizeTemplate goodsCustomizeTemplate = baseMapper.selectById(id);
+        if (EnableStatusEnums.ENABLE.name().equals(goodsCustomizeTemplate.getStatus())){
+            goodsCustomizeTemplate.setStatus(EnableStatusEnums.DISABLE.name());
+        }else{
+            goodsCustomizeTemplate.setStatus(EnableStatusEnums.ENABLE.name());
+        }
+        baseMapper.updateById(goodsCustomizeTemplate);
+        return Result.ok();
+    }
 }
diff --git a/framework/src/main/resources/mapper/lmk/GoodsCustomizeTemplateMapper.xml b/framework/src/main/resources/mapper/lmk/GoodsCustomizeTemplateMapper.xml
index d025c4b..3ea3f8f 100644
--- a/framework/src/main/resources/mapper/lmk/GoodsCustomizeTemplateMapper.xml
+++ b/framework/src/main/resources/mapper/lmk/GoodsCustomizeTemplateMapper.xml
@@ -9,12 +9,6 @@
         <result column="status" property="status" />
     </resultMap>
 
-
-
-
-
-
-
     <select id="getById" resultMap="BaseResultMap">
         SELECT
             LGCT.template_name,
@@ -36,6 +30,12 @@
             lmk_goods_customize_template LGCT
         WHERE
             LGCT.delete_flag = 0
+        <if test="query.templateName != null and query.templateName !=''">
+            AND LGCT.template_name LIKE CONCAT('%',#{query.templateName},'%')
+        </if>
+        <if test="query.status != null and query.status !=''">
+            AND LGCT.status = #{query.status}
+        </if>
     </select>
 
 </mapper>
diff --git a/framework/src/main/resources/mapper/lmk/VideoMapper.xml b/framework/src/main/resources/mapper/lmk/VideoMapper.xml
index b6dc81b..dc56251 100644
--- a/framework/src/main/resources/mapper/lmk/VideoMapper.xml
+++ b/framework/src/main/resources/mapper/lmk/VideoMapper.xml
@@ -336,6 +336,7 @@
           AND LV.video_type = #{query.videoType}
           AND LM.id IS NOT NULL
         ORDER BY
+            recommend DESC,
             create_time DESC
     </select>
     <select id="recommendVideoByVideoId" resultMap="WxResultMap">
diff --git a/seller-api/src/main/java/cn/lili/controller/template/GoodsCustomizeTemplateController.java b/seller-api/src/main/java/cn/lili/controller/template/GoodsCustomizeTemplateController.java
new file mode 100644
index 0000000..0d3eccb
--- /dev/null
+++ b/seller-api/src/main/java/cn/lili/controller/template/GoodsCustomizeTemplateController.java
@@ -0,0 +1,55 @@
+package cn.lili.controller.template;
+
+
+import cn.lili.base.Result;
+import cn.lili.modules.lmk.domain.entity.GoodsCustomizeTemplate;
+import cn.lili.modules.lmk.domain.form.GoodsCustomizeTemplateForm;
+import cn.lili.modules.lmk.domain.query.GoodsCustomizeTemplateQuery;
+import cn.lili.modules.lmk.service.GoodsCustomizeTemplateService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.security.core.parameters.P;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * lmk-shop-java
+ * 瀹氬埗鍟嗗搧妯℃澘
+ * @author : zxl
+ * @date : 2025-10-10 11:46
+ **/
+@RestController
+@RequiredArgsConstructor
+@RequestMapping("/store/lmk/goodsCustomizeTemplate")
+public class GoodsCustomizeTemplateController {
+
+    private final GoodsCustomizeTemplateService goodsCustomizeTemplateService;
+
+    @GetMapping()
+    public Result getPage(GoodsCustomizeTemplateQuery query){
+        return goodsCustomizeTemplateService.page(query);
+    }
+    @GetMapping("/{id}")
+    public Result getById(@PathVariable String id){
+        return goodsCustomizeTemplateService.detail(id);
+    }
+
+    @PostMapping()
+    public Result add(@RequestBody GoodsCustomizeTemplateForm form){
+        return goodsCustomizeTemplateService.add(form);
+    }
+
+    @PutMapping()
+    public Result edit(@RequestBody GoodsCustomizeTemplateForm form){
+        return goodsCustomizeTemplateService.update(form);
+    }
+
+    @PutMapping("/changeStatus/{id}")
+    public Result changeStatus(@PathVariable String id){
+        return goodsCustomizeTemplateService.changeStatus(id);
+    }
+    @DeleteMapping("/{id}")
+    public Result delete(@PathVariable String id){
+        return goodsCustomizeTemplateService.removeById(id);
+    }
+
+
+}

--
Gitblit v1.8.0