doum
2025-12-12 89029e9ade03f3139c6afcd6bac48d9a668875f3
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
package com.doumee.service.business.impl;
 
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.HotCityMapper;
import com.doumee.dao.business.join.HotCityJoinMapper;
import com.doumee.dao.business.model.Activity;
import com.doumee.dao.business.model.Areas;
import com.doumee.dao.business.model.HotCity;
import com.doumee.dao.web.response.HotCityResponse;
import com.doumee.service.business.HotCityService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
/**
 * 常用城市配置表Service实现
 * @author 江蹄蹄
 * @date 2023/03/21 15:48
 */
@Service
public class HotCityServiceImpl implements HotCityService {
 
    @Autowired
    private HotCityMapper hotCityMapper;
 
    @Autowired
    private HotCityJoinMapper hotCityJoinMapper;
 
    @Override
    public Integer create(HotCity hotCity) {
        if(hotCity.getCityId()==null){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),ResponseStatus.BAD_REQUEST.getMessage());
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        hotCity.setIsdeleted(Constants.ZERO);
        hotCity.setCreateDate(new Date());
        hotCity.setCreator(user.getId());
 
        HotCity query=new HotCity();
        query.setCityId(hotCity.getCityId());
        query.setIsdeleted(Constants.ZERO);
        List<HotCity> list= hotCityMapper.selectList(new QueryWrapper<>(query));
        if(!CollectionUtils.isEmpty(list)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"常用城市已存在,禁止添加");
        }
        hotCityMapper.insert(hotCity);
        return hotCity.getId();
    }
 
    @Override
    public void deleteById(Integer id) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        HotCity hotCity=new HotCity();
        hotCity.setEditDate(new Date());
        hotCity.setEditor(user.getId());
        hotCity.setId(id);
        hotCity.setIsdeleted(Constants.ONE);
        hotCityMapper.updateById(hotCity);
    }
 
    @Override
    public void delete(HotCity hotCity) {
        UpdateWrapper<HotCity> deleteWrapper = new UpdateWrapper<>(hotCity);
        hotCityMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        hotCityMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(HotCity hotCity) {
        if(hotCity.getCityId()==null){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),ResponseStatus.BAD_REQUEST.getMessage());
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        hotCity.setEditDate(new Date());
        hotCity.setEditor(user.getId());
 
        HotCity query=new HotCity();
        query.setCityId(hotCity.getCityId());
        query.setIsdeleted(Constants.ZERO);
        List<HotCity> list= hotCityMapper.selectList(new QueryWrapper<>(query));
        if(!CollectionUtils.isEmpty(list)&&!Constants.equalsInteger(list.get(0).getId(),hotCity.getId())){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"常用城市已存在,禁止添加");
        }
        hotCityMapper.updateById(hotCity);
    }
 
    @Override
    public void updateByIdInBatch(List<HotCity> hotCitys) {
        if (CollectionUtils.isEmpty(hotCitys)) {
            return;
        }
        for (HotCity hotCity: hotCitys) {
            this.updateById(hotCity);
        }
    }
 
    @Override
    public HotCity findById(Integer id) {
        return hotCityMapper.selectById(id);
    }
 
    @Override
    public HotCity findOne(HotCity hotCity) {
        QueryWrapper<HotCity> wrapper = new QueryWrapper<>(hotCity);
        return hotCityMapper.selectOne(wrapper);
    }
 
    @Override
    public List<HotCity> findList(HotCity hotCity) {
        QueryWrapper<HotCity> wrapper = new QueryWrapper<>(hotCity);
        return hotCityMapper.selectList(wrapper);
    }
  
    @Override
    public PageData<HotCity> findPage(PageWrap<HotCity> pageWrap) {
        IPage<HotCity> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<HotCity> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
 
        queryWrapper.selectAll(HotCity.class);
        queryWrapper.selectAs(Areas::getName,HotCity::getCityName);
        queryWrapper.leftJoin(Areas.class,Areas::getId,HotCity::getCityId);
 
        queryWrapper.eq(pageWrap.getModel().getCityId()!=null,HotCity::getCityId,pageWrap.getModel().getCityId());
        queryWrapper.eq(HotCity::getIsdeleted,Constants.ZERO);
        queryWrapper.orderByAsc(HotCity::getSortnum);
        IPage<HotCity> result = hotCityJoinMapper.selectJoinPage(page, HotCity.class, queryWrapper);
        return PageData.from(result);
    }
 
    @Override
    public long count(HotCity hotCity) {
        QueryWrapper<HotCity> wrapper = new QueryWrapper<>(hotCity);
        return hotCityMapper.selectCount(wrapper);
    }
 
    /****************************************移动端接口开始********************************************************************/
 
    @Override
    public List<HotCityResponse> getHotCityResponseList() {
        return hotCityMapper.getHotCityResponse();
    }
 
}