ParkingLotGroupServiceImpl.java
8.17 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package com.zteits.park.biz.parkgroup;
import com.clouds.common.utils.ListCopyUtil;
import com.clouds.common.utils.SequenceUtil;
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.DataStatusEnum;
import com.zteits.clouds.api.apibase.constants.ErrorType;
import com.zteits.clouds.api.apibase.exception.BizException;
import com.zteits.clouds.api.dto.park.dto.ParkingLotDTO;
import com.zteits.clouds.api.dto.park.dto.parkgroup.ParkingLotGroupDTO;
import com.zteits.clouds.api.dto.park.dto.parkgroup.ParkingLotGroupRelDTO;
import com.zteits.clouds.api.dto.park.param.parkgroup.ParkingLotGroupQueryReq;
import com.zteits.clouds.api.dto.park.param.parkgroup.ParkingLotGroupSaveReq;
import com.zteits.clouds.api.dto.park.param.parkgroup.SaveGroupRelReq;
import com.zteits.clouds.api.service.park.parkgroup.ParkingLotGroupService;
import com.zteits.park.dao.ParkingLotGroupDao;
import com.zteits.park.dao.ParkingLotGroupRelDao;
import com.zteits.park.domain.ParkingLotGroup;
import com.zteits.park.domain.ParkingLotGroupExample;
import com.zteits.park.domain.ParkingLotGroupRel;
import com.zteits.park.domain.ParkingLotGroupRelExample;
import com.zteits.park.mapper.ParkingLotGroupMapper;
import com.zteits.park.mapper.ParkingLotGroupRelMapper;
import com.zteits.park.pagepager.PageBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
/**
* Copyright: Copyright (c) 2017 zteits
*
* @ClassName: ParkingLotGroupServiceImpl.java
* @Description:
* @version: v1.0.0
* @author: wangfs
* @date: 2021-04-19 10:53
* Modification History:
* Date Author Version Description
* ---------------------------------------------------------*
* 2021-04-19 wangfs v1.0.0 创建
*/
@Service("com.zteits.park.biz.parkgroup.ParkingLotGroupServiceImpl")
public class ParkingLotGroupServiceImpl implements ParkingLotGroupService {
@Autowired
private ParkingLotGroupDao parkingLotGroupDao;
@Autowired
private ParkingLotGroupRelDao parkingLotGroupRelDao;
@Autowired
private ParkingLotGroupMapper parkingLotGroupMapper;
@Autowired
private ParkingLotGroupRelMapper parkingLotGroupRelMapper;
/**
* 车场组
*
* @param
* @return
* @Auther: wangfs
*/
@Transactional(rollbackFor = Exception.class)
@Override
public BizResult<Boolean> saveParkingLotGroup(ParkingLotGroupSaveReq req) {
Long parkGroupNo = SequenceUtil.getNextId();
req.setPlGroupNo(parkGroupNo + "");
Boolean aBoolean = this.parkGroupNameExist(req.getPlGroupName());
if (aBoolean) {
throw new BizException(ErrorType.OBJECT_EXISTS, "组名称已经存在!");
}
Integer integer = parkingLotGroupDao.saveParkingLotGroup(req);
return new BizResult<Boolean>(integer > 0);
}
@Override
public BizResult<Boolean> updateParkingLotGroupById(ParkingLotGroupSaveReq req) {
if (req == null || req.getId() == null) {
throw new BizException(ErrorType.PARAMM_NULL, "id为空!");
}
Boolean aBoolean = this.parkGroupNameExist(req.getPlGroupName());
if (aBoolean) {
throw new BizException(ErrorType.OBJECT_EXISTS, "组名称已经存在!");
}
Integer integer = parkingLotGroupDao.updateParkingLotGroup(req);
return new BizResult<Boolean>(integer > 0);
}
@Transactional(rollbackFor = Exception.class)
@Override
public BizResult<Boolean> deleteParkingLotGroupById(ParkingLotGroupSaveReq req) {
if (req == null || req.getId() == null) {
throw new BizException(ErrorType.PARAMM_NULL, "id为空!");
}
ParkingLotGroup parkingLotGroup = parkingLotGroupMapper.selectByPrimaryKey(req.getId());
parkingLotGroupMapper.deleteByPrimaryKey(req.getId());
ParkingLotGroupRelExample example = new ParkingLotGroupRelExample();
example.createCriteria().andPlGroupNoEqualTo(parkingLotGroup.getPlGroupNo());
int i = parkingLotGroupRelMapper.deleteByExample(example);
return new BizResult<Boolean>(i > 0);
}
private Boolean parkGroupNameExist(String groupName) {
Boolean flg = false;
ParkingLotGroupExample example = new ParkingLotGroupExample();
example.createCriteria().andDataStatusEqualTo(1).andPlGroupNameEqualTo(groupName);
List<ParkingLotGroup> parkingLotGroups = parkingLotGroupMapper.selectByExample(example);
if (!CollectionUtils.isEmpty(parkingLotGroups) && parkingLotGroups.size() > 0) {
flg = true;
}
return flg;
}
@Override
public BizResult<PageBean<ParkingLotGroupDTO>> queryParkGroupForPage(ParkingLotGroupSaveReq request) {
PageBean<ParkingLotGroupDTO> pageBean = new PageBean<ParkingLotGroupDTO>();
PageInfo<ParkingLotGroup> pageInfo = parkingLotGroupDao.queryParkGroupForPage(request);
PageBeanUtil.copyProperties(pageInfo, pageBean, ParkingLotGroupDTO.class);
this.ParkingLotGroupRelDao(pageBean);
return new BizResult<PageBean<ParkingLotGroupDTO>>(pageBean);
}
/**
* 保存车场关系表
*
* @param
* @return
* @Auther: wangfs
*/
@Transactional(rollbackFor = Exception.class)
@Override
public BizResult<Boolean> saveGroupRelReq(SaveGroupRelReq req) {
if (req == null || req.getPlGroupNo() == null) {
throw new BizException(ErrorType.PARAMM_NULL, "plGroupNo为空!");
}
Boolean flg = parkingLotGroupRelDao.saveGroupRelReq(req);
return new BizResult<Boolean>(flg);
}
@Override
public BizResult<List<ParkingLotGroupDTO>> queryParkGroupForList(ParkingLotGroupSaveReq request) {
List<ParkingLotGroupDTO> listDTO = new ArrayList<>();
ParkingLotGroupExample example = new ParkingLotGroupExample();
example.createCriteria().andDataStatusEqualTo(1).andOrgIdEqualTo(request.getOrgId()).andParkNumGreaterThan(0);
List<ParkingLotGroup> parkingLotGroups = parkingLotGroupMapper.selectByExample(example);
ListCopyUtil.listCopyProperties(parkingLotGroups, listDTO, ParkingLotGroupDTO.class);
return new BizResult<List<ParkingLotGroupDTO>>(listDTO);
}
@Override
public BizResult<List<ParkingLotDTO>> queryParkGroupForListByplGroupNo(ParkingLotGroupQueryReq request) {
ParkingLotGroupRelExample example = new ParkingLotGroupRelExample();
example.createCriteria().andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value())
.andPlGroupNoEqualTo(request.getPlGroupNo());
List<ParkingLotGroupRel> parkingLotGroupRels = parkingLotGroupRelMapper.selectByExample(example);
List<ParkingLotDTO> parkingLotDTOS = new ArrayList<>();
if (CollectionUtils.isEmpty(parkingLotGroupRels)) {
return new BizResult<>(parkingLotDTOS);
}
ListCopyUtil.listCopyProperties(parkingLotGroupRels,parkingLotDTOS,ParkingLotDTO.class);
return new BizResult<>(parkingLotDTOS);
}
private void ParkingLotGroupRelDao(PageBean<ParkingLotGroupDTO> pageBean) {
if (null != pageBean && !CollectionUtils.isEmpty(pageBean.getDataList())) {
List<ParkingLotGroupDTO> dataList = pageBean.getDataList();
for (ParkingLotGroupDTO parkingLotGroupDTO : dataList) {
if (null == parkingLotGroupDTO || StringUtils.isEmpty(parkingLotGroupDTO.getPlGroupNo())) {
continue;
}
List<ParkingLotGroupRelDTO> listDTO = new ArrayList<>();
List<ParkingLotGroupRel> parkingLotGroupRels = parkingLotGroupRelDao.queryParkingLotGroupRelByGroupCodeId(parkingLotGroupDTO.getPlGroupNo());
ListCopyUtil.listCopyProperties(parkingLotGroupRels, listDTO, ParkingLotGroupRelDTO.class);
parkingLotGroupDTO.setGroupRelList(listDTO);
}
}
}
}