feat: 新增文案模板管理功能,源码明细页按钮支持动态配置

- 新增 tt_copy_template 表及 CRUD 后端接口
- 新增文案模板管理页面,支持 {变量} 占位符动态替换
- 源码明细页复制按钮由硬编码改为数据库驱动
- 支持占位符:codeName、projectCode、projectName、codeDesc、codeEnvironment、codeTechnology、diskLink、screenshots

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
王鹏
2026-04-10 19:20:32 +08:00
parent 5e7bbe6c9d
commit 6940541216
10 changed files with 1033 additions and 343 deletions

View File

@@ -0,0 +1,106 @@
package com.ruoyi.office.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.office.domain.TtCopyTemplate;
import com.ruoyi.office.service.ITtCopyTemplateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
* 文案模板Controller
*
* @author ruoyi
* @date 2026-04-10
*/
@RestController
@RequestMapping("/office/copyTemplate")
public class TtCopyTemplateController extends BaseController {
@Autowired
private ITtCopyTemplateService ttCopyTemplateService;
/**
* 查询文案模板列表
*/
@PreAuthorize("@ss.hasPermi('office:copyTemplate:list')")
@GetMapping("/list")
public TableDataInfo list(TtCopyTemplate ttCopyTemplate) {
startPage();
List<TtCopyTemplate> list = ttCopyTemplateService.selectTtCopyTemplateList(ttCopyTemplate);
return getDataTable(list);
}
/**
* 查询所有启用的文案模板(供源码明细页动态按钮使用,无需分页权限)
*/
@GetMapping("/enabled")
public AjaxResult listEnabled() {
return success(ttCopyTemplateService.selectEnabledTemplates());
}
/**
* 导出文案模板列表
*/
@PreAuthorize("@ss.hasPermi('office:copyTemplate:export')")
@Log(title = "文案模板", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, TtCopyTemplate ttCopyTemplate) {
List<TtCopyTemplate> list = ttCopyTemplateService.selectTtCopyTemplateList(ttCopyTemplate);
ExcelUtil<TtCopyTemplate> util = new ExcelUtil<TtCopyTemplate>(TtCopyTemplate.class);
util.exportExcel(response, list, "文案模板数据");
}
/**
* 获取文案模板详细信息
*/
@PreAuthorize("@ss.hasPermi('office:copyTemplate:query')")
@GetMapping(value = "/{templateId}")
public AjaxResult getInfo(@PathVariable("templateId") Long templateId) {
return success(ttCopyTemplateService.selectTtCopyTemplateByTemplateId(templateId));
}
/**
* 新增文案模板
*/
@PreAuthorize("@ss.hasPermi('office:copyTemplate:add')")
@Log(title = "文案模板", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody TtCopyTemplate ttCopyTemplate) {
return toAjax(ttCopyTemplateService.insertTtCopyTemplate(ttCopyTemplate));
}
/**
* 修改文案模板
*/
@PreAuthorize("@ss.hasPermi('office:copyTemplate:edit')")
@Log(title = "文案模板", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody TtCopyTemplate ttCopyTemplate) {
return toAjax(ttCopyTemplateService.updateTtCopyTemplate(ttCopyTemplate));
}
/**
* 删除文案模板
*/
@PreAuthorize("@ss.hasPermi('office:copyTemplate:remove')")
@Log(title = "文案模板", businessType = BusinessType.DELETE)
@DeleteMapping("/{templateIds}")
public AjaxResult remove(@PathVariable Long[] templateIds) {
return toAjax(ttCopyTemplateService.deleteTtCopyTemplateByTemplateIds(templateIds));
}
}

View File

@@ -0,0 +1,88 @@
package com.ruoyi.office.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
/**
* 文案模板对象 tt_copy_template
*
* @author ruoyi
* @date 2026-04-10
*/
public class TtCopyTemplate extends BaseEntity {
private static final long serialVersionUID = 1L;
/** 模板ID */
private Long templateId;
/** 按钮显示名称 */
@Excel(name = "按钮名称")
private String templateName;
/** 文案模板内容,支持 {变量} 占位符 */
@Excel(name = "模板内容")
private String templateBody;
/** 排序号 */
@Excel(name = "排序")
private Integer sortNum;
/** 状态0正常 1停用 */
@Excel(name = "状态")
private String status;
public void setTemplateId(Long templateId) {
this.templateId = templateId;
}
public Long getTemplateId() {
return templateId;
}
public void setTemplateName(String templateName) {
this.templateName = templateName;
}
public String getTemplateName() {
return templateName;
}
public void setTemplateBody(String templateBody) {
this.templateBody = templateBody;
}
public String getTemplateBody() {
return templateBody;
}
public void setSortNum(Integer sortNum) {
this.sortNum = sortNum;
}
public Integer getSortNum() {
return sortNum;
}
public void setStatus(String status) {
this.status = status;
}
public String getStatus() {
return status;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("templateId", getTemplateId())
.append("templateName", getTemplateName())
.append("templateBody", getTemplateBody())
.append("sortNum", getSortNum())
.append("status", getStatus())
.append("createTime", getCreateTime())
.append("updateTime", getUpdateTime())
.toString();
}
}

View File

@@ -0,0 +1,48 @@
package com.ruoyi.office.mapper;
import java.util.List;
import com.ruoyi.office.domain.TtCopyTemplate;
/**
* 文案模板Mapper接口
*
* @author ruoyi
* @date 2026-04-10
*/
public interface TtCopyTemplateMapper {
/**
* 查询文案模板
*/
public TtCopyTemplate selectTtCopyTemplateByTemplateId(Long templateId);
/**
* 查询文案模板列表
*/
public List<TtCopyTemplate> selectTtCopyTemplateList(TtCopyTemplate ttCopyTemplate);
/**
* 查询所有启用的文案模板(按排序号升序)
*/
public List<TtCopyTemplate> selectEnabledTemplates();
/**
* 新增文案模板
*/
public int insertTtCopyTemplate(TtCopyTemplate ttCopyTemplate);
/**
* 修改文案模板
*/
public int updateTtCopyTemplate(TtCopyTemplate ttCopyTemplate);
/**
* 批量删除文案模板
*/
public int deleteTtCopyTemplateByTemplateIds(Long[] templateIds);
/**
* 删除文案模板信息
*/
public int deleteTtCopyTemplateByTemplateId(Long templateId);
}

View File

@@ -0,0 +1,48 @@
package com.ruoyi.office.service;
import java.util.List;
import com.ruoyi.office.domain.TtCopyTemplate;
/**
* 文案模板Service接口
*
* @author ruoyi
* @date 2026-04-10
*/
public interface ITtCopyTemplateService {
/**
* 查询文案模板
*/
public TtCopyTemplate selectTtCopyTemplateByTemplateId(Long templateId);
/**
* 查询文案模板列表(带分页、筛选)
*/
public List<TtCopyTemplate> selectTtCopyTemplateList(TtCopyTemplate ttCopyTemplate);
/**
* 查询所有启用的文案模板(供源码明细页按钮使用)
*/
public List<TtCopyTemplate> selectEnabledTemplates();
/**
* 新增文案模板
*/
public int insertTtCopyTemplate(TtCopyTemplate ttCopyTemplate);
/**
* 修改文案模板
*/
public int updateTtCopyTemplate(TtCopyTemplate ttCopyTemplate);
/**
* 批量删除文案模板
*/
public int deleteTtCopyTemplateByTemplateIds(Long[] templateIds);
/**
* 删除文案模板信息
*/
public int deleteTtCopyTemplateByTemplateId(Long templateId);
}

View File

@@ -0,0 +1,59 @@
package com.ruoyi.office.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.office.domain.TtCopyTemplate;
import com.ruoyi.office.mapper.TtCopyTemplateMapper;
import com.ruoyi.office.service.ITtCopyTemplateService;
/**
* 文案模板Service业务层处理
*
* @author ruoyi
* @date 2026-04-10
*/
@Service
public class TtCopyTemplateServiceImpl implements ITtCopyTemplateService {
@Autowired
private TtCopyTemplateMapper ttCopyTemplateMapper;
@Override
public TtCopyTemplate selectTtCopyTemplateByTemplateId(Long templateId) {
return ttCopyTemplateMapper.selectTtCopyTemplateByTemplateId(templateId);
}
@Override
public List<TtCopyTemplate> selectTtCopyTemplateList(TtCopyTemplate ttCopyTemplate) {
return ttCopyTemplateMapper.selectTtCopyTemplateList(ttCopyTemplate);
}
@Override
public List<TtCopyTemplate> selectEnabledTemplates() {
return ttCopyTemplateMapper.selectEnabledTemplates();
}
@Override
public int insertTtCopyTemplate(TtCopyTemplate ttCopyTemplate) {
ttCopyTemplate.setCreateTime(DateUtils.getNowDate());
return ttCopyTemplateMapper.insertTtCopyTemplate(ttCopyTemplate);
}
@Override
public int updateTtCopyTemplate(TtCopyTemplate ttCopyTemplate) {
ttCopyTemplate.setUpdateTime(DateUtils.getNowDate());
return ttCopyTemplateMapper.updateTtCopyTemplate(ttCopyTemplate);
}
@Override
public int deleteTtCopyTemplateByTemplateIds(Long[] templateIds) {
return ttCopyTemplateMapper.deleteTtCopyTemplateByTemplateIds(templateIds);
}
@Override
public int deleteTtCopyTemplateByTemplateId(Long templateId) {
return ttCopyTemplateMapper.deleteTtCopyTemplateByTemplateId(templateId);
}
}

View File

@@ -0,0 +1,85 @@
<?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.ruoyi.office.mapper.TtCopyTemplateMapper">
<resultMap type="TtCopyTemplate" id="TtCopyTemplateResult">
<result property="templateId" column="template_id" />
<result property="templateName" column="template_name" />
<result property="templateBody" column="template_body" />
<result property="sortNum" column="sort_num" />
<result property="status" column="status" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectTtCopyTemplateVo">
select template_id, template_name, template_body, sort_num, status, create_time, update_time
from tt_copy_template
</sql>
<select id="selectTtCopyTemplateList" parameterType="TtCopyTemplate" resultMap="TtCopyTemplateResult">
<include refid="selectTtCopyTemplateVo"/>
<where>
<if test="templateName != null and templateName != ''"> and template_name like concat('%', #{templateName}, '%')</if>
<if test="status != null and status != ''"> and status = #{status}</if>
</where>
order by sort_num asc, create_time asc
</select>
<select id="selectEnabledTemplates" resultMap="TtCopyTemplateResult">
<include refid="selectTtCopyTemplateVo"/>
where status = '0'
order by sort_num asc, create_time asc
</select>
<select id="selectTtCopyTemplateByTemplateId" parameterType="Long" resultMap="TtCopyTemplateResult">
<include refid="selectTtCopyTemplateVo"/>
where template_id = #{templateId}
</select>
<insert id="insertTtCopyTemplate" parameterType="TtCopyTemplate" useGeneratedKeys="true" keyProperty="templateId">
insert into tt_copy_template
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="templateName != null and templateName != ''">template_name,</if>
<if test="templateBody != null">template_body,</if>
<if test="sortNum != null">sort_num,</if>
<if test="status != null and status != ''">status,</if>
<if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="templateName != null and templateName != ''">#{templateName},</if>
<if test="templateBody != null">#{templateBody},</if>
<if test="sortNum != null">#{sortNum},</if>
<if test="status != null and status != ''">#{status},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<update id="updateTtCopyTemplate" parameterType="TtCopyTemplate">
update tt_copy_template
<trim prefix="SET" suffixOverrides=",">
<if test="templateName != null and templateName != ''">template_name = #{templateName},</if>
<if test="templateBody != null">template_body = #{templateBody},</if>
<if test="sortNum != null">sort_num = #{sortNum},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where template_id = #{templateId}
</update>
<delete id="deleteTtCopyTemplateByTemplateId" parameterType="Long">
delete from tt_copy_template where template_id = #{templateId}
</delete>
<delete id="deleteTtCopyTemplateByTemplateIds" parameterType="Long">
delete from tt_copy_template where template_id in
<foreach item="templateId" collection="array" open="(" separator="," close=")">
#{templateId}
</foreach>
</delete>
</mapper>