1
This commit is contained in:
@@ -2,6 +2,7 @@ package com.fizz.business.controller;
|
|||||||
|
|
||||||
import com.fizz.business.domain.BizSendTemplate;
|
import com.fizz.business.domain.BizSendTemplate;
|
||||||
import com.fizz.business.domain.BizSendTemplateItem;
|
import com.fizz.business.domain.BizSendTemplateItem;
|
||||||
|
import com.fizz.business.domain.dto.SendTemplateItemsBatchSaveDTO;
|
||||||
import com.fizz.business.domain.vo.BizSendTemplateVO;
|
import com.fizz.business.domain.vo.BizSendTemplateVO;
|
||||||
import com.fizz.business.service.IBizSendTemplateItemService;
|
import com.fizz.business.service.IBizSendTemplateItemService;
|
||||||
import com.fizz.business.service.IBizSendTemplateService;
|
import com.fizz.business.service.IBizSendTemplateService;
|
||||||
@@ -68,4 +69,25 @@ public class BizSendTemplateController extends BaseController {
|
|||||||
}
|
}
|
||||||
return toAjax(templateItemService.updateItemsBatch(items));
|
return toAjax(templateItemService.updateItemsBatch(items));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模板明细批量保存(新增/更新/删除)
|
||||||
|
*/
|
||||||
|
@PutMapping("/items/batchSave")
|
||||||
|
public AjaxResult batchSaveItems(@RequestBody SendTemplateItemsBatchSaveDTO dto) {
|
||||||
|
if (dto == null || dto.getTemplateId() == null) {
|
||||||
|
return AjaxResult.error("templateId is required");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Boolean ok = templateItemService.batchSave(
|
||||||
|
dto.getTemplateId(),
|
||||||
|
dto.getItems(),
|
||||||
|
dto.getDeleteIds(),
|
||||||
|
SecurityUtils.getUsername()
|
||||||
|
);
|
||||||
|
return toAjax(ok);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return AjaxResult.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,5 +14,8 @@ public class SendJobQueryDTO {
|
|||||||
|
|
||||||
/** 状态: PENDING, IN_PROGRESS, COMPLETED, PARTIAL_SUCCESS, FAILED, DELETED */
|
/** 状态: PENDING, IN_PROGRESS, COMPLETED, PARTIAL_SUCCESS, FAILED, DELETED */
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
|
/** 分组类型: DRIVE / FURNACE */
|
||||||
|
private String groupType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.fizz.business.domain.dto;
|
||||||
|
|
||||||
|
import com.fizz.business.domain.BizSendTemplateItem;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模板明细批量保存(新增/更新/删除)
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class SendTemplateItemsBatchSaveDTO {
|
||||||
|
|
||||||
|
/** 模板ID */
|
||||||
|
private Integer templateId;
|
||||||
|
|
||||||
|
/** 需要新增/更新的明细 */
|
||||||
|
private List<BizSendTemplateItem> items;
|
||||||
|
|
||||||
|
/** 需要删除的明细ID */
|
||||||
|
private List<Integer> deleteIds;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -11,8 +11,13 @@ import java.util.List;
|
|||||||
public interface IBizSendTemplateItemService extends IService<BizSendTemplateItem> {
|
public interface IBizSendTemplateItemService extends IService<BizSendTemplateItem> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量更新模板明细
|
* 批量更新模板明细(仅更新已有ID)
|
||||||
*/
|
*/
|
||||||
Boolean updateItemsBatch(List<BizSendTemplateItem> items);
|
Boolean updateItemsBatch(List<BizSendTemplateItem> items);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量保存模板明细(新增/更新/删除)
|
||||||
|
*/
|
||||||
|
Boolean batchSave(Integer templateId, List<BizSendTemplateItem> items, List<Integer> deleteIds, String username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||||||
import com.fizz.business.domain.BizSendTemplateItem;
|
import com.fizz.business.domain.BizSendTemplateItem;
|
||||||
import com.fizz.business.mapper.BizSendTemplateItemMapper;
|
import com.fizz.business.mapper.BizSendTemplateItemMapper;
|
||||||
import com.fizz.business.service.IBizSendTemplateItemService;
|
import com.fizz.business.service.IBizSendTemplateItemService;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class BizSendTemplateItemServiceImpl extends ServiceImpl<BizSendTemplateItemMapper, BizSendTemplateItem> implements IBizSendTemplateItemService {
|
public class BizSendTemplateItemServiceImpl extends ServiceImpl<BizSendTemplateItemMapper, BizSendTemplateItem> implements IBizSendTemplateItemService {
|
||||||
@@ -24,5 +25,74 @@ public class BizSendTemplateItemServiceImpl extends ServiceImpl<BizSendTemplateI
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Boolean batchSave(Integer templateId, List<BizSendTemplateItem> items, List<Integer> deleteIds, String username) {
|
||||||
|
Date now = new Date();
|
||||||
|
|
||||||
|
// 1) 删除(物理删除)。如果你们希望逻辑删除,可在此改为 enabled=0 / deleted 标记。
|
||||||
|
if (deleteIds != null && !deleteIds.isEmpty()) {
|
||||||
|
this.removeByIds(deleteIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2) 新增/更新
|
||||||
|
if (items == null) {
|
||||||
|
items = Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 基础校验:templateId 必须一致
|
||||||
|
for (BizSendTemplateItem it : items) {
|
||||||
|
if (it.getTemplateId() == null) {
|
||||||
|
it.setTemplateId(templateId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 校验:同一 templateId 下 paramCode 唯一
|
||||||
|
// - 先校验本次提交内是否重复
|
||||||
|
Set<String> seen = new HashSet<>();
|
||||||
|
for (BizSendTemplateItem it : items) {
|
||||||
|
if (it.getParamCode() == null || it.getParamCode().trim().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("paramCode is required");
|
||||||
|
}
|
||||||
|
String code = it.getParamCode().trim();
|
||||||
|
if (!seen.add(code)) {
|
||||||
|
throw new IllegalArgumentException("Duplicate paramCode in request: " + code);
|
||||||
|
}
|
||||||
|
it.setParamCode(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
// - 再校验数据库里是否已存在同 paramCode(排除自身ID)
|
||||||
|
for (BizSendTemplateItem it : items) {
|
||||||
|
LambdaQueryWrapper<BizSendTemplateItem> qw = new LambdaQueryWrapper<>();
|
||||||
|
qw.eq(BizSendTemplateItem::getTemplateId, templateId)
|
||||||
|
.eq(BizSendTemplateItem::getParamCode, it.getParamCode());
|
||||||
|
if (it.getTemplateItemId() != null) {
|
||||||
|
qw.ne(BizSendTemplateItem::getTemplateItemId, it.getTemplateItemId());
|
||||||
|
}
|
||||||
|
long cnt = this.count(qw);
|
||||||
|
if (cnt > 0) {
|
||||||
|
throw new IllegalArgumentException("paramCode already exists: " + it.getParamCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (BizSendTemplateItem it : items) {
|
||||||
|
it.setTemplateId(templateId);
|
||||||
|
if (it.getTemplateItemId() == null) {
|
||||||
|
it.setCreateBy(username);
|
||||||
|
it.setCreateTime(now);
|
||||||
|
it.setUpdateBy(username);
|
||||||
|
it.setUpdateTime(now);
|
||||||
|
this.save(it);
|
||||||
|
} else {
|
||||||
|
it.setUpdateBy(username);
|
||||||
|
it.setUpdateTime(now);
|
||||||
|
this.updateById(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -107,12 +107,36 @@ public class SendJobServiceImpl extends ServiceImpl<BizSendJobMapper, BizSendJob
|
|||||||
@Override
|
@Override
|
||||||
public List<BizSendJob> selectSendJobList(SendJobQueryDTO query) {
|
public List<BizSendJob> selectSendJobList(SendJobQueryDTO query) {
|
||||||
LambdaQueryWrapper<BizSendJob> qw = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<BizSendJob> qw = new LambdaQueryWrapper<>();
|
||||||
qw.eq(StringUtils.isNotBlank(query.getDeviceName()),
|
qw.eq(StringUtils.isNotBlank(query.getDeviceName()),
|
||||||
BizSendJob::getDeviceName, query.getDeviceName())
|
BizSendJob::getDeviceName, query.getDeviceName())
|
||||||
.eq(StringUtils.isNotBlank(query.getStatus()),
|
.eq(StringUtils.isNotBlank(query.getStatus()),
|
||||||
BizSendJob::getStatus, query.getStatus())
|
BizSendJob::getStatus, query.getStatus())
|
||||||
.orderByDesc(BizSendJob::getCreateTime);
|
.orderByDesc(BizSendJob::getCreateTime);
|
||||||
return baseMapper.selectList(qw);
|
|
||||||
|
List<BizSendJob> jobs = baseMapper.selectList(qw);
|
||||||
|
if (jobs == null || jobs.isEmpty()) {
|
||||||
|
return jobs;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果传了 groupType(如 FURNACE),则仅保留包含该 groupType 的 job
|
||||||
|
if (StringUtils.isNotBlank(query.getGroupType())) {
|
||||||
|
String gt = query.getGroupType().trim();
|
||||||
|
|
||||||
|
List<Integer> jobIds = jobs.stream().map(BizSendJob::getJobId).collect(Collectors.toList());
|
||||||
|
List<BizSendJobGroup> groups = jobGroupMapper.selectList(
|
||||||
|
new LambdaQueryWrapper<BizSendJobGroup>()
|
||||||
|
.in(BizSendJobGroup::getJobId, jobIds)
|
||||||
|
.eq(BizSendJobGroup::getGroupType, gt)
|
||||||
|
);
|
||||||
|
if (groups == null || groups.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<Integer> allowedJobIds = groups.stream().map(BizSendJobGroup::getJobId).collect(Collectors.toSet());
|
||||||
|
return jobs.stream().filter(j -> allowedJobIds.contains(j.getJobId())).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
return jobs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user