package ${servicePackage}.impl;
|
|
import ${voPackage}.${className}VO;
|
import ${dtoPackage}.${className}DTO;
|
import ${doPackage}.${doClassName};
|
import ${mapperPackage}.${className}DaoI;
|
import ${servicePackage}.${className}ServiceI;
|
#if(${lcStatusFullClassName} !="")
|
import ${lcStatusFullClassName};
|
#end
|
import com.vci.lcstatuspck.FrameworkDataLCStatus;
|
import com.vci.starter.revision.service.RevisionModelUtil;
|
import com.vci.starter.web.exception.VciBaseException;
|
import com.vci.starter.web.pagemodel.*;
|
import com.vci.starter.web.util.*;
|
import com.vci.starter.web.wrapper.*;
|
import com.vci.starter.revision.bo.TreeWrapperOptions;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.stereotype.Service;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import javax.annotation.Resource;
|
import org.springframework.util.CollectionUtils;
|
import org.apache.commons.lang3.StringUtils;
|
|
import java.util.*;
|
import com.vci.web.service.WebBoServiceI;
|
import com.vci.pagemodel.BatchCBO;
|
import static com.vci.constant.FrameWorkLangCodeConstant.*;
|
import static com.vci.frameworkcore.constant.FrameWorkDefaultValueConstant.*;
|
/**
|
* ${comments}服务
|
* @author ${author}
|
* @date ${datetime}
|
*/
|
@Service
|
public class ${className}ServiceImpl implements ${className}ServiceI{
|
|
/**
|
* 日志
|
*/
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
/**
|
* 数据操作层
|
*/
|
@Resource
|
private ${className}DaoI ${classNameFristLowwer}Mapper;
|
|
/**
|
* 业务类型操作的服务
|
*/
|
@Autowired
|
private WebBoServiceI boService;
|
|
/**
|
* 对象的操作
|
*/
|
@Autowired
|
private RevisionModelUtil revisionModelUtil;
|
|
|
#if(!${hasParentField})
|
/**
|
* 查询所有的${comments}
|
* @param conditionMap 查询条件
|
* @param pageHelper 分页和排序
|
* @return 执行结果
|
* @throws VciBaseException 查询条件和分页出错的时候会抛出异常
|
*/
|
@Override
|
public DataGrid<${className}VO> grid${className}(Map<String, String> conditionMap, PageHelper pageHelper) throws VciBaseException{
|
if (pageHelper == null) {
|
pageHelper = new PageHelper(-1);
|
}
|
pageHelper.addDefaultDesc("createTime");
|
List<${className}DO> doList = ${classNameFristLowwer}Mapper.selectByCondition(conditionMap,pageHelper);
|
DataGrid<${className}VO> dataGrid=new DataGrid<${className}VO>();
|
if (!CollectionUtils.isEmpty(doList)) {
|
dataGrid.setData(${classNameFristLowwer}DO2VOs(doList));
|
dataGrid.setTotal(VciBaseUtil.getInt(String.valueOf(${classNameFristLowwer}Mapper.countByCondition(conditionMap))));
|
}
|
return dataGrid;
|
}
|
#else
|
/**
|
* 上级节点的属性名称
|
*/
|
private static final String PARENT_FIELD_NAME = "${parentFieldName}";
|
/**
|
* 查询${comments} 树
|
* @param treeQueryObject 树查询对象
|
* @return ${comments} 显示树
|
* @throws VciBaseException 查询条件不符合要求的时候会抛出异常
|
*/
|
@Override
|
public List<Tree> tree${className}(TreeQueryObject treeQueryObject) throws VciBaseException{
|
List<${className}DO> doList =select${className}DOByTree(treeQueryObject);
|
List<${className}VO> voList = ${classNameFristLowwer}DO2VOs(doList);
|
TreeWrapperOptions treeWrapperOptions = new TreeWrapperOptions(PARENT_FIELD_NAME);
|
treeWrapperOptions.copyFromTreeQuery(treeQueryObject);
|
return revisionModelUtil.doList2Trees(voList,treeWrapperOptions,(${className}VO s) ->{
|
//可以在这里处理树节点的显示
|
return s.getId() + " " + s.getName() + (FrameworkDataLCStatus.DISABLED.getValue().equalsIgnoreCase(s
|
.getLcStatus()) ? (" 【停用】 ") : "");
|
});
|
}
|
/**
|
* 根据树形查询对象来查询数据对象
|
*
|
* @param treeQueryObject 树形查询对象
|
* @return 查询结果,数据对象
|
*/
|
@Override
|
public List<${className}DO> select${className}DOByTree(TreeQueryObject treeQueryObject) {
|
VciQueryWrapperForDO queryWrapperForDO = new VciQueryWrapperForDO(null,${className}DO.class);
|
VciParentQueryOption parentQueryOption = new VciParentQueryOption();
|
parentQueryOption.setParentFieldName(PARENT_FIELD_NAME);
|
queryWrapperForDO.parentQueryChild(treeQueryObject,parentQueryOption);
|
return ${classNameFristLowwer}Mapper.selectByWrapper(queryWrapperForDO);
|
}
|
#end
|
|
/**
|
* 批量数据对象转换为显示对象
|
* @param ${classNameFristLowwer}DOs 数据对象列表
|
* @return 显示对象
|
* @throws VciBaseException 参数为空或者不存在的时候会抛出异常
|
*/
|
@Override
|
public List<${className}VO> ${classNameFristLowwer}DO2VOs(Collection<${className}DO> ${classNameFristLowwer}DOs) throws VciBaseException{
|
List<${className}VO> voList = new ArrayList<${className}VO>();
|
if(!CollectionUtils.isEmpty(${classNameFristLowwer}DOs)){
|
for(${className}DO s: ${classNameFristLowwer}DOs){
|
${className}VO vo = ${classNameFristLowwer}DO2VO(s);
|
if(vo != null){
|
voList.add(vo);
|
}
|
}
|
}
|
return voList;
|
}
|
|
/**
|
* 数据对象转换为显示对象
|
* @param ${classNameFristLowwer}DO 数据对象
|
* @return 显示对象
|
* @throws VciBaseException 拷贝属性出错的时候会抛出异常
|
*/
|
@Override
|
public ${className}VO ${classNameFristLowwer}DO2VO(${className}DO ${classNameFristLowwer}DO) throws VciBaseException{
|
${className}VO vo = new ${className}VO();
|
if(${classNameFristLowwer}DO != null){
|
BeanUtilForVCI.copyPropertiesIgnoreCase(${classNameFristLowwer}DO,vo);
|
//如果有lcstatus的类的话
|
#if(${hasStatus})
|
vo.setLcStatusText(${lcStatusFullClassName}.getTextByValue(vo.getLcStatus()));
|
#end
|
|
}
|
return vo;
|
}
|
|
/**
|
* 增加${comments}
|
* @param ${classNameFristLowwer}DTO ${comments}数据传输对象
|
* @return 执行结果
|
* @throws VciBaseException 参数为空,唯一项,必输项不通过时会抛出异常
|
*/
|
@Override
|
public ${className}VO addSave(${className}DTO ${classNameFristLowwer}DTO) throws VciBaseException{
|
VciBaseUtil.alertNotNull(${classNameFristLowwer}DTO,"需要添加的数据对象");
|
//将DTO转换为DO
|
${className}DO ${classNameFristLowwer}DO = new ${className}DO();
|
BeanUtilForVCI.copyPropertiesIgnoreCase(${classNameFristLowwer}DTO,${classNameFristLowwer}DO);
|
${classNameFristLowwer}Mapper.insert(${classNameFristLowwer}DO);
|
return ${classNameFristLowwer}DO2VO(${classNameFristLowwer}DO);
|
}
|
|
/**
|
* 修改${comments}
|
* @param ${classNameFristLowwer}DTO ${comments}数据传输对象
|
* @return 执行结果
|
* @throws VciBaseException 参数为空,唯一项,必输项不通过时会抛出异常
|
*/
|
@Override
|
public ${className}VO editSave(${className}DTO ${classNameFristLowwer}DTO) throws VciBaseException{
|
VciBaseUtil.alertNotNull(${classNameFristLowwer}DTO,"数据对象",${classNameFristLowwer}DTO.getOid(),"${comments}主键");
|
//将DTO转换为DO
|
${className}DO ${classNameFristLowwer}DO = selectByOid(${classNameFristLowwer}DTO.getOid());
|
revisionModelUtil.copyFromDTOIgnore(${classNameFristLowwer}DTO,${classNameFristLowwer}DO);
|
${classNameFristLowwer}Mapper.updateByPrimaryKey(${classNameFristLowwer}DO);
|
return ${classNameFristLowwer}DO2VO(${classNameFristLowwer}DO);
|
}
|
|
#if(${hasParentField})
|
/**
|
* 检查 ${comments}是否删除
|
* @param ${classNameFristLowwer}DTO ${comments}数据传输对象,必须要有oid和ts属性
|
* @return 执行结果 success为true为可以删除,false表示有数据引用,obj为true表示有下级
|
* @throws VciBaseException 参数为空,被引用时抛出异常
|
*/
|
@Override
|
public BaseResult checkIsCanDelete(${className}DTO ${classNameFristLowwer}DTO) throws VciBaseException{
|
VciBaseUtil.alertNotNull(${classNameFristLowwer}DTO,"数据传输对象",${classNameFristLowwer}DTO.getOid(),"主键");
|
${className}DO ${classNameFristLowwer}DO = selectByOid(${classNameFristLowwer}DTO.getOid());
|
return checkIsCanDeleteForDO(${classNameFristLowwer}DTO,${classNameFristLowwer}DO);
|
}
|
#end
|
|
/**
|
* 校验是否可以删除,如果存在下级,并且下级有数据引用则不能删除
|
* @param ${classNameFristLowwer}DTO 数据传输对象
|
* @param ${classNameFristLowwer}DO 数据库中的数据对象
|
* @return success为true为可以删除,false表示有数据引用,obj为true表示有下级
|
*/
|
private BaseResult checkIsCanDeleteForDO(${className}DTO ${classNameFristLowwer}DTO, ${className}DO ${classNameFristLowwer}DO) {
|
${className}DO tsDO = new ${className}DO();
|
BeanUtilForVCI.copyPropertiesIgnoreCase(${classNameFristLowwer}DTO,tsDO);
|
boService.checkTs(tsDO);
|
#if(${hasParentField})
|
//校验下级是否有引用
|
if(checkChildIsLinked(${classNameFristLowwer}DO.getOid())){
|
return BaseResult.fail(DATA_CASCADE_LINKED_NOT_DELETE,new String[]{""});
|
}
|
return BaseResult.success(checkHasChild(${classNameFristLowwer}DO.getOid()));
|
#end
|
#if(!${hasParentField})
|
if(!checkIsLinked(${classNameFristLowwer}DO.getOid())) {
|
return BaseResult.success();
|
}else{
|
return BaseResult.fail(DATA_LINKED_NOT_DELETE,new String[]{""});
|
}
|
#end
|
}
|
#if(${hasParentField})
|
/**
|
* 检查是否有下级是否关联了数据
|
*
|
* @param oid 主键
|
* @return true 表示有引用,false表示没有引用
|
* @throws VciBaseException 参数为空和有引用的时候会抛出异常
|
*/
|
@Override
|
public boolean checkChildIsLinked(String oid) throws VciBaseException {
|
VciBaseUtil.alertNotNull(oid,"主键");
|
List<String> childOids = ${classNameFristLowwer}Mapper.selectAllLevelChildOid(oid.trim());
|
if(!CollectionUtils.isEmpty(childOids)){
|
for(String childOid: childOids){
|
if(!checkIsLinked(childOid)){
|
return false;
|
}
|
}
|
return true;
|
}
|
return false;
|
}
|
|
/**
|
* 校验是否有下级节点,不校验是否关联了数据
|
*
|
* @param oid 主键
|
* @return true表示有下级,false表示没有下级
|
* @throws VciBaseException 参数错误,或者数据不存在的时候会抛出异常
|
*/
|
@Override
|
public boolean checkHasChild(String oid) throws VciBaseException {
|
VciBaseUtil.alertNotNull(oid,"主键");
|
return ${classNameFristLowwer}Mapper.countAllLevelChildOid(oid.trim()) > 0;
|
}
|
#end
|
|
/**
|
* 校验是否被引用
|
* @param oid 主键
|
* @throws VciBaseException 被引用的时候会抛出异常
|
*/
|
private boolean checkIsLinked(String oid) throws VciBaseException{
|
//TODO 添加需要校验引用的地方
|
return false;
|
}
|
|
/**
|
* 删除${comments}
|
* @param ${classNameFristLowwer}DTO ${comments}数据传输对象,oid和ts需要传输
|
* @return 删除结果反馈::success:成功,fail:失败
|
* @throws VciBaseException 参数为空,被引用时抛出异常
|
*/
|
@Override
|
public BaseResult delete${className}(${className}DTO ${classNameFristLowwer}DTO) throws VciBaseException{
|
VciBaseUtil.alertNotNull(${classNameFristLowwer}DTO,"${comments}数据对象",${classNameFristLowwer}DTO.getOid(),"${comments}的主键");
|
${className}DO ${classNameFristLowwer}DO = selectByOid(${classNameFristLowwer}DTO.getOid());
|
BaseResult baseResult = checkIsCanDeleteForDO(${classNameFristLowwer}DTO,${classNameFristLowwer}DO);
|
if(baseResult.isSuccess()) {
|
#if(${hasParentField})
|
//找下级的,这个是可以删除的时候
|
List<String> childrenOids = ${classNameFristLowwer}Mapper.selectAllLevelChildOid(${classNameFristLowwer}DO.getOid().trim());
|
if (!CollectionUtils.isEmpty(childrenOids)) {
|
Collection<Collection<String>> childrenCollections = VciBaseUtil.switchCollectionForOracleIn(childrenOids);
|
for(Collection<String> s : childrenCollections){
|
${classNameFristLowwer}Mapper.batchDeleteByOids(s);
|
}
|
}
|
#end
|
}else{
|
return baseResult;
|
}
|
//执行删除操作
|
BatchCBO batchCBO = ${classNameFristLowwer}Mapper.deleteByPrimaryKey(${classNameFristLowwer}DO.getOid());
|
return (batchCBO!=null && batchCBO.getDeleteCbos() !=null &&batchCBO.getDeleteCbos().size() > 0)?BaseResult.successMsg(DELETE_SUCCESS):BaseResult.fail(DELETE_FAIL);
|
}
|
|
/**
|
* 主键获取${comments}
|
* @param oid 主键
|
* @return ${comments}显示对象
|
* @throws VciBaseException 参数为空,数据不存在时会抛出异常
|
*/
|
@Override
|
public ${className}VO getObjectByOid(String oid) throws VciBaseException{
|
return ${classNameFristLowwer}DO2VO(selectByOid(oid));
|
}
|
|
/**
|
* 主键查询数据对象
|
* @param oid 主键
|
* @return 数据对象
|
* @throws VciBaseException 参数为空,并且数据不存在的时候会抛出异常
|
*/
|
private ${className}DO selectByOid(String oid) throws VciBaseException{
|
VciBaseUtil.alertNotNull(oid,"主键");
|
${className}DO ${classNameFristLowwer}DO = ${classNameFristLowwer}Mapper.selectByPrimaryKey(oid.trim());
|
if(${classNameFristLowwer}DO == null || StringUtils.isBlank(${classNameFristLowwer}DO.getOid())){
|
throw new VciBaseException(DATA_OID_NOT_EXIST);
|
}
|
return ${classNameFristLowwer}DO;
|
}
|
|
/**
|
* 主键批量获取${comments}
|
* @param oidCollections 主键集合,但是受性能影响,建议一次查询不超过10000个
|
* @return ${comments}显示对象
|
* @throws VciBaseException 查询出现异常时会抛出
|
*/
|
@Override
|
public Collection<${className}VO> list${className}ByOids(Collection<String> oidCollections) throws VciBaseException{
|
VciBaseUtil.alertNotNull(oidCollections,"数据对象主键集合");
|
List<${className}DO> ${classNameFristLowwer}DOList = list${className}DOByOidCollections(oidCollections);
|
return ${classNameFristLowwer}DO2VOs(${classNameFristLowwer}DOList);
|
}
|
|
/**
|
* 使用主键集合查询数据对象
|
* @param oidCollections 主键的集合
|
* @return 数据对象列表
|
*/
|
private List<${className}DO> list${className}DOByOidCollections(Collection<String> oidCollections){
|
List<${className}DO> ${classNameFristLowwer}DOList = new ArrayList<${className}DO>();
|
if(!CollectionUtils.isEmpty(oidCollections)){
|
Collection<Collection<String>> oidCollectionsList = VciBaseUtil.switchCollectionForOracleIn(oidCollections);
|
for(Collection<String> oids: oidCollectionsList){
|
List<${className}DO> tempDOList = ${classNameFristLowwer}Mapper.selectByPrimaryKeyCollection(oids);
|
if(!CollectionUtils.isEmpty(tempDOList)){
|
${classNameFristLowwer}DOList.addAll(tempDOList);
|
}
|
}
|
}
|
return ${classNameFristLowwer}DOList;
|
}
|
|
#if(${hasEnable})
|
/**
|
* 启用${comments}
|
* @param ${classNameFristLowwer}DTO ${comments}数据传输对象,oid和ts需要传输
|
#if(${hasParentField})
|
* @param cascade 级联启用
|
#end
|
* @return 启用结果反馈::success:成功,fail:失败
|
* @throws VciBaseException 执行出现异常时会抛出
|
*/
|
@Override
|
public BaseResult enable${className}(${className}DTO ${classNameFristLowwer}DTO#if(${hasParentField}),boolean cascade #end) throws VciBaseException{
|
return changeLcStatus(${classNameFristLowwer}DTO,false#if(${hasParentField}),cascade#end);
|
}
|
|
/**
|
* 停用{comments}
|
* @param ${classNameFristLowwer}DTO ${comments}数据传输对象,oid和ts需要传输
|
#if(${hasParentField})
|
* @param cascade 级联停用
|
#end
|
* @return 停用结果反馈::success:成功,fail:失败
|
* @throws VciBaseException 执行出现异常时会抛出
|
*/
|
@Override
|
public BaseResult disable${className}(${className}DTO ${classNameFristLowwer}DTO#if(${hasParentField}),boolean cascade #end) throws VciBaseException{
|
return changeLcStatus(${classNameFristLowwer}DTO,true#if(${hasParentField}),cascade#end);
|
}
|
|
/**
|
* 修改生命周期的状态,如停用和启用
|
* @param ${classNameFristLowwer}DTO ${comments}数据传输对象,必须要有oid和ts
|
* @param disable 是否为停用
|
#if(${hasParentField})
|
* @param cascade 是否级联操作下级节点
|
#end
|
* @return 执行的结果
|
*/
|
private BaseResult changeLcStatus(${className}DTO ${classNameFristLowwer}DTO,boolean disable#if(${hasParentField}),boolean cascade#end){
|
VciBaseUtil.alertNotNull(${classNameFristLowwer}DTO,"数据对象",${classNameFristLowwer}DTO.getOid(),"主键");
|
${className}DO ${classNameFristLowwer}DO = selectByOid(${classNameFristLowwer}DTO.getOid());
|
boService.checkTs(${classNameFristLowwer}DTO.getTs());
|
if(disable){
|
${classNameFristLowwer}DO.setLcStatus(FrameworkDataLCStatus.DISABLED.getValue());
|
}else{
|
${classNameFristLowwer}DO.setLcStatus(FrameworkDataLCStatus.ENABLED.getValue());
|
}
|
#if(${hasParentField})
|
//我们要取所有的下级,然后去判断是否被引用
|
if(cascade) {
|
List<String> childrenOids = ${classNameFristLowwer}Mapper.selectAllLevelChildOid(${classNameFristLowwer}DO.getOid().trim());
|
if (!CollectionUtils.isEmpty(childrenOids)) {
|
Collection<Collection<String>> oidCollectionsList = WebUtil.switchCollectionForOracleIn(childrenOids);
|
for(Collection<String> oids: oidCollectionsList){
|
${classNameFristLowwer}Mapper.batchUpdateLcStatus(oids,${classNameFristLowwer}DO.getLcStatus());
|
}
|
}
|
}
|
#end
|
return (${classNameFristLowwer}Mapper.updateLcStatus(${classNameFristLowwer}DO.getOid(),${classNameFristLowwer}DO.getLcStatus()) >0 )?(BaseResult.successMsg((disable?DISABLE_SUCCESS:ENABLE_SUCCESS))):(BaseResult.fail((disable?DISABLE_FAIL:ENABLE_FAIL)));
|
}
|
#end
|
|
|
#if(!${hasParentField})
|
/**
|
* 参照${comments}列表
|
* @param conditionMap 查询条件
|
* @param pageHelper 分页和排序
|
* @return ${comments}显示对象列表,生效的内容
|
* @throws VciBaseException 查询条件和分页出错的时候会抛出异常
|
*/
|
@Override
|
public DataGrid<${className}VO> refDataGrid${className}(Map<String, String> conditionMap, PageHelper pageHelper) throws VciBaseException{
|
if(conditionMap == null){
|
conditionMap = new HashMap<String, String>();
|
}
|
#if(${hasEnable})
|
if(conditionMap.containsKey(LC_STATUS)) {
|
conditionMap.remove(LC_STATUS);
|
}
|
conditionMap.put(LC_STATUS, FRAMEWORK_DATA_ENABLED);
|
#end
|
return grid${className}(conditionMap,pageHelper);
|
}
|
#else
|
/**
|
* 参照树 ${comments}
|
* @param treeQueryObject 树形查询对象
|
* @return ${comments}显示树
|
* @throws VciBaseException 查询条件和分页出错的时候会抛出异常
|
*/
|
@Override
|
public List<Tree> referTree(TreeQueryObject treeQueryObject) throws VciBaseException{
|
if(treeQueryObject == null){
|
treeQueryObject = new TreeQueryObject();
|
}
|
if(treeQueryObject.getConditionMap() == null){
|
treeQueryObject.setConditionMap(new HashMap<>());
|
}
|
if(treeQueryObject.getConditionMap().containsKey(LC_STATUS)) {
|
treeQueryObject.getConditionMap().remove(LC_STATUS);
|
}
|
#if(${hasEnable})
|
if(treeQueryObject.getExtandParamsMap() ==null || !treeQueryObject.getExtandParamsMap().containsKey(REFER_SHOW_DISABLED_QUERY_KEY)) {
|
treeQueryObject.getConditionMap().put(LC_STATUS, FRAMEWORK_DATA_ENABLED);
|
}
|
#end
|
return tree${className}(treeQueryObject);
|
}
|
#end
|
}
|