parent
2b933d6f62
commit
595a2172e3
@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package org.opsli.modulars.generator.template.entity;
|
||||
|
||||
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldStrategy;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.opsli.core.base.entity.BaseEntity;
|
||||
|
||||
/**
|
||||
* 代码模板 Entity
|
||||
*
|
||||
* @author 周鹏程
|
||||
* @date 2021-05-27 14:33:49
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class GenTemplate extends BaseEntity {
|
||||
|
||||
/** 模板名称 */
|
||||
private String tempName;
|
||||
|
||||
/** 表类型 */
|
||||
private String tableType;
|
||||
|
||||
/** 备注信息 */
|
||||
private String remark;
|
||||
|
||||
// ========================================
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package org.opsli.modulars.generator.template.entity;
|
||||
|
||||
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldStrategy;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.opsli.core.base.entity.BaseEntity;
|
||||
|
||||
/**
|
||||
* 代码模板详情 Entity
|
||||
*
|
||||
* @author 周鹏程
|
||||
* @date 2021-05-28 17:12:38
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class GenTemplateDetail extends BaseEntity {
|
||||
|
||||
|
||||
/** 父级ID */
|
||||
private String parentId;
|
||||
|
||||
/** 路径 */
|
||||
private String path;
|
||||
|
||||
/** 文件名 */
|
||||
private String fileName;
|
||||
|
||||
/** 文件内容 */
|
||||
private String fileContent;
|
||||
|
||||
// ========================================
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package org.opsli.modulars.generator.template.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import org.opsli.modulars.generator.template.entity.GenTemplateDetail;
|
||||
|
||||
|
||||
/**
|
||||
* 代码模板详情 Mapper
|
||||
*
|
||||
* @author 周鹏程
|
||||
* @date 2021-05-28 17:12:38
|
||||
*/
|
||||
@Mapper
|
||||
public interface GenTemplateDetailMapper extends BaseMapper<GenTemplateDetail> {
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package org.opsli.modulars.generator.template.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import org.opsli.modulars.generator.template.entity.GenTemplate;
|
||||
|
||||
|
||||
/**
|
||||
* 代码模板 Mapper
|
||||
*
|
||||
* @author 周鹏程
|
||||
* @date 2021-05-27 14:33:49
|
||||
*/
|
||||
@Mapper
|
||||
public interface GenTemplateMapper extends BaseMapper<GenTemplate> {
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
<?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="org.opsli.modulars.generator.template.mapper.GenTemplateDetailMapper">
|
||||
|
||||
|
||||
|
||||
</mapper>
|
@ -0,0 +1,8 @@
|
||||
<?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="org.opsli.modulars.generator.template.mapper.GenTemplateMapper">
|
||||
|
||||
|
||||
|
||||
</mapper>
|
@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package org.opsli.modulars.generator.template.service;
|
||||
|
||||
|
||||
import org.opsli.core.base.service.interfaces.CrudServiceInterface;
|
||||
import org.opsli.modulars.generator.template.entity.GenTemplateDetail;
|
||||
import org.opsli.modulars.generator.template.wrapper.GenTemplateDetailModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 代码模板详情 Service
|
||||
*
|
||||
* @author 周鹏程
|
||||
* @date 2021-05-28 17:12:38
|
||||
*/
|
||||
public interface IGenTemplateDetailService extends CrudServiceInterface<GenTemplateDetail, GenTemplateDetailModel> {
|
||||
|
||||
/**
|
||||
* 根据父类ID 删除
|
||||
* @param parentId 父类ID
|
||||
* @return boolean
|
||||
*/
|
||||
boolean delByParent(String parentId);
|
||||
|
||||
/**
|
||||
* 根据父类ID 查询List 集合
|
||||
* @param parentId 父类ID
|
||||
* @return List
|
||||
*/
|
||||
List<GenTemplateDetailModel> findListByParent(String parentId);
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package org.opsli.modulars.generator.template.service;
|
||||
|
||||
|
||||
import org.opsli.core.base.service.interfaces.CrudServiceInterface;
|
||||
|
||||
|
||||
|
||||
import org.opsli.modulars.generator.template.entity.GenTemplate;
|
||||
import org.opsli.modulars.generator.template.wrapper.GenTemplateAndDetailModel;
|
||||
import org.opsli.modulars.generator.template.wrapper.GenTemplateModel;
|
||||
|
||||
|
||||
/**
|
||||
* 代码模板 Service
|
||||
*
|
||||
* @author 周鹏程
|
||||
* @date 2021-05-27 14:33:49
|
||||
*/
|
||||
public interface IGenTemplateService extends CrudServiceInterface<GenTemplate, GenTemplateModel> {
|
||||
|
||||
/**
|
||||
* 新增 且 操作明细数据
|
||||
* @param model model
|
||||
* @return GenTemplateModel
|
||||
*/
|
||||
GenTemplateModel insertAndDetail(GenTemplateAndDetailModel model);
|
||||
|
||||
/**
|
||||
* 修改 且 操作明细数据
|
||||
* @param model model
|
||||
* @return GenTemplateModel
|
||||
*/
|
||||
GenTemplateModel updateAndDetail(GenTemplateAndDetailModel model);
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,230 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package org.opsli.modulars.generator.template.service.impl;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.opsli.common.constants.MyBatisConstants;
|
||||
import org.opsli.common.exception.ServiceException;
|
||||
import org.opsli.common.utils.FieldUtil;
|
||||
import org.opsli.core.base.service.impl.CrudServiceImpl;
|
||||
import org.opsli.core.msg.CoreMsg;
|
||||
import org.opsli.core.persistence.querybuilder.GenQueryBuilder;
|
||||
import org.opsli.core.persistence.querybuilder.QueryBuilder;
|
||||
import org.opsli.modulars.generator.template.entity.GenTemplateDetail;
|
||||
import org.opsli.modulars.generator.template.mapper.GenTemplateDetailMapper;
|
||||
import org.opsli.modulars.generator.template.service.IGenTemplateDetailService;
|
||||
import org.opsli.modulars.generator.template.wrapper.GenTemplateDetailModel;
|
||||
import org.opsli.plugins.generator.utils.GenTemplateUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* 代码模板详情 Service Impl
|
||||
*
|
||||
* @author 周鹏程
|
||||
* @date 2021-05-28 17:12:38
|
||||
*/
|
||||
@Service
|
||||
public class GenTemplateDetailServiceImpl extends CrudServiceImpl<GenTemplateDetailMapper, GenTemplateDetail, GenTemplateDetailModel>
|
||||
implements IGenTemplateDetailService {
|
||||
|
||||
@Autowired(required = false)
|
||||
private GenTemplateDetailMapper mapper;
|
||||
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* @param model model 数据模型
|
||||
* @return DictDetailModel
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public GenTemplateDetailModel insert(GenTemplateDetailModel model) {
|
||||
GenTemplateDetailModel ret = super.insert(model);
|
||||
if(ret != null){
|
||||
// 删除缓存
|
||||
this.clearCache(Collections.singletonList(
|
||||
ret.getParentId()
|
||||
));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param model model 数据模型
|
||||
* @return GenTemplateDetailModel
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public GenTemplateDetailModel update(GenTemplateDetailModel model) {
|
||||
// 旧数据 用于删除老缓存
|
||||
GenTemplateDetailModel oldModel = this.get(model);
|
||||
|
||||
GenTemplateDetailModel ret = super.update(model);
|
||||
if(ret != null){
|
||||
// 删除缓存
|
||||
this.clearCache(Collections.singletonList(
|
||||
oldModel.getParentId()
|
||||
));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param id ID
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean delete(String id) {
|
||||
GenTemplateDetailModel baseModel = this.get(id);
|
||||
boolean ret = super.delete(id);
|
||||
if(ret){
|
||||
// 删除缓存
|
||||
this.clearCache(Collections.singletonList(
|
||||
baseModel.getParentId()
|
||||
));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 - 多个
|
||||
* @param ids id数组
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean deleteAll(String[] ids) {
|
||||
QueryBuilder<GenTemplateDetail> queryBuilder = new GenQueryBuilder<>();
|
||||
QueryWrapper<GenTemplateDetail> queryWrapper = queryBuilder.build();
|
||||
List<?> idList = Convert.toList(ids);
|
||||
queryWrapper.in(FieldUtil.humpToUnderline(MyBatisConstants.FIELD_ID),idList);
|
||||
List<GenTemplateDetail> list = this.findList(queryWrapper);
|
||||
boolean ret = super.deleteAll(ids);
|
||||
|
||||
if(ret){
|
||||
if(CollUtil.isNotEmpty(list)){
|
||||
Set<String> parentIds = new HashSet<>();
|
||||
// 封装数据
|
||||
for (GenTemplateDetail genTemplateDetail : list) {
|
||||
parentIds.add(genTemplateDetail.getParentId());
|
||||
}
|
||||
|
||||
List<String> parentIdList = Lists.newArrayListWithCapacity(parentIds.size());
|
||||
|
||||
// 删除缓存
|
||||
this.clearCache(parentIdList);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 父类ID 全部删除
|
||||
* @param parentId 父类ID
|
||||
* @return boolean
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean delByParent(String parentId) {
|
||||
if(StringUtils.isEmpty(parentId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String key = FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID);
|
||||
QueryBuilder<GenTemplateDetail> queryBuilder = new GenQueryBuilder<>();
|
||||
QueryWrapper<GenTemplateDetail> queryWrapper = queryBuilder.build();
|
||||
queryWrapper.eq(key, parentId);
|
||||
|
||||
boolean removeFlag = super.remove(queryWrapper);
|
||||
if(removeFlag){
|
||||
// 删除缓存
|
||||
this.clearCache(Collections.singletonList(
|
||||
parentId
|
||||
));
|
||||
}
|
||||
return removeFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 父类ID 全部删除
|
||||
* @param parentId 父类ID
|
||||
* @return boolean
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public List<GenTemplateDetailModel> findListByParent(String parentId) {
|
||||
if(StringUtils.isEmpty(parentId)) {
|
||||
return ListUtil.empty();
|
||||
}
|
||||
|
||||
String key = FieldUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID);
|
||||
QueryBuilder<GenTemplateDetail> queryBuilder = new GenQueryBuilder<>();
|
||||
QueryWrapper<GenTemplateDetail> queryWrapper = queryBuilder.build();
|
||||
queryWrapper.eq(key, parentId);
|
||||
|
||||
return super.transformTs2Ms(this.findList(queryWrapper));
|
||||
}
|
||||
|
||||
|
||||
// ====================
|
||||
|
||||
|
||||
/**
|
||||
* 清除缓存
|
||||
* @param parentIdList 父级ID集合
|
||||
*/
|
||||
private void clearCache(List<String> parentIdList) {
|
||||
// 删除缓存
|
||||
if (CollUtil.isNotEmpty(parentIdList)) {
|
||||
int cacheCount = 0;
|
||||
for (String parentId : parentIdList) {
|
||||
cacheCount++;
|
||||
boolean tmp = GenTemplateUtil.delAll(parentId);
|
||||
if(tmp){
|
||||
cacheCount--;
|
||||
}
|
||||
}
|
||||
// 判断删除状态
|
||||
if(cacheCount != 0){
|
||||
// 删除缓存失败
|
||||
throw new ServiceException(CoreMsg.CACHE_DEL_EXCEPTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,175 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package org.opsli.modulars.generator.template.service.impl;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.opsli.common.constants.MyBatisConstants;
|
||||
import org.opsli.common.exception.ServiceException;
|
||||
import org.opsli.common.utils.WrapperUtil;
|
||||
import org.opsli.core.base.service.impl.CrudServiceImpl;
|
||||
import org.opsli.core.msg.CoreMsg;
|
||||
import org.opsli.core.persistence.querybuilder.GenQueryBuilder;
|
||||
import org.opsli.core.persistence.querybuilder.QueryBuilder;
|
||||
import org.opsli.modulars.generator.template.entity.GenTemplate;
|
||||
import org.opsli.modulars.generator.template.mapper.GenTemplateMapper;
|
||||
import org.opsli.modulars.generator.template.service.IGenTemplateDetailService;
|
||||
import org.opsli.modulars.generator.template.service.IGenTemplateService;
|
||||
import org.opsli.modulars.generator.template.wrapper.GenTemplateAndDetailModel;
|
||||
import org.opsli.modulars.generator.template.wrapper.GenTemplateDetailModel;
|
||||
import org.opsli.modulars.generator.template.wrapper.GenTemplateModel;
|
||||
import org.opsli.plugins.generator.utils.GenTemplateUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 代码模板 Service Impl
|
||||
*
|
||||
* @author 周鹏程
|
||||
* @date 2021-05-27 14:33:49
|
||||
*/
|
||||
@Service
|
||||
public class GenTemplateServiceImpl extends CrudServiceImpl<GenTemplateMapper, GenTemplate, GenTemplateModel>
|
||||
implements IGenTemplateService {
|
||||
|
||||
@Autowired(required = false)
|
||||
private GenTemplateMapper mapper;
|
||||
@Autowired
|
||||
private IGenTemplateDetailService iGenTemplateDetailService;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public GenTemplateModel insertAndDetail(GenTemplateAndDetailModel model) {
|
||||
if(model == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
GenTemplateModel insertModel = super.insert(
|
||||
WrapperUtil.transformInstance(model, GenTemplateModel.class));
|
||||
|
||||
if(insertModel != null){
|
||||
|
||||
// 保存模型明细
|
||||
List<GenTemplateDetailModel> detailList = model.getDetailList();
|
||||
if(!CollUtil.isEmpty(detailList)){
|
||||
for (GenTemplateDetailModel templateDetailModel : detailList) {
|
||||
templateDetailModel.setParentId(insertModel.getId());
|
||||
iGenTemplateDetailService.insert(templateDetailModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return insertModel;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public GenTemplateModel updateAndDetail(GenTemplateAndDetailModel model) {
|
||||
if(model == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
GenTemplateModel updateModel = super.update(
|
||||
WrapperUtil.transformInstance(model, GenTemplateModel.class));
|
||||
|
||||
if(updateModel != null){
|
||||
|
||||
// 删除子表明细
|
||||
iGenTemplateDetailService.delByParent(model.getId());
|
||||
// 保存模型明细
|
||||
List<GenTemplateDetailModel> detailList = model.getDetailList();
|
||||
if(!CollUtil.isEmpty(detailList)){
|
||||
for (GenTemplateDetailModel templateDetailModel : detailList) {
|
||||
templateDetailModel.setParentId(updateModel.getId());
|
||||
iGenTemplateDetailService.insert(templateDetailModel);
|
||||
}
|
||||
}
|
||||
|
||||
// 删除缓存
|
||||
this.clearCache(Collections.singletonList(
|
||||
updateModel.getId()
|
||||
));
|
||||
}
|
||||
|
||||
return updateModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean delete(String id) {
|
||||
GenTemplateModel base = this.get(id);
|
||||
if (base == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
iGenTemplateDetailService.delByParent(id);
|
||||
|
||||
return this.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean deleteAll(String[] ids) {
|
||||
QueryBuilder<GenTemplate> queryBuilder = new GenQueryBuilder<>();
|
||||
QueryWrapper<GenTemplate> queryWrapper = queryBuilder.build();
|
||||
queryWrapper.in(MyBatisConstants.FIELD_ID, Convert.toList(String.class, ids));
|
||||
|
||||
// 查询数据 抽取Map 字典 便于后续查询
|
||||
List<GenTemplate> baseList = this.findList(queryWrapper);
|
||||
for (GenTemplate base : baseList) {
|
||||
// 先删除子数据
|
||||
iGenTemplateDetailService.delByParent(base.getId());
|
||||
}
|
||||
|
||||
return super.deleteAll(ids);
|
||||
}
|
||||
|
||||
|
||||
// ====================
|
||||
|
||||
|
||||
/**
|
||||
* 清除缓存
|
||||
* @param parentIdList 父级ID集合
|
||||
*/
|
||||
private void clearCache(List<String> parentIdList) {
|
||||
// 删除缓存
|
||||
if (CollUtil.isNotEmpty(parentIdList)) {
|
||||
int cacheCount = 0;
|
||||
for (String parentId : parentIdList) {
|
||||
cacheCount++;
|
||||
boolean tmp = GenTemplateUtil.delAll(parentId);
|
||||
if(tmp){
|
||||
cacheCount--;
|
||||
}
|
||||
}
|
||||
// 判断删除状态
|
||||
if(cacheCount != 0){
|
||||
// 删除缓存失败
|
||||
throw new ServiceException(CoreMsg.CACHE_DEL_EXCEPTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package org.opsli.modulars.generator.template.wrapper;
|
||||
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.opsli.api.base.warpper.ApiWrapper;
|
||||
import org.opsli.common.annotation.validator.Validator;
|
||||
import org.opsli.common.annotation.validator.ValidatorLenMax;
|
||||
import org.opsli.common.enums.ValidatorType;
|
||||
import org.opsli.plugins.excel.annotation.ExcelInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 代码模板 Model
|
||||
*
|
||||
* @author 周鹏程
|
||||
* @date 2021-05-27 14:33:49
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class GenTemplateAndDetailModel extends ApiWrapper {
|
||||
|
||||
|
||||
/** 模板名称 */
|
||||
@ApiModelProperty(value = "模板名称")
|
||||
@ExcelProperty(value = "模板名称", order = 1)
|
||||
@ExcelInfo
|
||||
@Validator({
|
||||
ValidatorType.IS_GENERAL_WITH_CHINESE,
|
||||
ValidatorType.IS_NOT_NULL
|
||||
})
|
||||
@ValidatorLenMax(100)
|
||||
private String tempName;
|
||||
|
||||
/** 表类型 */
|
||||
@ApiModelProperty(value = "表类型")
|
||||
@ExcelProperty(value = "表类型", order = 2)
|
||||
@ExcelInfo( dictType = "table_type" )
|
||||
@Validator({
|
||||
ValidatorType.IS_NOT_NULL
|
||||
})
|
||||
@ValidatorLenMax(30)
|
||||
private String tableType;
|
||||
|
||||
|
||||
/** 备注信息 */
|
||||
@ApiModelProperty(value = "备注信息")
|
||||
@ExcelProperty(value = "备注信息", order = 3)
|
||||
@ExcelInfo
|
||||
@ValidatorLenMax(255)
|
||||
private String remark;
|
||||
|
||||
/** 模板信息 */
|
||||
@ApiModelProperty(value = "模板信息")
|
||||
@ExcelProperty(value = "模板信息", order = 4)
|
||||
@ExcelInfo
|
||||
private List<GenTemplateDetailModel> detailList;
|
||||
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package org.opsli.modulars.generator.template.wrapper;
|
||||
|
||||
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.opsli.api.base.warpper.ApiWrapper;
|
||||
import org.opsli.common.annotation.validator.Validator;
|
||||
import org.opsli.common.annotation.validator.ValidatorLenMax;
|
||||
import org.opsli.common.annotation.validator.ValidatorLenMin;
|
||||
import org.opsli.common.enums.ValidatorType;
|
||||
import org.opsli.plugins.excel.annotation.ExcelInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
/**
|
||||
* 代码模板详情 Model
|
||||
*
|
||||
* @author 周鹏程
|
||||
* @date 2021-05-28 17:12:38
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class GenTemplateDetailModel extends ApiWrapper {
|
||||
|
||||
|
||||
/** 父级ID */
|
||||
@ApiModelProperty(value = "父级ID")
|
||||
@ExcelProperty(value = "父级ID", order = 1)
|
||||
@ExcelInfo
|
||||
@Validator({
|
||||
ValidatorType.IS_NOT_NULL
|
||||
})
|
||||
@ValidatorLenMax(19)
|
||||
private String parentId;
|
||||
|
||||
/** 路径 */
|
||||
@ApiModelProperty(value = "路径")
|
||||
@ExcelProperty(value = "路径", order = 2)
|
||||
@ExcelInfo
|
||||
@Validator({
|
||||
ValidatorType.IS_NOT_NULL
|
||||
})
|
||||
@ValidatorLenMax(255)
|
||||
private String path;
|
||||
|
||||
/** 文件名 */
|
||||
@ApiModelProperty(value = "文件名")
|
||||
@ExcelProperty(value = "文件名", order = 3)
|
||||
@ExcelInfo
|
||||
@Validator({
|
||||
ValidatorType.IS_NOT_NULL
|
||||
})
|
||||
@ValidatorLenMax(100)
|
||||
private String fileName;
|
||||
|
||||
/** 文件内容 */
|
||||
@ApiModelProperty(value = "文件内容")
|
||||
@ExcelProperty(value = "文件内容", order = 4)
|
||||
@ExcelInfo
|
||||
@Validator({
|
||||
ValidatorType.IS_NOT_NULL
|
||||
})
|
||||
@ValidatorLenMax(20000)
|
||||
private String fileContent;
|
||||
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package org.opsli.modulars.generator.template.wrapper;
|
||||
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.opsli.api.base.warpper.ApiWrapper;
|
||||
import org.opsli.common.annotation.validator.Validator;
|
||||
import org.opsli.common.annotation.validator.ValidatorLenMax;
|
||||
import org.opsli.common.annotation.validator.ValidatorLenMin;
|
||||
import org.opsli.common.enums.ValidatorType;
|
||||
import org.opsli.plugins.excel.annotation.ExcelInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
/**
|
||||
* 代码模板 Model
|
||||
*
|
||||
* @author 周鹏程
|
||||
* @date 2021-05-27 14:33:49
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class GenTemplateModel extends ApiWrapper {
|
||||
|
||||
|
||||
/** 模板名称 */
|
||||
@ApiModelProperty(value = "模板名称")
|
||||
@ExcelProperty(value = "模板名称", order = 1)
|
||||
@ExcelInfo
|
||||
@Validator({
|
||||
ValidatorType.IS_GENERAL_WITH_CHINESE,
|
||||
ValidatorType.IS_NOT_NULL
|
||||
})
|
||||
@ValidatorLenMax(100)
|
||||
private String tempName;
|
||||
|
||||
/** 表类型 */
|
||||
@ApiModelProperty(value = "表类型")
|
||||
@ExcelProperty(value = "表类型", order = 2)
|
||||
@ExcelInfo( dictType = "table_type" )
|
||||
@Validator({
|
||||
ValidatorType.IS_NOT_NULL
|
||||
})
|
||||
@ValidatorLenMax(30)
|
||||
private String tableType;
|
||||
|
||||
|
||||
/** 备注信息 */
|
||||
@ApiModelProperty(value = "备注信息")
|
||||
@ExcelProperty(value = "备注信息", order = 3)
|
||||
@ExcelInfo
|
||||
@ValidatorLenMax(255)
|
||||
private String remark;
|
||||
|
||||
}
|
@ -0,0 +1,294 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.plugins.generator.utils;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.comparator.CompareUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.opsli.api.base.result.ResultVo;
|
||||
import org.opsli.api.web.system.dict.DictDetailApi;
|
||||
import org.opsli.api.wrapper.system.dict.DictDetailModel;
|
||||
import org.opsli.api.wrapper.system.dict.DictWrapper;
|
||||
import org.opsli.common.constants.DictConstants;
|
||||
import org.opsli.core.cache.local.CacheUtil;
|
||||
import org.opsli.core.msg.CoreMsg;
|
||||
import org.opsli.core.utils.DictUtil;
|
||||
import org.opsli.core.utils.DistributedLockUtil;
|
||||
import org.opsli.core.utils.ThrowExceptionUtil;
|
||||
import org.opsli.modulars.generator.template.service.IGenTemplateDetailService;
|
||||
import org.opsli.modulars.generator.template.wrapper.GenTemplateDetailModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.opsli.common.constants.OrderConstants.UTIL_ORDER;
|
||||
|
||||
/**
|
||||
* 代码模板
|
||||
*
|
||||
* @author parker
|
||||
* @date 2020-09-22 11:17
|
||||
*/
|
||||
@Slf4j
|
||||
@Order(UTIL_ORDER)
|
||||
@Component
|
||||
@Lazy(false)
|
||||
public class GenTemplateUtil {
|
||||
|
||||
/** 增加初始状态开关 防止异常使用 */
|
||||
private static boolean IS_INIT;
|
||||
|
||||
/** 缓存前缀 NAME */
|
||||
private static final String CACHE_PREFIX_NAME = "gen:template:";
|
||||
|
||||
/** 代码模板明细 Service */
|
||||
private static IGenTemplateDetailService genTemplateDetailService;
|
||||
|
||||
/**
|
||||
* 根据模板ID 模板明细列表
|
||||
* @param parentId 模板ID
|
||||
* @return List
|
||||
*/
|
||||
public static List<GenTemplateDetailModel> getTemplateDetailList(String parentId){
|
||||
// 判断 工具类是否初始化完成
|
||||
ThrowExceptionUtil.isThrowException(!IS_INIT,
|
||||
CoreMsg.OTHER_EXCEPTION_UTILS_INIT);
|
||||
|
||||
// 缓存Key
|
||||
String cacheKey = CACHE_PREFIX_NAME + parentId;
|
||||
|
||||
// 处理集合数据
|
||||
List<GenTemplateDetailModel> wrapperModels = handleDictList(
|
||||
CacheUtil.getHashAll(cacheKey), parentId);
|
||||
if(CollUtil.isNotEmpty(wrapperModels)){
|
||||
return sortWrappers(wrapperModels);
|
||||
}
|
||||
|
||||
// 防止缓存穿透判断
|
||||
boolean hasNilFlag = CacheUtil.hasNilFlag(cacheKey);
|
||||
if(hasNilFlag){
|
||||
return sortWrappers(wrapperModels);
|
||||
}
|
||||
|
||||
try {
|
||||
// 分布式加锁
|
||||
if(!DistributedLockUtil.lock(cacheKey)){
|
||||
// 无法申领分布式锁
|
||||
log.error(CoreMsg.REDIS_EXCEPTION_LOCK.getMessage());
|
||||
return sortWrappers(wrapperModels);
|
||||
}
|
||||
|
||||
// 如果获得锁 则 再次检查缓存里有没有, 如果有则直接退出, 没有的话才发起数据库请求
|
||||
// 处理集合数据
|
||||
wrapperModels = handleDictList(
|
||||
CacheUtil.getHashAll(cacheKey), parentId);
|
||||
if(CollUtil.isNotEmpty(wrapperModels)){
|
||||
return sortWrappers(wrapperModels);
|
||||
}
|
||||
|
||||
|
||||
List<GenTemplateDetailModel> listByParent = genTemplateDetailService.findListByParent(parentId);
|
||||
// 处理数据库查询数据
|
||||
if(CollUtil.isNotEmpty(listByParent)){
|
||||
wrapperModels = listByParent;
|
||||
// 计数器
|
||||
int count = wrapperModels.size();
|
||||
for (GenTemplateDetailModel model : wrapperModels) {
|
||||
// 保存至缓存
|
||||
boolean ret = GenTemplateUtil.put(model);
|
||||
if(ret){
|
||||
count--;
|
||||
}
|
||||
}
|
||||
|
||||
// 回滚 清空缓存
|
||||
if(count != 0){
|
||||
for (GenTemplateDetailModel model : wrapperModels) {
|
||||
GenTemplateUtil.del(model);
|
||||
}
|
||||
}
|
||||
|
||||
return sortWrappers(wrapperModels);
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
log.error(e.getMessage(),e);
|
||||
}finally {
|
||||
// 释放锁
|
||||
DistributedLockUtil.unlock(cacheKey);
|
||||
}
|
||||
|
||||
// 如果值还是 为空 则赋默认值
|
||||
if(CollUtil.isEmpty(wrapperModels)){
|
||||
// 加入缓存防穿透
|
||||
// 设置空变量 用于防止穿透判断
|
||||
CacheUtil.putNilFlag(cacheKey);
|
||||
}
|
||||
|
||||
// 排序
|
||||
return sortWrappers(wrapperModels);
|
||||
}
|
||||
|
||||
/**
|
||||
* 模板排序
|
||||
* @param wrapperModels 字典Model
|
||||
* @return List
|
||||
*/
|
||||
private static List<GenTemplateDetailModel> sortWrappers(List<GenTemplateDetailModel> wrapperModels) {
|
||||
// 非法判读
|
||||
if(wrapperModels == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
return ListUtil.sort(wrapperModels,
|
||||
(o1, o2) -> CompareUtil.compare(o1.getFileName(), o2.getFileName()));
|
||||
}
|
||||
|
||||
|
||||
// ===============
|
||||
|
||||
|
||||
/**
|
||||
* 删除 字典
|
||||
* @param model 字典模型
|
||||
*/
|
||||
private static boolean put(GenTemplateDetailModel model){
|
||||
// 判断 工具类是否初始化完成
|
||||
ThrowExceptionUtil.isThrowException(!IS_INIT,
|
||||
CoreMsg.OTHER_EXCEPTION_UTILS_INIT);
|
||||
|
||||
// 清除缓存
|
||||
GenTemplateUtil.del(model);
|
||||
|
||||
return CacheUtil.putHash(CACHE_PREFIX_NAME + model.getParentId(),
|
||||
model.getId(), model);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 字典
|
||||
* @param model 字典模型
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean del(GenTemplateDetailModel model){
|
||||
// 判断 工具类是否初始化完成
|
||||
ThrowExceptionUtil.isThrowException(!IS_INIT,
|
||||
CoreMsg.OTHER_EXCEPTION_UTILS_INIT);
|
||||
|
||||
if(model == null){
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean hasNilFlag = CacheUtil.hasNilFlag(CACHE_PREFIX_NAME +
|
||||
model.getParentId() + ":" + model.getId());
|
||||
|
||||
GenTemplateDetailModel templateDetailModel = CacheUtil.getHash(GenTemplateDetailModel.class,
|
||||
CACHE_PREFIX_NAME + model.getParentId(),
|
||||
model.getId());
|
||||
|
||||
// 计数器
|
||||
int count = 0;
|
||||
if (hasNilFlag){
|
||||
count++;
|
||||
// 清除空拦截
|
||||
boolean tmp = CacheUtil.delNilFlag(CACHE_PREFIX_NAME +
|
||||
model.getParentId() + ":" + model.getId());
|
||||
if(tmp){
|
||||
count--;
|
||||
}
|
||||
}
|
||||
|
||||
if (templateDetailModel != null){
|
||||
count++;
|
||||
// 清除空拦截
|
||||
boolean tmp = CacheUtil.delHash(CACHE_PREFIX_NAME +
|
||||
model.getParentId(), model.getId());
|
||||
if(tmp){
|
||||
count--;
|
||||
}
|
||||
}
|
||||
|
||||
return count == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 parentId 下所有模板
|
||||
* @param parentId 模板ID
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean delAll(String parentId){
|
||||
// 判断 工具类是否初始化完成
|
||||
ThrowExceptionUtil.isThrowException(!IS_INIT,
|
||||
CoreMsg.OTHER_EXCEPTION_UTILS_INIT);
|
||||
|
||||
List<GenTemplateDetailModel> wrapperList = GenTemplateUtil.getTemplateDetailList(parentId);
|
||||
if(CollUtil.isEmpty(wrapperList)){
|
||||
return true;
|
||||
}
|
||||
|
||||
// 计数器
|
||||
int count = wrapperList.size();
|
||||
for (GenTemplateDetailModel wrapperModel : wrapperList) {
|
||||
boolean tmp = GenTemplateUtil.del(wrapperModel);
|
||||
if(tmp){
|
||||
count--;
|
||||
}
|
||||
}
|
||||
return count == 0;
|
||||
}
|
||||
|
||||
/***
|
||||
* 处理返回模板明细集合
|
||||
* @param tempMap Map
|
||||
* @param id 模板ID
|
||||
* @return List
|
||||
*/
|
||||
public static List<GenTemplateDetailModel> handleDictList(Map<String, Object> tempMap, String id){
|
||||
List<GenTemplateDetailModel> wrapperModels = Lists.newArrayList();
|
||||
if(CollUtil.isNotEmpty(tempMap)){
|
||||
for (Map.Entry<String, Object> entry : tempMap.entrySet()) {
|
||||
// 赋值
|
||||
Object data = entry.getValue();
|
||||
GenTemplateDetailModel templateDetailModel = Convert.convert(GenTemplateDetailModel.class, data);
|
||||
wrapperModels.add(templateDetailModel);
|
||||
}
|
||||
}
|
||||
|
||||
// 返回排序后 list
|
||||
return CollUtil.isNotEmpty(wrapperModels)?sortWrappers(wrapperModels):wrapperModels;
|
||||
}
|
||||
|
||||
|
||||
// ===================================
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
@Autowired
|
||||
public void init(IGenTemplateDetailService genTemplateDetailService) {
|
||||
GenTemplateUtil.genTemplateDetailService = genTemplateDetailService;
|
||||
|
||||
IS_INIT = true;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue