【7.1.6】更新主题管理

pull/25/head
xixiaowei 2021-12-27 09:59:39 +08:00
parent a7c93a09b9
commit 82fabd9623
16 changed files with 372 additions and 51 deletions

View File

@ -27,7 +27,12 @@ public enum SysThemeTemplateExceptionEnum implements AbstractExceptionEnum {
/**
* 使
*/
TEMPLATE_IS_USED(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "113", "系统主题模板正在被使用,不允许操作");
TEMPLATE_IS_USED(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "113", "系统主题模板正在被使用,不允许操作"),
/**
*
*/
TEMPLATE_NOT_ATTRIBUTE(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "114", "系统主题模板没有属性,不允许启用");
/**
*

View File

@ -17,7 +17,12 @@ public enum SysThemeTemplateFieldExceptionEnum implements AbstractExceptionEnum
/**
*
*/
FIELD_NOT_EXIST(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "101", "系统主题模板属性不存在");
FIELD_NOT_EXIST(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "101", "系统主题模板属性不存在"),
/**
* 使
*/
FIELD_IS_USED(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "102", "系统主题模板属性正在被使用,不允许操作");
/**
*

View File

@ -0,0 +1,30 @@
package cn.stylefeng.roses.kernel.system.api.exception.enums.theme;
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
import cn.stylefeng.roses.kernel.system.api.constants.SystemConstants;
import lombok.Getter;
@Getter
public enum SysThemeTemplateRelExceptionEnum implements AbstractExceptionEnum {
/**
*
*/
RELATION_NOT_EXIST(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "131", "系统主题模板属性关系不存在");
/**
*
*/
private final String errorCode;
/**
*
*/
private final String userTip;
SysThemeTemplateRelExceptionEnum(String errorCode, String userTip) {
this.errorCode = errorCode;
this.userTip = userTip;
}
}

View File

@ -28,7 +28,6 @@ public class SysThemeTemplateFieldRequest extends BaseRequest {
/**
* ID
*/
@NotNull(message = "模板ID不能为空", groups = {add.class, delete.class})
@ChineseDescription("模板ID")
private Long templateId;
@ -39,6 +38,10 @@ public class SysThemeTemplateFieldRequest extends BaseRequest {
@ChineseDescription("属性名称")
private String fieldName;
@NotNull(message = "属性编码不能为空", groups = {add.class, edit.class})
@ChineseDescription("属性编码")
private String fieldCode;
/**
* ()
*/

View File

@ -0,0 +1,40 @@
package cn.stylefeng.roses.kernel.system.api.pojo.theme;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import cn.stylefeng.roses.kernel.scanner.api.annotation.field.ChineseDescription;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
*
*
* @author xixiaowei
* @date 2021/12/24 10:42
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class SysThemeTemplateRelRequest extends BaseRequest {
/**
* ID
*/
@ChineseDescription("主键ID")
private Long relationId;
/**
* ID
*/
@NotNull(message = "模板ID不能为空", groups = {add.class})
@ChineseDescription("模板ID")
private Long templateId;
/**
*
*/
@NotEmpty(message = "属性编码集合不能为空", groups = {add.class, delete.class})
@ChineseDescription("属性编码集合")
private String[] fieldCodes;
}

View File

@ -32,6 +32,13 @@ public class SysThemeTemplateRequest extends BaseRequest {
@ChineseDescription("主题模板名称")
private String templateName;
/**
*
*/
@NotNull(message = "主题模板编码不能为空", groups = {add.class, edit.class})
@ChineseDescription("主题模板编码")
private String templateCode;
/**
* 1-2-
*/

View File

@ -63,13 +63,46 @@ public class SysThemeTemplateFieldController {
}
/**
*
*
*
* @author xixiaowei
* @date 2021/12/17 11:49
*/
@GetResource(name = "查询系统主题模板属性", path = "/sysThemeTemplateField/detail")
public ResponseData detail(SysThemeTemplateFieldRequest sysThemeTemplateFieldParam) {
@GetResource(name = "查询系统主题模板属性详情", path = "/sysThemeTemplateField/detail")
public ResponseData detail(@Validated(SysThemeTemplateFieldRequest.detail.class) SysThemeTemplateFieldRequest sysThemeTemplateFieldParam) {
return new SuccessResponseData(sysThemeTemplateFieldService.detail(sysThemeTemplateFieldParam));
}
/**
*
*
* @author xixiaowei
* @date 2021/12/24 9:47
*/
@GetResource(name = "查询系统主题模板属性列表", path = "/sysThemeTemplateField/findPage")
public ResponseData findPage(SysThemeTemplateFieldRequest sysThemeTemplateFieldParam) {
return new SuccessResponseData(sysThemeTemplateFieldService.findPage(sysThemeTemplateFieldParam));
}
/**
*
*
* @author xixiaowei
* @date 2021/12/24 14:42
*/
@GetResource(name = "查询系统主题模板属性已有关系列表", path = "/sysThemeTemplateField/findRelList")
public ResponseData findRelPage(SysThemeTemplateFieldRequest sysThemeTemplateFieldParam) {
return new SuccessResponseData(sysThemeTemplateFieldService.findRelList(sysThemeTemplateFieldParam));
}
/**
*
*
* @author xixiaowei
* @date 2021/12/24 14:44
*/
@GetResource(name = "查询系统主题模板属性未有关系列表", path = "/sysThemeTemplateField/findNotRelList")
public ResponseData findNotRelPage(SysThemeTemplateFieldRequest sysThemeTemplateFieldParam) {
return new SuccessResponseData(sysThemeTemplateFieldService.findNotRelList(sysThemeTemplateFieldParam));
}
}

View File

@ -0,0 +1,51 @@
package cn.stylefeng.roses.kernel.system.modular.theme.controller;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.system.api.pojo.theme.SysThemeTemplateRelRequest;
import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeTemplateRelService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
*
*
* @author xixiaowei
* @date 2021/12/24 10:55
*/
@RestController
@ApiResource(name = "系统主题模板属性关系管理")
public class SysThemeTemplateRelController {
@Resource
private SysThemeTemplateRelService sysThemeTemplateRelService;
/**
*
*
* @author xixiaowei
* @date 2021/12/24 11:17
*/
@PostResource(name = "增加系统主题模板属性关系", path = "/sysThemeTemplateRel/add")
public ResponseData add(@RequestBody @Validated(SysThemeTemplateRelRequest.add.class) SysThemeTemplateRelRequest sysThemeTemplateParam) {
sysThemeTemplateRelService.add(sysThemeTemplateParam);
return new SuccessResponseData();
}
/**
*
*
* @author xixiaowei
* @date 2021/12/24 11:23
*/
@PostResource(name = "删除系统主题模板属性关系", path = "/sysThemeTemplateRel/del")
public ResponseData del(@RequestBody SysThemeTemplateRelRequest sysThemeTemplateRelParam) {
sysThemeTemplateRelService.del(sysThemeTemplateRelParam);
return new SuccessResponseData();
}
}

View File

@ -5,7 +5,6 @@ import cn.stylefeng.roses.kernel.system.api.pojo.theme.SysThemeRequest;
import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysTheme;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* service
*

View File

@ -1,9 +1,12 @@
package cn.stylefeng.roses.kernel.system.modular.theme.service;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.system.api.pojo.theme.SysThemeTemplateFieldRequest;
import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysThemeTemplateField;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* service
*
@ -37,10 +40,36 @@ public interface SysThemeTemplateFieldService extends IService<SysThemeTemplateF
void edit(SysThemeTemplateFieldRequest sysThemeTemplateFieldRequest);
/**
*
*
*
* @author xixiaowei
* @date 2021/12/17 11:47
*/
SysThemeTemplateField detail(SysThemeTemplateFieldRequest sysThemeTemplateFieldRequest);
/**
*
*
* @return
* @author xixiaowei
* @date 2021/12/24 9:29
*/
PageResult<SysThemeTemplateField> findPage(SysThemeTemplateFieldRequest sysThemeTemplateFieldRequest);
/**
*
*
* @author xixiaowei
* @date 2021/12/24 11:35
*/
List<SysThemeTemplateField> findRelList(SysThemeTemplateFieldRequest sysThemeTemplateFieldRequest);
/**
*
*
* @author xixiaowei
* @date 2021/12/24 11:49
*/
List<SysThemeTemplateField> findNotRelList(SysThemeTemplateFieldRequest sysThemeTemplateFieldRequest);
}

View File

@ -1,5 +1,6 @@
package cn.stylefeng.roses.kernel.system.modular.theme.service;
import cn.stylefeng.roses.kernel.system.api.pojo.theme.SysThemeTemplateRelRequest;
import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysThemeTemplateRel;
import com.baomidou.mybatisplus.extension.service.IService;
@ -11,4 +12,19 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface SysThemeTemplateRelService extends IService<SysThemeTemplateRel> {
/**
*
*
* @author xixiaowei
* @date 2021/12/24 10:56
*/
void add(SysThemeTemplateRelRequest sysThemeTemplateRelRequest);
/**
*
*
* @author xixiaowei
* @date 2021/12/24 11:18
*/
void del(SysThemeTemplateRelRequest sysThemeTemplateRelRequest);
}

View File

@ -41,7 +41,7 @@ public interface SysThemeTemplateService extends IService<SysThemeTemplate> {
void del(SysThemeTemplateRequest sysThemeTemplateRequest);
/**
*
*
*
* @return
* @author xixiaowei

View File

@ -54,7 +54,6 @@ public class SysThemeServiceImpl extends ServiceImpl<SysThemeMapper, SysTheme> i
public void add(SysThemeRequest sysThemeRequest) {
// 查询模板状态
SysThemeTemplate sysThemeTemplate = sysThemeTemplateService.getById(sysThemeRequest.getTemplateId());
// 判断模板启用状态:如果为禁用状态不允许使用
if (YesOrNotEnum.N.getCode().equals(sysThemeTemplate.getStatusFlag().toString())) {
throw new SystemModularException(SysThemeExceptionEnum.THEME_TEMPLATE_IS_DISABLE);

View File

@ -2,6 +2,10 @@ package cn.stylefeng.roses.kernel.system.modular.theme.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import cn.stylefeng.roses.kernel.system.api.exception.SystemModularException;
import cn.stylefeng.roses.kernel.system.api.exception.enums.theme.SysThemeTemplateFieldExceptionEnum;
@ -12,13 +16,14 @@ import cn.stylefeng.roses.kernel.system.modular.theme.mapper.SysThemeTemplateFie
import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeTemplateFieldService;
import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeTemplateRelService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* service
@ -33,47 +38,54 @@ public class SysThemeTemplateFieldServiceImpl extends ServiceImpl<SysThemeTempla
private SysThemeTemplateRelService sysThemeTemplateRelService;
@Override
@Transactional(rollbackFor = Exception.class)
public void add(SysThemeTemplateFieldRequest sysThemeTemplateFieldRequest) {
SysThemeTemplateField sysThemeTemplateField = new SysThemeTemplateField();
// 拷贝属性
BeanUtil.copyProperties(sysThemeTemplateFieldRequest, sysThemeTemplateField);
// 设置主题模板属性编码
sysThemeTemplateField.setFieldCode(IdWorker.getIdStr());
// 设置是否必填:如果请求参数为空,默认设置为非必填
sysThemeTemplateField.setFieldRequired(StringUtils.isBlank(sysThemeTemplateFieldRequest.getFieldType()) ? YesOrNotEnum.N.getCode().charAt(0) : sysThemeTemplateFieldRequest.getFieldRequired());
// 添加关联关系
SysThemeTemplateRel sysThemeTemplateRel = new SysThemeTemplateRel();
sysThemeTemplateRel.setTemplateId(sysThemeTemplateFieldRequest.getTemplateId());
sysThemeTemplateRel.setFieldCode(sysThemeTemplateField.getFieldCode());
// 保存关联关系
sysThemeTemplateRelService.save(sysThemeTemplateRel);
this.save(sysThemeTemplateField);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void del(SysThemeTemplateFieldRequest sysThemeTemplateFieldRequest) {
SysThemeTemplateField sysThemeTemplateField = this.queryThemeTemplateFieldById(sysThemeTemplateFieldRequest);
// 删除关联关系
LambdaQueryWrapper<SysThemeTemplateRel> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysThemeTemplateRel::getFieldCode, sysThemeTemplateField.getFieldCode());
sysThemeTemplateRelService.remove(queryWrapper);
// 校验系统主题模板属性使用
this.verificationAttributeUsage(sysThemeTemplateField);
this.removeById(sysThemeTemplateField.getFieldId());
}
/**
* 使
*
* @author xixiaowei
* @date 2021/12/24 9:16
*/
private void verificationAttributeUsage(SysThemeTemplateField sysThemeTemplateField) {
// 查询当前属性是否被使用
LambdaQueryWrapper<SysThemeTemplateRel> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysThemeTemplateRel::getFieldCode, sysThemeTemplateField.getFieldCode());
List<SysThemeTemplateRel> themeTemplateRels = sysThemeTemplateRelService.list(queryWrapper);
// 被使用,抛出异常
if (themeTemplateRels.size() > 0) {
throw new SystemModularException(SysThemeTemplateFieldExceptionEnum.FIELD_IS_USED);
}
}
@Override
public void edit(SysThemeTemplateFieldRequest sysThemeTemplateFieldRequest) {
SysThemeTemplateField sysThemeTemplateField = this.queryThemeTemplateFieldById(sysThemeTemplateFieldRequest);
// 校验系统主题模板属性使用
this.verificationAttributeUsage(sysThemeTemplateField);
// 更新属性
BeanUtil.copyProperties(sysThemeTemplateFieldRequest, sysThemeTemplateField);
@ -88,6 +100,72 @@ public class SysThemeTemplateFieldServiceImpl extends ServiceImpl<SysThemeTempla
return this.queryThemeTemplateFieldById(sysThemeTemplateFieldRequest);
}
@Override
public PageResult<SysThemeTemplateField> findPage(SysThemeTemplateFieldRequest sysThemeTemplateFieldRequest) {
LambdaQueryWrapper<SysThemeTemplateField> queryWrapper = new LambdaQueryWrapper<>();
// 根据属性名称模糊查询
queryWrapper.like(StrUtil.isNotBlank(sysThemeTemplateFieldRequest.getFieldName()), SysThemeTemplateField::getFieldName, sysThemeTemplateFieldRequest.getFieldName());
Page<SysThemeTemplateField> page = page(PageFactory.defaultPage(), queryWrapper);
return PageResultFactory.createPageResult(page);
}
@Override
public List<SysThemeTemplateField> findRelList(SysThemeTemplateFieldRequest sysThemeTemplateFieldRequest) {
List<String> fieldCodes = this.getFieldCodes(sysThemeTemplateFieldRequest, sysThemeTemplateRelService);
// 查询具体属性信息
LambdaQueryWrapper<SysThemeTemplateField> queryWrapper = new LambdaQueryWrapper<>();
List<SysThemeTemplateField> sysThemeTemplateFields = null;
// 如果关联属性非空,拼接查询条件
if (fieldCodes.size() > 0) {
queryWrapper.in(SysThemeTemplateField::getFieldCode, fieldCodes);
sysThemeTemplateFields = this.list(queryWrapper);
}
return sysThemeTemplateFields;
}
/**
*
*
* @author xixiaowei
* @date 2021/12/24 14:38
*/
private List<String> getFieldCodes(SysThemeTemplateFieldRequest sysThemeTemplateFieldRequest, SysThemeTemplateRelService sysThemeTemplateRelService) {
// 查询有关联的属性
LambdaQueryWrapper<SysThemeTemplateRel> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysThemeTemplateRel::getTemplateId, sysThemeTemplateFieldRequest.getTemplateId());
List<SysThemeTemplateRel> sysThemeTemplateRels = sysThemeTemplateRelService.list(queryWrapper);
// 过滤出所有的属性编码
List<String> fieldCodes = sysThemeTemplateRels.stream().map(SysThemeTemplateRel::getFieldCode).collect(Collectors.toList());
return fieldCodes;
}
@Override
public List<SysThemeTemplateField> findNotRelList(SysThemeTemplateFieldRequest sysThemeTemplateFieldRequest) {
// 查询有关联的属性
List<String> fieldCodes = getFieldCodes(sysThemeTemplateFieldRequest, sysThemeTemplateRelService);
// 查询没有关联的属性
LambdaQueryWrapper<SysThemeTemplateField> queryWrapper = new LambdaQueryWrapper<>();
List<SysThemeTemplateField> sysThemeTemplateFields;
// 如果关联属性非空,拼接条件;否者查询全部
if (fieldCodes.size() > 0) {
queryWrapper.notIn(SysThemeTemplateField::getFieldCode, fieldCodes);
sysThemeTemplateFields = this.list(queryWrapper);
} else {
sysThemeTemplateFields = this.list();
}
return sysThemeTemplateFields;
}
/**
*
*

View File

@ -1,11 +1,16 @@
package cn.stylefeng.roses.kernel.system.modular.theme.service.impl;
import cn.stylefeng.roses.kernel.system.api.pojo.theme.SysThemeTemplateRelRequest;
import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysThemeTemplateRel;
import cn.stylefeng.roses.kernel.system.modular.theme.mapper.SysThemeTemplateRelMapper;
import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeTemplateRelService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* service
*
@ -15,4 +20,35 @@ import org.springframework.stereotype.Service;
@Service
public class SysThemeTemplateRelServiceImpl extends ServiceImpl<SysThemeTemplateRelMapper, SysThemeTemplateRel> implements SysThemeTemplateRelService {
@Override
public void add(SysThemeTemplateRelRequest sysThemeTemplateRelRequest) {
// 获取请求中的所有属性编码
String[] fieldCodes = sysThemeTemplateRelRequest.getFieldCodes();
List<SysThemeTemplateRel> sysThemeTemplateRels = new ArrayList<>();
// 填充对象
for (String fieldCode : fieldCodes) {
SysThemeTemplateRel sysThemeTemplateRel = new SysThemeTemplateRel();
sysThemeTemplateRel.setTemplateId(sysThemeTemplateRelRequest.getTemplateId());
sysThemeTemplateRel.setFieldCode(fieldCode);
sysThemeTemplateRels.add(sysThemeTemplateRel);
}
// 保存关系
this.saveBatch(sysThemeTemplateRels);
}
@Override
public void del(SysThemeTemplateRelRequest sysThemeTemplateRelRequest) {
// 获取请求中的所有属性编码
String[] fieldCodes = sysThemeTemplateRelRequest.getFieldCodes();
// 构建删除条件
LambdaQueryWrapper<SysThemeTemplateRel> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(SysThemeTemplateRel::getFieldCode, fieldCodes);
this.remove(queryWrapper);
}
}

View File

@ -13,15 +13,12 @@ import cn.stylefeng.roses.kernel.system.api.pojo.theme.SysThemeTemplateDataDTO;
import cn.stylefeng.roses.kernel.system.api.pojo.theme.SysThemeTemplateRequest;
import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysTheme;
import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysThemeTemplate;
import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysThemeTemplateField;
import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysThemeTemplateRel;
import cn.stylefeng.roses.kernel.system.modular.theme.mapper.SysThemeTemplateMapper;
import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeService;
import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeTemplateFieldService;
import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeTemplateRelService;
import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeTemplateService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
@ -29,7 +26,6 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* service
@ -49,9 +45,6 @@ public class SysThemeTemplateServiceImpl extends ServiceImpl<SysThemeTemplateMap
@Resource
private SysThemeTemplateRelService sysThemeTemplateRelService;
@Resource
private SysThemeTemplateFieldService sysThemeTemplateFieldService;
@Override
public void add(SysThemeTemplateRequest sysThemeTemplateRequest) {
SysThemeTemplate sysThemeTemplate = new SysThemeTemplate();
@ -59,8 +52,6 @@ public class SysThemeTemplateServiceImpl extends ServiceImpl<SysThemeTemplateMap
// 拷贝属性
BeanUtil.copyProperties(sysThemeTemplateRequest, sysThemeTemplate);
// 设置主题模板编码
sysThemeTemplate.setTemplateCode(IdWorker.getIdStr());
// 默认启用状态禁用N
sysThemeTemplate.setStatusFlag(YesOrNotEnum.N.getCode().charAt(0));
@ -90,21 +81,10 @@ public class SysThemeTemplateServiceImpl extends ServiceImpl<SysThemeTemplateMap
throw new SystemModularException(SysThemeTemplateExceptionEnum.TEMPLATE_IS_ENABLE);
}
// 删除关联关系
// 删除关联关系条件
LambdaQueryWrapper<SysThemeTemplateRel> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysThemeTemplateRel::getTemplateId, sysThemeTemplate.getTemplateId());
// 查询所有关联属性的编码
List<SysThemeTemplateRel> SysThemeTemplateRels = sysThemeTemplateRelService.list(queryWrapper.select(SysThemeTemplateRel::getFieldCode));
List<String> sysThemeTemplateFieldCodes = SysThemeTemplateRels.stream().map(SysThemeTemplateRel::getFieldCode).collect(Collectors.toList());
LambdaQueryWrapper<SysThemeTemplateField> delFieldWrapper = new LambdaQueryWrapper<>();
delFieldWrapper.in(SysThemeTemplateField::getFieldCode, sysThemeTemplateFieldCodes);
// 删除关联属性
if (sysThemeTemplateFieldCodes.size() > 0) {
sysThemeTemplateFieldService.remove(delFieldWrapper);
}
// 删除关联关系
sysThemeTemplateRelService.remove(queryWrapper);
@ -139,9 +119,19 @@ public class SysThemeTemplateServiceImpl extends ServiceImpl<SysThemeTemplateMap
if (YesOrNotEnum.Y.getCode().equals(sysThemeTemplate.getStatusFlag().toString())) {
sysThemeTemplate.setStatusFlag(YesOrNotEnum.N.getCode().charAt(0));
} else {
// 如果该模板没有属性不允许启用
LambdaQueryWrapper<SysThemeTemplateRel> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(SysThemeTemplateRel::getTemplateId, sysThemeTemplate.getTemplateId());
List<SysThemeTemplateRel> sysThemeTemplateRels = sysThemeTemplateRelService.list(wrapper);
if (sysThemeTemplateRels.size() <= 0) {
throw new SystemModularException(SysThemeTemplateExceptionEnum.TEMPLATE_NOT_ATTRIBUTE);
}
sysThemeTemplate.setStatusFlag(YesOrNotEnum.Y.getCode().charAt(0));
}
this.updateById(sysThemeTemplate);
}