com.ape9527.core.service.BaseObjFieldService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ape-core Show documentation
Show all versions of ape-core Show documentation
Ape low code platform core module
The newest version!
package com.ape9527.core.service;
import com.ape9527.core.constant.Const;
import com.ape9527.core.entity.BaseObj;
import com.ape9527.core.entity.BaseObjField;
import com.ape9527.core.mapper.BaseObjFieldMapper;
import com.ape9527.core.mapper.BaseObjMapper;
import com.ape9527.core.model.AjaxResult;
import com.ape9527.core.model.base.CorrelatedBaseObj;
import com.ape9527.utils.string.StringUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 基础数据对象属性操作业务层
*
* @author YuanShuai[[email protected]]
*/
@Service
public class BaseObjFieldService {
private final BaseObjFieldMapper mapper;
public BaseObjFieldService(BaseObjFieldMapper mapper) {
this.mapper = mapper;
}
/**
* 查询数据对象属性列表
*
* @param field 参数
* @return 数据对象列表
*/
public List queryList(BaseObjField field) {
return mapper.selectList(field);
}
/**
* 分页查询数据对象属性列表
*
* @param field 参数
* @param pageNum 页码
* @param pageSize 每页大小
* @return 数据对象列表分页对象
*/
public PageInfo queryListByPage(BaseObjField field, Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
List baseObjFields = queryList(field);
return new PageInfo<>(baseObjFields);
}
/**
* 根据ID查询数据对象属性
*
* @param uuid 数据对象属性唯一ID
* @return 数据对象属性
*/
public BaseObjField queryById(String uuid) {
return mapper.selectById(uuid);
}
/**
* 保存数据对象属性
* 数据对象编码相同时,属性编码不允许重复
*
* @param field 数据对象属性
* @return 是否保存成功
*/
@Transactional(rollbackFor = Exception.class)
public AjaxResult save(BaseObjField field) {
int i;
BaseObjField dbBaseObjField = mapper.selectByFieldCode(field.getObjCode(), field.getFieldCode());
if (StringUtil.isEmpty(field.getUuid())) {
if (dbBaseObjField != null) {
return AjaxResult.error("数据对象属性编码不允许重复," + field.getObjCode() + "-" + field.getFieldCode() + "已存在");
}
field.setIsBaseObj(Const.BASE_OBJ.equals(field.getFieldType()));
i = mapper.insert(field);
// 新增表字段
if (Const.BASE_OBJ.equals(field.getFieldType())) {
field.setFieldType("varchar");
field.setFieldLength("32");
field.setDecimalDigits("0");
field.setDefaultValue("");
field.setIsBaseObj(true);
}
mapper.insertColumn(field);
} else {
if (dbBaseObjField != null && !dbBaseObjField.getUuid().equals(field.getUuid())) {
return AjaxResult.error("数据对象属性编码不允许重复," + field.getObjCode() + "-" + field.getFieldCode() + "已存在");
}
final BaseObjField oldField = mapper.selectById(field.getUuid());
field.setIsBaseObj(Const.BASE_OBJ.equals(field.getFieldType()));
i = mapper.update(field);
// 修改表字段
if (Const.BASE_OBJ.equals(field.getFieldType())) {
field.setFieldType("varchar");
field.setFieldLength("32");
field.setDecimalDigits("0");
field.setDefaultValue("");
field.setIsBaseObj(true);
}
mapper.updateColumn(oldField.getFieldCode(), field);
}
return i == 1 ? AjaxResult.success() : AjaxResult.error();
}
/**
* 根据ID对数据对象属性进行逻辑删除
*
* @param uuid 数据对象属性唯一ID
* @return 是否删除成功
*/
public boolean delById(String uuid) {
String[] uuids = {uuid};
return delByIds(uuids);
}
/**
* 根据ID数组对多个数据对象属性进行逻辑删除
*
* @param uuids 数据对象属性唯一ID
* @return 是否删除成功
*/
@Transactional(rollbackFor = Exception.class)
public boolean delByIds(String[] uuids) {
List