新增动态修改模板
This commit is contained in:
@@ -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<BizSendTemplateItem> 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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<BizSendTemplateItem> {
|
||||
|
||||
/**
|
||||
* 批量更新模板明细
|
||||
*/
|
||||
Boolean updateItemsBatch(List<BizSendTemplateItem> items);
|
||||
}
|
||||
|
||||
@@ -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<BizSendTemplateItemMapper, BizSendTemplateItem> implements IBizSendTemplateItemService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean updateItemsBatch(List<BizSendTemplateItem> items) {
|
||||
if (items == null || items.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
// MyBatis-Plus 批量更新:这里简单循环 updateById(数量约40~100可接受)
|
||||
for (BizSendTemplateItem it : items) {
|
||||
this.updateById(it);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user