zhibing.pu
2024-08-09 ff859437dd9d18d9d7411bafc4c31038f940b9f2
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
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.TChargingGunDTO;
import com.ruoyi.chargingPile.api.model.TChargingGun;
import com.ruoyi.chargingPile.api.query.TChargingGunQuery;
import com.ruoyi.chargingPile.api.vo.TChargingGunVO;
import com.ruoyi.chargingPile.api.vo.TMonitoringEquipmentVO;
import com.ruoyi.chargingPile.domain.SiteMenu;
import com.ruoyi.chargingPile.mapper.TChargingGunMapper;
import com.ruoyi.chargingPile.service.IPartnerService;
import com.ruoyi.chargingPile.service.TChargingGunService;
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.other.api.feignClient.RoleSiteClient;
import com.ruoyi.other.api.feignClient.UserSiteClient;
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.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
 
/**
 * <p>
 * 充电枪 服务实现类
 * </p>
 *
 * @author xiaochen
 * @since 2024-08-06
 */
@Service
public class TChargingGunServiceImpl extends ServiceImpl<TChargingGunMapper, TChargingGun> implements TChargingGunService {
    
    @Resource
    private SysUserClient sysUserClient;
    
    @Resource
    private IPartnerService partnerService;
    
    @Resource
    private UserSiteClient userSiteClient;
    
    @Resource
    private RoleSiteClient roleSiteClient;
 
    
    
    
    @Override
    public PageInfo<TChargingGunVO> pageList(TChargingGunQuery query) {
        Set<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_GUN);
        }else{
            //非管理员需要根据角色和用户配置查询允许的站点数据
            if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                List<Integer> data = userSiteClient.getSiteIds(sysUser.getUserId()).getData();
                List<Integer> data1 = roleSiteClient.getSiteIds(sysUser.getRoleId()).getData();
                data.addAll(data1);
                siteIds = new HashSet<>(data);
            }
        }
        PageInfo<TChargingGunVO> pageInfo = new PageInfo<>(query.getPageCurr(),query.getPageSize());
        List<TChargingGunVO> list = this.baseMapper.pageList(query,pageInfo, siteIds);
        for (TChargingGunVO tChargingGunVO : list) {
            Integer siteId = tChargingGunVO.getSiteId();
            tChargingGunVO.setAuthDelete(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.CHARGING_GUN_DELETE));
            tChargingGunVO.setAuthDownloadQRCode(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.CHARGING_GUN_DOWNLOAD_QR_CODE));
            tChargingGunVO.setAuthEndCharge(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.CHARGING_GUN_END_CHARGE));
            tChargingGunVO.setAuthQueryInfo(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.CHARGING_GUN_QUERY_INFO));
            tChargingGunVO.setAuthUpdate(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.CHARGING_GUN_UPDATE));
            tChargingGunVO.setAuthViewRates(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.CHARGING_GUN_VIEW_RATES));
        }
        pageInfo.setRecords(list);
        return pageInfo;
    }
    
    /**
     * 添加充电枪
     * @param dto
     * @return
     */
    @Override
    public AjaxResult add(TChargingGunDTO dto) {
        AjaxResult ajaxResult = addVerify(dto);
        if(ajaxResult.isError()){
            return ajaxResult;
        }
        long count = this.count(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getCode, dto.getCode()).eq(TChargingGun::getDelFlag, 0));
        if(count > 0){
            return AjaxResult.error("接口编码已存在");
        }
        this.save(dto);
        return AjaxResult.success();
    }
    
    
    /**
     * 编辑充电枪
     * @param dto
     * @return
     */
    @Override
    public AjaxResult update(TChargingGunDTO dto) {
        TChargingGun chargingGun = this.getById(dto.getId());
        if(Arrays.asList(3,4,5,6).contains(chargingGun.getStatus())){
            return AjaxResult.error("接口占用中,无法编辑!");
        }
        AjaxResult ajaxResult = addVerify(dto);
        if(ajaxResult.isError()){
            return ajaxResult;
        }
        TChargingGun one = this.getOne(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getCode, dto.getCode()).eq(TChargingGun::getDelFlag, 0));
        if(null != one && !dto.getId().equals(one.getId())){
            return AjaxResult.error("接口编码已存在");
        }
        this.updateById(dto);
        return AjaxResult.success();
    }
    
    /**
     * 校验必填项
     * @param dto
     * @return
     */
    AjaxResult addVerify(TChargingGunDTO dto){
        if(StringUtils.isEmpty(dto.getCode())){
            return AjaxResult.error("接口编码不能为空");
        }
        if(StringUtils.isEmpty(dto.getName())){
            return AjaxResult.error("接口名称不能为空");
        }
        if(null == dto.getType()){
            return AjaxResult.error("接口类型不能为空");
        }
        if(null == dto.getStatus()){
            return AjaxResult.error("接口状态不能为空");
        }
        if(null == dto.getChargeMode()){
            return AjaxResult.error("充电方式不能为空");
        }
        if(null == dto.getUpperRatedVoltage()){
            return AjaxResult.error("额定电压上限不能为空");
        }
        if(null == dto.getLowerLimitOfRatedVoltage()){
            return AjaxResult.error("额定电压下限不能为空");
        }
        if(null == dto.getRatedCurrent()){
            return AjaxResult.error("额定电流不能为空");
        }
        if(null == dto.getRatedPower()){
            return AjaxResult.error("额定功率不能为空");
        }
        if(StringUtils.isEmpty(dto.getNationalStandard())){
            return AjaxResult.error("国家标准不能为空");
        }
        return AjaxResult.success();
    }
}