zhibing.pu
2024-08-09 bed6becab65745585281ba2e499fa39de561c29f
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.ruoyi.chargingPile.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.chargingPile.api.dto.PageChargingPileListDTO;
import com.ruoyi.chargingPile.api.model.TChargingGun;
import com.ruoyi.chargingPile.api.model.TChargingPile;
import com.ruoyi.chargingPile.api.query.BatchSetAccountingStrategy;
import com.ruoyi.chargingPile.api.query.PageChargingPileList;
import com.ruoyi.chargingPile.domain.SiteMenu;
import com.ruoyi.chargingPile.mapper.TChargingPileMapper;
import com.ruoyi.chargingPile.service.IPartnerService;
import com.ruoyi.chargingPile.service.TChargingGunService;
import com.ruoyi.chargingPile.service.TChargingPileService;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.feignClient.SysUserClient;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 充电桩 服务实现类
 * </p>
 *
 * @author xiaochen
 * @since 2024-08-06
 */
@Service
public class TChargingPileServiceImpl extends ServiceImpl<TChargingPileMapper, TChargingPile> implements TChargingPileService {
    
    @Resource
    private TChargingGunService chargingGunService;
    
    @Resource
    private SysUserClient sysUserClient;
    
    @Resource
    private IPartnerService partnerService;
    
    
    
    
    /**
     * 获取充电桩列表数据
     * @param page
     * @return
     */
    @Override
    public PageInfo<PageChargingPileListDTO> pageChargingPileList(PageChargingPileList page) {
        List<Integer> siteIds = null;
        //校验合作商权限
        SysUser sysUser = sysUserClient.getSysUser(SecurityUtils.getUserId()).getData();
        Integer roleType = sysUser.getRoleType();
        Integer objectId = sysUser.getObjectId();
        //合作商
        if(roleType == 2){
            siteIds = partnerService.authSite(objectId, SiteMenu.CHARGING_PILE);
        }
        PageInfo<PageChargingPileListDTO> pageInfo = new PageInfo<>(page.getPageCurr(), page.getPageSize());
        List<PageChargingPileListDTO> list = this.baseMapper.pageChargingPileList(pageInfo, page, siteIds);
        for (PageChargingPileListDTO pageChargingPileListDTO : list) {
            Integer siteId = pageChargingPileListDTO.getSiteId();
            pageChargingPileListDTO.setAuthAddChargingGun(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.CHARGING_PILE_ADD_CHARGING_GUN));
            pageChargingPileListDTO.setAuthDelete(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.CHARGING_PILE_DELETE));
            pageChargingPileListDTO.setAuthQueryInfo(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.CHARGING_PILE_QUERY_INFO));
            pageChargingPileListDTO.setAuthUpdate(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.CHARGING_PILE_UPDATE));
        }
        return pageInfo.setRecords(list);
    }
    
    
    /**
     * 添加充电桩
     * @param chargingPile
     * @return
     */
    @Override
    public AjaxResult addChargingPile(TChargingPile chargingPile) {
        AjaxResult ajaxResult = addChargingPileVerify(chargingPile);
        if(ajaxResult.isError()){
            return ajaxResult;
        }
        long count = this.count(new LambdaQueryWrapper<TChargingPile>().eq(TChargingPile::getCode, chargingPile.getCode())
                .eq(TChargingPile::getDelFlag, 0));
        if(count > 0){
            return AjaxResult.error("设备编号已存在");
        }
        this.save(chargingPile);
        return AjaxResult.success();
    }
    
    
    /**
     * 校验必填项
     * @param chargingPile
     * @return
     */
    AjaxResult addChargingPileVerify(TChargingPile chargingPile){
        if(StringUtils.isEmpty(chargingPile.getCode())){
            return AjaxResult.error("设备编号不能为空");
        }
        if(StringUtils.isEmpty(chargingPile.getName())){
            return AjaxResult.error("充电设备名称不能为空");
        }
        if(null == chargingPile.getNumber()){
            return AjaxResult.error("桩号不能为空");
        }
        if(null == chargingPile.getType()){
            return AjaxResult.error("设备类型不能为空");
        }
        if(null == chargingPile.getSiteId()){
            return AjaxResult.error("归属电站不能为空");
        }
        if(null == chargingPile.getPartnerId()){
            return AjaxResult.error("归属合作商不能为空");
        }
        if(null == chargingPile.getRatedPower()){
            return AjaxResult.error("额定功率不能为空");
        }
        return AjaxResult.success();
    }
    
    
    /**
     * 获取充电桩详情
     * @param id 充电桩id
     * @return
     */
    @Override
    public TChargingPile getChargingPile(Integer id) {
        return this.baseMapper.getChargingPile(id);
    }
    
    
    /**
     * 编辑充电桩
     * @param chargingPile
     * @return
     */
    @Override
    public AjaxResult editChargingPile(TChargingPile chargingPile) {
        AjaxResult ajaxResult = addChargingPileVerify(chargingPile);
        if(ajaxResult.isError()){
            return ajaxResult;
        }
        TChargingPile one = this.getOne(new LambdaQueryWrapper<TChargingPile>().eq(TChargingPile::getCode, chargingPile.getCode())
                .eq(TChargingPile::getDelFlag, 0));
        if(null != one && !one.getId().equals(chargingPile.getId())){
            return AjaxResult.error("设备编号已存在");
        }
        this.updateById(chargingPile);
        return AjaxResult.success();
    }
    
    
    /**
     * 删除充电桩
     * @param id
     * @return
     */
    @Override
    public AjaxResult delChargingPile(Integer id) {
        //检查是否有关联数据
        //接口
        long count = chargingGunService.count(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getChargingPileId, id).eq(TChargingGun::getDelFlag, 0));
        if(count > 0){
            return AjaxResult.error("该充电桩有关联的接口数据,删除失败!");
        }
        TChargingPile chargingPile = this.getById(id);
        chargingPile.setDelFlag(true);
        this.updateById(chargingPile);
        return AjaxResult.success();
    }
    
    /**
     * 批量设置计费策略
     * @param setAccountingStrategy
     */
    @Override
    public void batchSetAccountingStrategy(BatchSetAccountingStrategy setAccountingStrategy) {
        List<Integer> id = setAccountingStrategy.getId();
        List<TChargingGun> list = chargingGunService.list(new LambdaQueryWrapper<TChargingGun>().in(TChargingGun::getChargingPileId, id).eq(TChargingGun::getDelFlag, 0));
        for (TChargingGun tChargingGun : list) {
            tChargingGun.setChargingPileId(setAccountingStrategy.getAccountingStrategyId());
        }
        chargingGunService.updateBatchById(list);
    }
}