Blame view

parking-module-system/src/main/java/com/zteits/sys/biz/DataDictionaryServiceImpl.java 6.58 KB
55f68655   王彪总   新项目
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
  /**
   * 
   */
  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<List<DataDictionaryKindDTO>> 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<SysCodeDef> sysCodeDefDOList = sysCodeDefDao.getDataDictionaryKindList(example);
  		List<DataDictionaryKindDTO> dataDictionaryKindDTOList = null;
  		if (null != sysCodeDefDOList) {
  			dataDictionaryKindDTOList = JSON.parseArray(JSON.toJSONString(sysCodeDefDOList, false), DataDictionaryKindDTO.class);
  		}
  		return new BizResult<List<DataDictionaryKindDTO>>(dataDictionaryKindDTOList);
  	}
  
  	/**
  	 * 新增一条数据字典大类记录
  	 */
  	@Override
  	public BizResult<Long> insertDataDictionaryKind(DataDictionaryKindObjRequest requestObject) {
  		if (null == requestObject) {
              throw new BizException(ErrorType.PARAMM_NULL, "请求对象为空");
          }
  		
  		SysCodeDef sysCodeDef= new SysCodeDef();
  		BeanUtils.copyProperties(requestObject, sysCodeDef);
  		
  		return new BizResult<Long> (sysCodeDefDao.insertDataDictionaryKind(sysCodeDef));
  	}
  
  	/**
  	 * 删除一条数据字典大类
  	 */
  	@Override
  	public BizResult<Boolean> deleteDataDictionaryKindByCodeKind(DeleteDataDicRequest requestObject) {
  		if (null == requestObject) {
              throw new BizException(ErrorType.PARAMM_NULL, "请求对象为空");
          }
  		
  		SysCodeDefExample example = new SysCodeDefExample();
  		example.createCriteria().andCodeKindEqualTo(requestObject.getCodeKind());
  	
  		return new BizResult<Boolean> (sysCodeDefDao.deleteDataDictionaryKindByCodeKind(example));
  	}
  
  	@Override
  	public BizResult<List<DataDicKindDetailDTO>> 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<SysCodeValue> sysCodeValueDOList = sysCodeValueDao.getDataDictionaryKindDetails(example);
  		List<DataDicKindDetailDTO> dataDicKindDetailDTOList = null;
  		if (null != sysCodeValueDOList) {
  			//放入缓存
  			Map<String,SysCodeValueDTO> 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<List<DataDicKindDetailDTO>>(dataDicKindDetailDTOList);
  	}
  	
  	@Override
  	public BizResult<Long> insertDataDictionaryKindItem(DataDicKindItemObjRequest requestObject) {
  		if (null == requestObject) {
              throw new BizException(ErrorType.PARAMM_NULL, "请求对象为空");
          }
  		
  		SysCodeValue sysCodeValue = new SysCodeValue();
  		BeanUtils.copyProperties(requestObject, sysCodeValue);
  		
  		return new BizResult<Long> (sysCodeValueDao.insertDataDictionaryKindItem(sysCodeValue));
  	}
  
  	@Override
  	public BizResult<Boolean> deleteDataDictionaryKindItemByCodeKind(DeleteDataDicRequest requestObject) {
  		if (null == requestObject) {
              throw new BizException(ErrorType.PARAMM_NULL, "请求对象为空");
          }
  		
  		SysCodeValueExample example = new SysCodeValueExample ();
  		example.createCriteria().andCodeKindEqualTo(requestObject.getCodeKind());
  		return new BizResult<Boolean> (sysCodeValueDao.deleteDataDictionaryKindItemByCodeKind(example));
  	}
  
  	@Override
  	public BizResult<PageBean<DataDicKindDetailDTO>> getDataDictionaryInfo(DataDictionaryKindListReuest requestObject) {
  		if (null == requestObject.getBaseRequest()) {
  			throw new BizException(ErrorType.PARAMM_NULL, "分页参数为空");
  		}
  		PageInfo<DataDicKindDetailDO> pageInfo = sysCodeValueDao.getDataDictionaryInfo(requestObject);
  		
  		PageBean<DataDicKindDetailDTO> pageBean = new PageBean<DataDicKindDetailDTO>();
  		
  		if (pageInfo != null) {
  			PageBeanUtil.copyProperties(pageInfo, pageBean, DataDicKindDetailDTO.class);
  		}
  		
  		return new BizResult<PageBean<DataDicKindDetailDTO>>(pageBean);
  	}
  
  }