Selaa lähdekoodia

店铺装修相关代码

zyy 3 viikkoa sitten
vanhempi
commit
ffb5aead3e
18 muutettua tiedostoa jossa 818 lisäystä ja 8 poistoa
  1. 49 0
      fs-admin/src/main/java/com/fs/decoration/controller/DecorationCompanyTemplateController.java
  2. 13 1
      fs-admin/src/main/java/com/fs/decoration/controller/DecorationTemplateController.java
  3. 45 0
      fs-company/src/main/java/com/fs/decoration/DecorationCompanyTemplateController.java
  4. 70 0
      fs-company/src/main/java/com/fs/decoration/DecorationComponentController.java
  5. 28 0
      fs-company/src/main/java/com/fs/decoration/DecorationComponentTypeController.java
  6. 53 0
      fs-company/src/main/java/com/fs/decoration/DecorationTemplateController.java
  7. 30 0
      fs-service/src/main/java/com/fs/decoration/domain/DecorationCompanyTemplate.java
  8. 13 0
      fs-service/src/main/java/com/fs/decoration/dto/UseTemplateReq.java
  9. 32 0
      fs-service/src/main/java/com/fs/decoration/mapper/DecorationCompanyTemplateMapper.java
  10. 13 2
      fs-service/src/main/java/com/fs/decoration/mapper/DecorationTemplateMapper.java
  11. 23 0
      fs-service/src/main/java/com/fs/decoration/service/IDecorationCompanyTemplateService.java
  12. 20 1
      fs-service/src/main/java/com/fs/decoration/service/IDecorationTemplateService.java
  13. 107 0
      fs-service/src/main/java/com/fs/decoration/service/impl/DecorationCompanyTemplateServiceImpl.java
  14. 157 1
      fs-service/src/main/java/com/fs/decoration/service/impl/DecorationTemplateServiceImpl.java
  15. 2 2
      fs-service/src/main/java/com/fs/distribution/service/impl/DistributionServiceImpl.java
  16. 88 0
      fs-service/src/main/resources/mapper/decoration/DecorationCompanyTemplateMapper.xml
  17. 19 1
      fs-service/src/main/resources/mapper/decoration/DecorationTemplateMapper.xml
  18. 56 0
      fs-user-app/src/main/java/com/fs/app/controller/DecorationTemplateController.java

+ 49 - 0
fs-admin/src/main/java/com/fs/decoration/controller/DecorationCompanyTemplateController.java

@@ -0,0 +1,49 @@
+package com.fs.decoration.controller;
+
+import com.fs.common.core.domain.AjaxResult;
+import com.fs.common.core.domain.model.LoginUser;
+import com.fs.common.utils.ServletUtils;
+import com.fs.decoration.dto.DecorationComponentQuery;
+import com.fs.decoration.dto.DecorationComponentSaveReq;
+import com.fs.decoration.dto.DecorationComponentStatusReq;
+import com.fs.decoration.dto.UseTemplateReq;
+import com.fs.decoration.service.IDecorationCompanyTemplateService;
+import com.fs.decoration.service.IDecorationComponentService;
+import com.fs.framework.web.service.TokenService;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+
+/**
+ * 公司模板绑定控制器
+ */
+@RestController
+@RequestMapping("/decoration/companyTemplate")
+public class DecorationCompanyTemplateController {
+
+    @Resource
+    private IDecorationCompanyTemplateService companyTemplateService;
+    @Resource
+    private TokenService tokenService;
+
+    /**
+     * 当前登录公司使用某个模板
+     */
+    @PostMapping("/use")
+    public AjaxResult useTemplate(@RequestBody UseTemplateReq req) {
+        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+        companyTemplateService.useTemplate(loginUser.getUser().getCompanyId(), req);
+        return AjaxResult.success("使用成功");
+    }
+
+    /**
+     * 查询当前登录公司某个模板类型正在使用的模板ID
+     */
+    @GetMapping("/current")
+    public AjaxResult current(@RequestParam(defaultValue = "home") String templateType) {
+        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+        Long templateId = companyTemplateService.getCurrentTemplateId(loginUser.getUser().getCompanyId(), templateType);
+
+        return AjaxResult.success(templateId);
+    }
+}

+ 13 - 1
fs-admin/src/main/java/com/fs/decoration/controller/DecorationTemplateController.java

@@ -50,4 +50,16 @@ public class DecorationTemplateController {
         decorationTemplateService.deleteById(id);
         return AjaxResult.success("删除成功");
     }
-}
+
+    /**
+     * 启用模板
+     */
+    @PostMapping("/enable/{id}")
+    public AjaxResult enable(@PathVariable Long id) {
+
+        decorationTemplateService.enableTemplate(id);
+
+        return AjaxResult.success("启用成功");
+    }
+
+}

+ 45 - 0
fs-company/src/main/java/com/fs/decoration/DecorationCompanyTemplateController.java

@@ -0,0 +1,45 @@
+package com.fs.decoration;
+
+import com.fs.common.core.domain.AjaxResult;
+import com.fs.common.utils.ServletUtils;
+import com.fs.decoration.dto.UseTemplateReq;
+import com.fs.decoration.service.IDecorationCompanyTemplateService;
+import com.fs.framework.security.LoginUser;
+import com.fs.framework.service.TokenService;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+
+/**
+ * 公司模板绑定控制器
+ */
+@RestController
+@RequestMapping("/decoration/companyTemplate")
+public class DecorationCompanyTemplateController {
+
+    @Resource
+    private IDecorationCompanyTemplateService companyTemplateService;
+    @Resource
+    private TokenService tokenService;
+
+    /**
+     * 当前登录公司使用某个模板
+     */
+    @PostMapping("/use")
+    public AjaxResult useTemplate(@RequestBody UseTemplateReq req) {
+        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+        companyTemplateService.useTemplate(loginUser.getUser().getCompanyId(), req);
+        return AjaxResult.success("使用成功");
+    }
+
+    /**
+     * 查询当前登录公司某个模板类型正在使用的模板ID
+     */
+    @GetMapping("/current")
+    public AjaxResult current(@RequestParam(defaultValue = "home") String templateType) {
+        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+        Long templateId = companyTemplateService.getCurrentTemplateId(loginUser.getUser().getCompanyId(), templateType);
+
+        return AjaxResult.success(templateId);
+    }
+}

+ 70 - 0
fs-company/src/main/java/com/fs/decoration/DecorationComponentController.java

@@ -0,0 +1,70 @@
+package com.fs.decoration;
+
+import com.fs.common.core.domain.AjaxResult;
+import com.fs.decoration.dto.DecorationComponentQuery;
+import com.fs.decoration.dto.DecorationComponentSaveReq;
+import com.fs.decoration.dto.DecorationComponentStatusReq;
+import com.fs.decoration.service.IDecorationComponentService;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+
+/**
+ * 组件定义控制器
+ */
+@RestController
+@RequestMapping("/decoration/component")
+public class DecorationComponentController {
+
+    @Resource
+    private IDecorationComponentService decorationComponentService;
+
+    /**
+     * 查询组件列表
+     */
+    @GetMapping("/list")
+    public AjaxResult list(DecorationComponentQuery query) {
+        return AjaxResult.success(decorationComponentService.selectList(query));
+    }
+
+    /**
+     * 查询组件详情
+     */
+    @GetMapping("/{id}")
+    public AjaxResult getInfo(@PathVariable Long id) {
+        return AjaxResult.success(decorationComponentService.selectById(id));
+    }
+
+    /**
+     * 新增/修改组件
+     */
+    @PostMapping("/save")
+    public AjaxResult save(@RequestBody DecorationComponentSaveReq req) {
+        Long id = decorationComponentService.saveComponent(req);
+        return AjaxResult.success("保存成功", id);
+    }
+
+    /**
+     * 删除组件
+     */
+    @DeleteMapping("/{id}")
+    public AjaxResult remove(@PathVariable Long id) {
+        decorationComponentService.deleteById(id);
+        return AjaxResult.success("删除成功");
+    }
+
+    /**
+     * 修改组件状态
+     */
+    @PostMapping("/changeStatus")
+    public AjaxResult changeStatus(@RequestBody DecorationComponentStatusReq req) {
+        if (req.getId() == null) {
+            return AjaxResult.error("组件ID不能为空");
+        }
+        if (req.getStatus() == null) {
+            return AjaxResult.error("状态不能为空");
+        }
+        decorationComponentService.updateStatus(req.getId(), req.getStatus());
+        return AjaxResult.success("状态修改成功");
+    }
+}

+ 28 - 0
fs-company/src/main/java/com/fs/decoration/DecorationComponentTypeController.java

@@ -0,0 +1,28 @@
+package com.fs.decoration;
+
+import com.fs.common.core.domain.AjaxResult;
+import com.fs.decoration.service.IDecorationComponentTypeService;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+
+/**
+ * 组件类型控制器
+ */
+@RestController
+@RequestMapping("/decoration/componentType")
+public class DecorationComponentTypeController {
+
+    @Resource
+    private IDecorationComponentTypeService decorationComponentTypeService;
+
+    /**
+     * 查询组件类型下拉
+     */
+    @GetMapping("/options")
+    public AjaxResult options() {
+        return AjaxResult.success(decorationComponentTypeService.listOptions());
+    }
+}

+ 53 - 0
fs-company/src/main/java/com/fs/decoration/DecorationTemplateController.java

@@ -0,0 +1,53 @@
+package com.fs.decoration;
+
+import com.fs.common.core.domain.AjaxResult;
+import com.fs.decoration.dto.DecorationTemplateSaveReq;
+import com.fs.decoration.service.IDecorationTemplateService;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+
+/**
+ * 模板控制器
+ */
+@RestController
+@RequestMapping("/decoration/template")
+public class DecorationTemplateController {
+
+    @Resource
+    private IDecorationTemplateService decorationTemplateService;
+
+    /**
+     * 查询模板列表
+     */
+    @GetMapping("/list")
+    public AjaxResult list() {
+        return AjaxResult.success(decorationTemplateService.selectList());
+    }
+
+    /**
+     * 查询模板详情
+     */
+    @GetMapping("/{id}")
+    public AjaxResult getInfo(@PathVariable Long id) {
+        return AjaxResult.success(decorationTemplateService.selectById(id));
+    }
+
+    /**
+     * 新增/修改模板
+     */
+    @PostMapping("/save")
+    public AjaxResult save(@RequestBody DecorationTemplateSaveReq req) {
+        Long id = decorationTemplateService.saveTemplate(req);
+        return AjaxResult.success("保存成功", id);
+    }
+
+    /**
+     * 删除模板
+     */
+    @DeleteMapping("/{id}")
+    public AjaxResult remove(@PathVariable Long id) {
+        decorationTemplateService.deleteById(id);
+        return AjaxResult.success("删除成功");
+    }
+}

+ 30 - 0
fs-service/src/main/java/com/fs/decoration/domain/DecorationCompanyTemplate.java

@@ -0,0 +1,30 @@
+package com.fs.decoration.domain;
+
+import lombok.Data;
+import java.util.Date;
+
+/**
+ * 公司模板绑定表
+ */
+@Data
+public class DecorationCompanyTemplate {
+
+    /** 主键ID */
+    private Long id;
+
+    /** 公司ID */
+    private Long companyId;
+
+    /** 模板ID */
+    private Long templateId;
+
+    /** 页面类型 home首页 activity活动 */
+    private String templateType;
+
+    /** 状态 1启用 0停用 */
+    private Integer status;
+
+    private Date createTime;
+
+    private Date updateTime;
+}

+ 13 - 0
fs-service/src/main/java/com/fs/decoration/dto/UseTemplateReq.java

@@ -0,0 +1,13 @@
+package com.fs.decoration.dto;
+
+import lombok.Data;
+
+/**
+ * 使用模板请求
+ */
+@Data
+public class UseTemplateReq {
+
+    /** 模板ID */
+    private Long templateId;
+}

+ 32 - 0
fs-service/src/main/java/com/fs/decoration/mapper/DecorationCompanyTemplateMapper.java

@@ -0,0 +1,32 @@
+package com.fs.decoration.mapper;
+
+import com.fs.decoration.domain.DecorationCompanyTemplate;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 模板 Mapper
+ */
+public interface DecorationCompanyTemplateMapper {
+
+    /**
+     * 根据公司ID和页面类型查询启用模板绑定
+     */
+    DecorationCompanyTemplate selectByCompanyAndTemplateType(
+            @Param("companyId") Long companyId,
+            @Param("pageType") String pageType
+    );
+
+    DecorationCompanyTemplate selectByTemplateType(@Param("pageType") String pageType);
+
+    /**
+     * 新增绑定
+     */
+    int insert(DecorationCompanyTemplate entity);
+
+    /**
+     * 修改绑定
+     */
+    int updateById(DecorationCompanyTemplate entity);
+}

+ 13 - 2
fs-service/src/main/java/com/fs/decoration/mapper/DecorationTemplateMapper.java

@@ -1,5 +1,6 @@
 package com.fs.decoration.mapper;
 
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.fs.decoration.domain.DecorationTemplate;
 import org.apache.ibatis.annotations.Param;
 
@@ -8,7 +9,7 @@ import java.util.List;
 /**
  * 模板 Mapper
  */
-public interface DecorationTemplateMapper {
+public interface DecorationTemplateMapper extends BaseMapper<DecorationTemplate> {
 
     /**
      * 查询模板列表
@@ -34,4 +35,14 @@ public interface DecorationTemplateMapper {
      * 删除模板
      */
     int deleteById(@Param("id") Long id);
-}
+
+    /**
+     * 关闭同类型模板
+     */
+    int disableByTemplateType(@Param("templateType") String templateType);
+
+    /**
+     * 启用模板
+     */
+    int enableTemplate(@Param("id") Long id);
+}

+ 23 - 0
fs-service/src/main/java/com/fs/decoration/service/IDecorationCompanyTemplateService.java

@@ -0,0 +1,23 @@
+package com.fs.decoration.service;
+
+import com.fs.decoration.dto.UseTemplateReq;
+
+import java.util.List;
+
+/**
+ * 公司模板绑定 Service
+ */
+public interface IDecorationCompanyTemplateService {
+
+    /**
+     * 当前公司使用某个模板
+     */
+    void useTemplate(Long companyId, UseTemplateReq req);
+
+    /**
+     * 查询当前公司某个类型正在使用的模板ID
+     */
+    Long getCurrentTemplateId(Long companyId, String templateType);
+
+
+}

+ 20 - 1
fs-service/src/main/java/com/fs/decoration/service/IDecorationTemplateService.java

@@ -1,5 +1,6 @@
 package com.fs.decoration.service;
 
+import com.alibaba.fastjson.JSONObject;
 import com.fs.decoration.domain.DecorationTemplate;
 import com.fs.decoration.dto.DecorationTemplateSaveReq;
 
@@ -29,4 +30,22 @@ public interface IDecorationTemplateService {
      * 删除模板
      */
     int deleteById(Long id);
-}
+
+    /**
+     * 根据公司ID和页面类型查询运行态模板(目前未绑定到对应公司,还未启用)
+     */
+    JSONObject getCompanyRuntimeTemplate(Long companyId, String pageType);
+
+    /**
+     * 查询启用的模版
+     */
+    JSONObject getRuntimeTemplate(String pageType);
+
+    /**
+     * 启用模板
+     */
+    void enableTemplate(Long id);
+
+
+
+}

+ 107 - 0
fs-service/src/main/java/com/fs/decoration/service/impl/DecorationCompanyTemplateServiceImpl.java

@@ -0,0 +1,107 @@
+package com.fs.decoration.service.impl;
+
+import com.fs.decoration.domain.DecorationCompanyTemplate;
+import com.fs.decoration.domain.DecorationTemplate;
+import com.fs.decoration.dto.UseTemplateReq;
+import com.fs.decoration.mapper.DecorationCompanyTemplateMapper;
+import com.fs.decoration.mapper.DecorationTemplateMapper;
+import com.fs.decoration.service.IDecorationCompanyTemplateService;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+
+/**
+ * 公司模板绑定 Service 实现
+ */
+@Service
+public class DecorationCompanyTemplateServiceImpl implements IDecorationCompanyTemplateService {
+
+    @Resource
+    private DecorationCompanyTemplateMapper companyTemplateMapper;
+
+    @Resource
+    private DecorationTemplateMapper templateMapper;
+
+    /**
+     * 当前公司使用某个模板
+     *
+     * 逻辑:
+     * 1. 根据 templateId 查询模板
+     * 2. 获取模板类型 templateType
+     * 3. 查询当前 companyId + templateType 是否已绑定
+     * 4. 已绑定则更新
+     * 5. 未绑定则新增
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void useTemplate(Long companyId, UseTemplateReq req) {
+        if (companyId == null) {
+            throw new RuntimeException("当前登录账号未绑定公司");
+        }
+
+        if (req == null || req.getTemplateId() == null) {
+            throw new RuntimeException("模板ID不能为空");
+        }
+
+        DecorationTemplate template = templateMapper.selectById(req.getTemplateId());
+        if (template == null) {
+            throw new RuntimeException("模板不存在");
+        }
+
+        if (template.getStatus() == null || template.getStatus() != 1) {
+            throw new RuntimeException("模板未启用");
+        }
+
+        String templateType = template.getTemplateType();
+        if (templateType == null || templateType.trim().isEmpty()) {
+            throw new RuntimeException("模板类型不能为空");
+        }
+
+        DecorationCompanyTemplate old = companyTemplateMapper.selectByCompanyAndTemplateType(
+                companyId,
+                templateType
+        );
+
+        if (old == null) {
+            DecorationCompanyTemplate entity = new DecorationCompanyTemplate();
+            entity.setCompanyId(companyId);
+            entity.setTemplateId(req.getTemplateId());
+            entity.setTemplateType(templateType);
+            entity.setStatus(1);
+
+            companyTemplateMapper.insert(entity);
+        } else {
+            old.setTemplateId(req.getTemplateId());
+            old.setTemplateType(templateType);
+            old.setStatus(1);
+
+            companyTemplateMapper.updateById(old);
+        }
+    }
+
+    /**
+     * 查询当前公司某个模板类型正在使用的模板ID
+     */
+    @Override
+    public Long getCurrentTemplateId(Long companyId, String templateType) {
+        if (companyId == null) {
+            return null;
+        }
+
+        if (templateType == null || templateType.trim().isEmpty()) {
+            templateType = "home";
+        }
+
+        DecorationCompanyTemplate bind = companyTemplateMapper.selectByCompanyAndTemplateType(
+                companyId,
+                templateType
+        );
+
+        if (bind == null || bind.getStatus() == null || bind.getStatus() != 1) {
+            return null;
+        }
+
+        return bind.getTemplateId();
+    }
+}

+ 157 - 1
fs-service/src/main/java/com/fs/decoration/service/impl/DecorationTemplateServiceImpl.java

@@ -1,8 +1,14 @@
 package com.fs.decoration.service.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fs.decoration.domain.DecorationCompanyTemplate;
 import com.fs.decoration.domain.DecorationTemplate;
 import com.fs.decoration.dto.DecorationTemplateSaveReq;
+import com.fs.decoration.mapper.DecorationCompanyTemplateMapper;
 import com.fs.decoration.mapper.DecorationTemplateMapper;
 import com.fs.decoration.service.IDecorationTemplateService;
 import com.fs.decoration.vo.TemplateContentVO;
@@ -21,6 +27,9 @@ public class DecorationTemplateServiceImpl implements IDecorationTemplateService
     @Resource
     private DecorationTemplateMapper decorationTemplateMapper;
 
+    @Resource
+    private DecorationCompanyTemplateMapper decorationCompanyTemplateMapper;
+
     /** 用于校验 templateData JSON 结构 */
     private final ObjectMapper objectMapper = new ObjectMapper();
 
@@ -92,4 +101,151 @@ public class DecorationTemplateServiceImpl implements IDecorationTemplateService
             throw new RuntimeException("模板JSON格式错误:" + e.getMessage());
         }
     }
-}
+
+
+    /**
+     * 根据公司ID和页面类型查询运行态模板
+     * 返回给前端时过滤掉组件实例ID
+     */
+    @Override
+    public JSONObject getCompanyRuntimeTemplate(Long companyId, String pageType) {
+        if (companyId == null) {
+            throw new RuntimeException("公司ID不能为空");
+        }
+        if (pageType == null || pageType.trim().isEmpty()) {
+            pageType = "home";
+        }
+
+        // 1. 查询公司绑定的模板
+        DecorationCompanyTemplate bind =
+                decorationCompanyTemplateMapper.selectByCompanyAndTemplateType(companyId, pageType);
+
+        if (bind == null) {
+            throw new RuntimeException("当前公司未绑定模板");
+        }
+
+        // 2. 查询模板详情
+        DecorationTemplate template = decorationTemplateMapper.selectById(bind.getTemplateId());
+
+        if (template == null) {
+            throw new RuntimeException("模板不存在");
+        }
+
+        if (template.getStatus() == null || template.getStatus() != 1) {
+            throw new RuntimeException("模板未启用");
+        }
+
+        // 3. 解析模板JSON
+        JSONObject sourceJson = JSON.parseObject(template.getTemplateData());
+
+        JSONObject pageConfig = sourceJson.getJSONObject("pageConfig");
+        JSONArray sourceComponents = sourceJson.getJSONArray("components");
+
+        JSONArray targetComponents = new JSONArray();
+
+        if (sourceComponents != null) {
+            for (int i = 0; i < sourceComponents.size(); i++) {
+                JSONObject sourceItem = sourceComponents.getJSONObject(i);
+
+                JSONObject targetItem = new JSONObject();
+
+                // 只返回前端运行需要的字段,不返回 id
+                targetItem.put("componentCode", sourceItem.getString("componentCode"));
+
+                // props 可能为空,给默认 {}
+                JSONObject props = sourceItem.getJSONObject("props");
+                targetItem.put("props", props == null ? new JSONObject() : props);
+
+                targetComponents.add(targetItem);
+            }
+        }
+
+        // 4. 组装返回
+        JSONObject result = new JSONObject();
+        result.put("pageConfig", pageConfig == null ? new JSONObject() : pageConfig);
+        result.put("components", targetComponents);
+
+        return result;
+    }
+
+
+    @Override
+    public JSONObject getRuntimeTemplate(String pageType) {
+        if (pageType == null || pageType.trim().isEmpty()) {
+            pageType = "home";
+        }
+
+        // 1. 查询启用的模板
+        DecorationTemplate template = decorationTemplateMapper.selectOne(new LambdaQueryWrapper<DecorationTemplate>().eq(DecorationTemplate::getStatus, 1)
+                .eq(DecorationTemplate::getTemplateType, pageType));
+
+        if (template == null) {
+            throw new RuntimeException("未找到启用的模板");
+        }
+
+        // 3. 解析模板JSON
+        JSONObject sourceJson = JSON.parseObject(template.getTemplateData());
+
+        JSONObject pageConfig = sourceJson.getJSONObject("pageConfig");
+        JSONArray sourceComponents = sourceJson.getJSONArray("components");
+
+        JSONArray targetComponents = new JSONArray();
+
+        if (sourceComponents != null) {
+            for (int i = 0; i < sourceComponents.size(); i++) {
+                JSONObject sourceItem = sourceComponents.getJSONObject(i);
+
+                JSONObject targetItem = new JSONObject();
+
+                // 只返回前端运行需要的字段,不返回 id
+                targetItem.put("componentCode", sourceItem.getString("componentCode"));
+
+                // props 可能为空,给默认 {}
+                JSONObject props = sourceItem.getJSONObject("props");
+                targetItem.put("props", props == null ? new JSONObject() : props);
+
+                targetComponents.add(targetItem);
+            }
+        }
+
+        // 4. 组装返回
+        JSONObject result = new JSONObject();
+        result.put("pageConfig", pageConfig == null ? new JSONObject() : pageConfig);
+        result.put("components", targetComponents);
+
+        return result;
+    }
+
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void enableTemplate(Long id) {
+
+        if (id == null) {
+            throw new RuntimeException("模板ID不能为空");
+        }
+
+        DecorationTemplate template = decorationTemplateMapper.selectById(id);
+
+        if (template == null) {
+            throw new RuntimeException("模板不存在");
+        }
+
+        String templateType =
+                template.getTemplateType();
+
+        if (templateType == null) {
+            throw new RuntimeException("模板类型不能为空");
+        }
+
+        /**
+         * 先关闭同类型模板
+         */
+        decorationTemplateMapper.disableByTemplateType(templateType);
+
+        /**
+         * 再启用当前模板
+         */
+        decorationTemplateMapper.enableTemplate(id);
+    }
+}

+ 2 - 2
fs-service/src/main/java/com/fs/distribution/service/impl/DistributionServiceImpl.java

@@ -109,7 +109,7 @@ public class DistributionServiceImpl implements DistributionService {
     }
 
     /**
-     * 订单支付成功后生成佣金
+     * 订单完成后生成佣金
      *
      * 注意:
      * 1. 必须幂等,同一个订单不能重复生成佣金
@@ -576,4 +576,4 @@ public class DistributionServiceImpl implements DistributionService {
         }
         return queryDistributionAccountResponse;
     }
-}
+}

+ 88 - 0
fs-service/src/main/resources/mapper/decoration/DecorationCompanyTemplateMapper.xml

@@ -0,0 +1,88 @@
+<?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.fs.decoration.mapper.DecorationCompanyTemplateMapper">
+
+    <resultMap id="DecorationCompanyTemplateResultMap"
+               type="com.fs.decoration.domain.DecorationCompanyTemplate">
+        <id property="id" column="id"/>
+        <result property="companyId" column="company_id"/>
+        <result property="templateId" column="template_id"/>
+        <result property="templateType" column="template_type"/>
+        <result property="status" column="status"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateTime" column="update_time"/>
+    </resultMap>
+
+    <select id="selectByCompanyAndTemplateType"
+            resultMap="DecorationCompanyTemplateResultMap">
+        select
+            id,
+            company_id,
+            template_id,
+            template_type,
+            status,
+            create_time,
+            update_time
+        from decoration_company_template
+        where company_id = #{companyId}
+          and template_type = #{pageType}
+          and status = 1
+            limit 1
+    </select>
+    <select id="selectByTemplateType" resultType="com.fs.decoration.domain.DecorationCompanyTemplate">
+        select
+            id,
+            company_id,
+            template_id,
+            template_type,
+            status,
+            create_time,
+            update_time
+        from decoration_company_template
+        where template_type = #{pageType}
+          and status = 1
+            limit 1
+    </select>
+
+
+    <!-- 新增绑定 -->
+    <insert id="insert" useGeneratedKeys="true" keyProperty="id">
+        insert into decoration_company_template (
+            company_id,
+            template_id,
+            template_type,
+            status,
+            create_time,
+            update_time
+        ) values (
+                     #{companyId},
+                     #{templateId},
+                     #{templateType},
+                     #{status},
+                     now(),
+                     now()
+                 )
+    </insert>
+
+    <!-- 修改绑定 -->
+    <update id="updateById">
+        update decoration_company_template
+        <set>
+            <if test="templateId != null">
+                template_id = #{templateId},
+            </if>
+            <if test="templateType != null">
+                template_type = #{templateType},
+            </if>
+            <if test="status != null">
+                status = #{status},
+            </if>
+            update_time = now()
+        </set>
+        where id = #{id}
+    </update>
+
+</mapper>

+ 19 - 1
fs-service/src/main/resources/mapper/decoration/DecorationTemplateMapper.xml

@@ -82,9 +82,27 @@
         where id = #{id}
     </update>
 
+    <!-- 关闭同类型模板 -->
+    <update id="disableByTemplateType">
+
+        update decoration_template
+        set status = 0
+
+        where template_type = #{templateType}
+
+    </update>
+
+    <!-- 启用模板 -->
+    <update id="enableTemplate">
+        update decoration_template
+        set status = 1
+        where id = #{id}
+
+    </update>
+
     <delete id="deleteById">
         delete from decoration_template
         where id = #{id}
     </delete>
 
-</mapper>
+</mapper>

+ 56 - 0
fs-user-app/src/main/java/com/fs/app/controller/DecorationTemplateController.java

@@ -0,0 +1,56 @@
+package com.fs.app.controller;
+
+
+import com.fs.app.utils.JwtUtils;
+import com.fs.common.core.domain.AjaxResult;
+import com.fs.common.core.domain.R;
+import com.fs.decoration.service.IDecorationTemplateService;
+import com.fs.his.domain.FsAdv;
+import com.fs.his.domain.FsUser;
+import com.fs.his.param.FsAdvUParam;
+import com.fs.his.service.IFsAdvService;
+import com.fs.his.service.IFsUserService;
+import com.fs.hisStore.vo.FsAdvListQueryVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.List;
+
+
+/**
+ * 店铺装修模板接口
+ */
+@RestController
+@RequestMapping("/store/decoration/template")
+public class DecorationTemplateController extends AppBaseController {
+
+	@Autowired
+	private IDecorationTemplateService decorationTemplateService;
+	@Autowired
+	private IFsUserService userService;
+
+	/**
+	 * 根据公司ID查询运行态模板
+	 */
+	@GetMapping("/runtime/company")
+	public R getCompanyRuntimeTemplate(@RequestParam(defaultValue = "home") String pageType) {
+		long userId = Long.parseLong(getUserId());
+		FsUser fsUser = userService.selectFsUserById(userId);
+		return R.ok().put("data",decorationTemplateService.getCompanyRuntimeTemplate(fsUser.getCompanyId(), pageType));
+	}
+
+
+	/**
+	 * 查询启用的模板
+	 */
+	@GetMapping("/runtime")
+	public R getRuntimeTemplate(@RequestParam(defaultValue = "home") String pageType) {
+		return R.ok().put("data",decorationTemplateService.getRuntimeTemplate(pageType));
+	}
+
+
+}