diff --git a/business/src/main/java/com/fizz/business/controller/BizSendTemplateController.java b/business/src/main/java/com/fizz/business/controller/BizSendTemplateController.java index ebfdd3a..3900df2 100644 --- a/business/src/main/java/com/fizz/business/controller/BizSendTemplateController.java +++ b/business/src/main/java/com/fizz/business/controller/BizSendTemplateController.java @@ -1,12 +1,19 @@ package com.fizz.business.controller; +import com.fizz.business.domain.BizSendTemplate; +import com.fizz.business.domain.BizSendTemplateItem; import com.fizz.business.domain.vo.BizSendTemplateVO; +import com.fizz.business.service.IBizSendTemplateItemService; import com.fizz.business.service.IBizSendTemplateService; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.utils.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.Date; +import java.util.List; + /** * 发送模板配置 Controller */ @@ -17,6 +24,9 @@ public class BizSendTemplateController extends BaseController { @Autowired private IBizSendTemplateService templateService; + @Autowired + private IBizSendTemplateItemService templateItemService; + /** * 按模板编码获取模板(含明细) */ @@ -28,4 +38,34 @@ public class BizSendTemplateController extends BaseController { } return AjaxResult.success(vo); } + + /** + * 更新模板主表(如 deviceName) + */ + @PutMapping + public AjaxResult updateTemplate(@RequestBody BizSendTemplate template) { + if (template == null || template.getTemplateId() == null) { + return AjaxResult.error("templateId is required"); + } + template.setUpdateBy(SecurityUtils.getUsername()); + template.setUpdateTime(new Date()); + return toAjax(templateService.updateById(template)); + } + + /** + * 批量更新模板明细(address/defaultValueRaw/enabled等) + */ + @PutMapping("/items") + public AjaxResult updateTemplateItems(@RequestBody List items) { + if (items == null || items.isEmpty()) { + return AjaxResult.success(); + } + Date now = new Date(); + String username = SecurityUtils.getUsername(); + for (BizSendTemplateItem it : items) { + it.setUpdateBy(username); + it.setUpdateTime(now); + } + return toAjax(templateItemService.updateItemsBatch(items)); + } } diff --git a/business/src/main/java/com/fizz/business/service/IBizSendTemplateItemService.java b/business/src/main/java/com/fizz/business/service/IBizSendTemplateItemService.java new file mode 100644 index 0000000..367402b --- /dev/null +++ b/business/src/main/java/com/fizz/business/service/IBizSendTemplateItemService.java @@ -0,0 +1,18 @@ +package com.fizz.business.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.fizz.business.domain.BizSendTemplateItem; + +import java.util.List; + +/** + * 发送模板明细 Service + */ +public interface IBizSendTemplateItemService extends IService { + + /** + * 批量更新模板明细 + */ + Boolean updateItemsBatch(List items); +} + diff --git a/business/src/main/java/com/fizz/business/service/impl/BizSendTemplateItemServiceImpl.java b/business/src/main/java/com/fizz/business/service/impl/BizSendTemplateItemServiceImpl.java new file mode 100644 index 0000000..3fbe1ba --- /dev/null +++ b/business/src/main/java/com/fizz/business/service/impl/BizSendTemplateItemServiceImpl.java @@ -0,0 +1,28 @@ +package com.fizz.business.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.fizz.business.domain.BizSendTemplateItem; +import com.fizz.business.mapper.BizSendTemplateItemMapper; +import com.fizz.business.service.IBizSendTemplateItemService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Service +public class BizSendTemplateItemServiceImpl extends ServiceImpl implements IBizSendTemplateItemService { + + @Override + @Transactional(rollbackFor = Exception.class) + public Boolean updateItemsBatch(List items) { + if (items == null || items.isEmpty()) { + return true; + } + // MyBatis-Plus 批量更新:这里简单循环 updateById(数量约40~100可接受) + for (BizSendTemplateItem it : items) { + this.updateById(it); + } + return true; + } +} +