TpPRegionAreaDaoImpl.java
6.21 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
package com.zteits.park.dao.impl;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import com.clouds.common.constants.ParkConstant.OptFlag;
import com.clouds.common.utils.SequenceUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.xiaoleilu.hutool.util.CollectionUtil;
import com.zteits.clouds.api.apibase.constants.DataStatusEnum;
import com.zteits.clouds.api.apibase.constants.ErrorType;
import com.zteits.clouds.api.apibase.constants.SequenceTypeEnum;
import com.zteits.clouds.api.apibase.exception.BizException;
import com.zteits.park.dao.TpPRegionAreaDao;
import com.zteits.park.domain.TpPRegionArea;
import com.zteits.park.domain.TpPRegionAreaDO;
import com.zteits.park.domain.TpPRegionAreaExample;
import com.zteits.park.domain.TpPRegionAreaExample.Criteria;
import com.zteits.park.mapper.TpPRegionAreaMapper;
import com.zteits.park.mapper.smapper.TpPRegionAreaSMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class TpPRegionAreaDaoImpl implements TpPRegionAreaDao {
@Autowired
private TpPRegionAreaSMapper tpPRegionAreaSMapper;
@Autowired
private TpPRegionAreaMapper tpPRegionAreaMapper;
@Override
public long saveOrUpdateTpPRegionArea(TpPRegionArea tpPRegionArea) {
long id = 0;
if (null == tpPRegionArea.getId()) {
String parkAreaCode = SequenceUtil.getNextId(SequenceTypeEnum.PARK_AREA_CODE);
tpPRegionArea.setParkAreaCode(parkAreaCode);
id = tpPRegionAreaMapper.insertSelective(tpPRegionArea);
} else {
tpPRegionAreaMapper.updateByPrimaryKeySelective(tpPRegionArea);
}
return id;
}
@Override
public boolean deleteTpPRegionArea(List<Long> ids, Long modifyOpId) {
//判断泊位区间下是否有泊位信息,有则不可以删除
List<TpPRegionAreaDO> pRegionAreaDOs = tpPRegionAreaSMapper.queryNotAllowDeleteBerthAreaInfo(ids);
if (CollectionUtils.isNotEmpty(pRegionAreaDOs)) {
throw new BizException(ErrorType.NOT_ALLOW_DEL_BERTH_AREA);
}
//删除泊位区间
TpPRegionAreaExample example = new TpPRegionAreaExample();
example.createCriteria().andIdIn(ids);
TpPRegionArea record = new TpPRegionArea();
record.setModifyTime(new Date());
record.setModifyOp(modifyOpId);
record.setDataState(DataStatusEnum.DATA_STATUS_NO_VALID.value());
record.setOptFlg(OptFlag.DELETE);
tpPRegionAreaMapper.updateByExampleSelective(record, example);
return true;
}
@Override
public PageInfo<TpPRegionAreaDO> queryTpPRegionAreaForPage(List<String> plNos, String parkAreaName, int pageNum,
int pageSize, String parkAreaCode) {
// 1.设置分页信息
PageHelper.startPage(pageNum, pageSize);
List<TpPRegionAreaDO> list = tpPRegionAreaSMapper.queryTpPRegionAreaForPage(plNos, parkAreaName, parkAreaCode);
return new PageInfo<TpPRegionAreaDO>(list);
}
@Override
public List<TpPRegionArea> queryTpPRegionAreaByPlnoAndAreaCode(String plNo, String parkAreaCode) {
TpPRegionAreaExample example = new TpPRegionAreaExample();
Criteria sql = example.createCriteria();
sql.andParkAreaCodeEqualTo(parkAreaCode);
sql.andPlNoEqualTo(plNo);
sql.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
List<TpPRegionArea> list = tpPRegionAreaMapper.selectByExample(example);
return list;
}
@Override
public List<TpPRegionArea> queryTpPRegionAreaByPlNos(List<String> plNos) {
TpPRegionAreaExample example = new TpPRegionAreaExample();
Criteria sql = example.createCriteria();
sql.andPlNoIn(plNos);
sql.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
List<TpPRegionArea> list = tpPRegionAreaMapper.selectByExample(example);
return list;
}
@Override
public Map<String, TpPRegionArea> queryTpPRegionAreaByParkAreaCodes(List<String> parkAreaCodes) {
TpPRegionAreaExample example = new TpPRegionAreaExample();
Criteria sql = example.createCriteria();
if (CollectionUtil.isNotEmpty(parkAreaCodes)) {
sql.andParkAreaCodeIn(parkAreaCodes);
}
sql.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
List<TpPRegionArea> list = tpPRegionAreaMapper.selectByExample(example);
Map<String, TpPRegionArea> map = new HashMap<String, TpPRegionArea>();
if (!CollectionUtil.isEmpty(list)) {
for (TpPRegionArea tpPRegionArea : list) {
if (null != tpPRegionArea) {
String parkAreaCode = StringUtil.isEmpty(tpPRegionArea.getParkAreaCode()) ? ""
: tpPRegionArea.getParkAreaCode();
if (!map.containsKey(parkAreaCode)) {
map.put(parkAreaCode, tpPRegionArea);
}
}
}
}
return map;
}
@Override
public List<TpPRegionArea> queryRegionAreaByBerthNo(String plNo, String berthNo) {
return tpPRegionAreaSMapper.queryRegionAreaByBerthNo(plNo, berthNo);
}
@Override
public Map<String, Long> queryParkAreaNum(List<String> plNos) {
TpPRegionAreaExample example = new TpPRegionAreaExample();
example.createCriteria().andPlNoIn(plNos)
.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
List<TpPRegionArea> tpPRegionAreas = tpPRegionAreaMapper.selectByExample(example);
if (CollectionUtil.isEmpty(tpPRegionAreas)) {
return new HashMap<>();
}
return tpPRegionAreas.stream().collect(Collectors.groupingBy(TpPRegionArea::getPlNo, Collectors.counting()));
}
@Override
public int insertSelective(TpPRegionArea regionArea) {
String parkAreaCode = SequenceUtil.getNextId(SequenceTypeEnum.PARK_AREA_CODE);
regionArea.setParkAreaCode(parkAreaCode);
return tpPRegionAreaMapper.insertSelective(regionArea);
}
}