/** * */ package com.zteits.sys.biz; import java.util.List; import java.util.Map; import com.clouds.common.cache.sys.SysCodeValueCacheUtil; import com.google.common.collect.Maps; import com.zteits.clouds.api.apibase.constants.DataStatusEnum; import com.zteits.clouds.api.dto.sys.SysCodeValueDTO; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.alibaba.fastjson.JSON; import com.github.pagehelper.PageInfo; import com.zteits.clouds.api.apibase.bean.BizResult; import com.zteits.clouds.api.apibase.bean.PageBean; import com.zteits.clouds.api.apibase.constants.ErrorType; import com.zteits.clouds.api.apibase.exception.BizException; import com.zteits.clouds.api.dto.sys.DataDicKindDetailDTO; import com.zteits.clouds.api.dto.sys.DataDictionaryKindDTO; import com.zteits.clouds.api.dto.sys.param.DataDicKindDetailRequest; import com.zteits.clouds.api.dto.sys.param.DataDicKindItemObjRequest; import com.zteits.clouds.api.dto.sys.param.DataDictionaryKindListReuest; import com.zteits.clouds.api.dto.sys.param.DataDictionaryKindObjRequest; import com.zteits.clouds.api.dto.sys.param.DeleteDataDicRequest; import com.zteits.clouds.api.service.sys.DataDictionaryService; import com.zteits.sys.dao.SysCodeDefDao; import com.zteits.sys.dao.SysCodeValueDao; import com.zteits.sys.domain.DataDicKindDetailDO; import com.zteits.sys.domain.SysCodeDef; import com.zteits.sys.domain.SysCodeDefExample; import com.zteits.sys.domain.SysCodeValueExample; import com.zteits.sys.domain.SysCodeDefExample.Criteria; import com.zteits.sys.domain.SysCodeValue; import com.zteits.sys.pagepaper.PageBeanUtil; /** * @author hxz * */ @Component public class DataDictionaryServiceImpl implements DataDictionaryService { @Autowired private SysCodeValueDao sysCodeValueDao; @Autowired private SysCodeDefDao sysCodeDefDao; /** * 通过分类编号或者分类名称模糊查询数据字典分类列表 */ @Override public BizResult> getDataDictionaryKindList( DataDictionaryKindListReuest requestObject) { if (null == requestObject) { throw new BizException(ErrorType.PARAMM_NULL, "请求对象为空"); } SysCodeDefExample example = new SysCodeDefExample(); Criteria criteria1 = example.createCriteria(); criteria1.andCodeNameLike(requestObject.getCodeName()); Criteria criteria2 = example.createCriteria(); criteria2.andCodeKindLike(requestObject.getCodeKind()); example.or(criteria2); List sysCodeDefDOList = sysCodeDefDao.getDataDictionaryKindList(example); List dataDictionaryKindDTOList = null; if (null != sysCodeDefDOList) { dataDictionaryKindDTOList = JSON.parseArray(JSON.toJSONString(sysCodeDefDOList, false), DataDictionaryKindDTO.class); } return new BizResult>(dataDictionaryKindDTOList); } /** * 新增一条数据字典大类记录 */ @Override public BizResult insertDataDictionaryKind(DataDictionaryKindObjRequest requestObject) { if (null == requestObject) { throw new BizException(ErrorType.PARAMM_NULL, "请求对象为空"); } SysCodeDef sysCodeDef= new SysCodeDef(); BeanUtils.copyProperties(requestObject, sysCodeDef); return new BizResult (sysCodeDefDao.insertDataDictionaryKind(sysCodeDef)); } /** * 删除一条数据字典大类 */ @Override public BizResult deleteDataDictionaryKindByCodeKind(DeleteDataDicRequest requestObject) { if (null == requestObject) { throw new BizException(ErrorType.PARAMM_NULL, "请求对象为空"); } SysCodeDefExample example = new SysCodeDefExample(); example.createCriteria().andCodeKindEqualTo(requestObject.getCodeKind()); return new BizResult (sysCodeDefDao.deleteDataDictionaryKindByCodeKind(example)); } @Override public BizResult> getDataDictionaryKindDetails(DataDicKindDetailRequest requestObject) { if (null == requestObject) { throw new BizException(ErrorType.PARAMM_NULL, "请求对象为空"); } SysCodeValueExample example = new SysCodeValueExample (); example.createCriteria().andCodeKindEqualTo(requestObject.getCodeKind()).andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()); List sysCodeValueDOList = sysCodeValueDao.getDataDictionaryKindDetails(example); List dataDicKindDetailDTOList = null; if (null != sysCodeValueDOList) { //放入缓存 Map sysCodeDTOs = Maps.newLinkedHashMap(); for (SysCodeValue codeValue : sysCodeValueDOList) { SysCodeValueDTO dto = new SysCodeValueDTO(); BeanUtils.copyProperties(codeValue, dto); sysCodeDTOs.put(codeValue.getCodeValue(),dto); } SysCodeValueCacheUtil.setCodeValues(requestObject.getCodeKind().toUpperCase(),sysCodeDTOs); dataDicKindDetailDTOList = JSON.parseArray(JSON.toJSONString(sysCodeValueDOList, false), DataDicKindDetailDTO.class); } return new BizResult>(dataDicKindDetailDTOList); } @Override public BizResult insertDataDictionaryKindItem(DataDicKindItemObjRequest requestObject) { if (null == requestObject) { throw new BizException(ErrorType.PARAMM_NULL, "请求对象为空"); } SysCodeValue sysCodeValue = new SysCodeValue(); BeanUtils.copyProperties(requestObject, sysCodeValue); return new BizResult (sysCodeValueDao.insertDataDictionaryKindItem(sysCodeValue)); } @Override public BizResult deleteDataDictionaryKindItemByCodeKind(DeleteDataDicRequest requestObject) { if (null == requestObject) { throw new BizException(ErrorType.PARAMM_NULL, "请求对象为空"); } SysCodeValueExample example = new SysCodeValueExample (); example.createCriteria().andCodeKindEqualTo(requestObject.getCodeKind()); return new BizResult (sysCodeValueDao.deleteDataDictionaryKindItemByCodeKind(example)); } @Override public BizResult> getDataDictionaryInfo(DataDictionaryKindListReuest requestObject) { if (null == requestObject.getBaseRequest()) { throw new BizException(ErrorType.PARAMM_NULL, "分页参数为空"); } PageInfo pageInfo = sysCodeValueDao.getDataDictionaryInfo(requestObject); PageBean pageBean = new PageBean(); if (pageInfo != null) { PageBeanUtil.copyProperties(pageInfo, pageBean, DataDicKindDetailDTO.class); } return new BizResult>(pageBean); } }