Pu Zhibing
2024-10-12 1e7bea1cfadbbbc95b0c0697b13aa9050cf02dc7
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingGunServiceImpl.java
@@ -7,9 +7,7 @@
import com.ruoyi.chargingPile.api.model.TChargingGun;
import com.ruoyi.chargingPile.api.model.TChargingPile;
import com.ruoyi.chargingPile.api.query.TChargingGunQuery;
import com.ruoyi.chargingPile.api.vo.ChargingGunCountVO;
import com.ruoyi.chargingPile.api.vo.TChargingGunVO;
import com.ruoyi.chargingPile.api.vo.TMonitoringEquipmentVO;
import com.ruoyi.chargingPile.api.vo.*;
import com.ruoyi.chargingPile.domain.SiteMenu;
import com.ruoyi.chargingPile.mapper.TChargingGunMapper;
import com.ruoyi.chargingPile.service.IPartnerService;
@@ -21,22 +19,21 @@
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.integration.api.feignClient.SendMessageClient;
import com.ruoyi.integration.api.model.QrCodeDelivery;
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 com.ruoyi.system.api.feignClient.SysUserRoleClient;
import com.ruoyi.system.api.model.SysUserRoleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.HashSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import java.util.Set;
/**
 * <p>
@@ -63,6 +60,12 @@
    @Autowired
    private TChargingPileService chargingPileService;
    @Resource
    private SysUserRoleClient sysUserRoleClient;
    @Resource
    private SendMessageClient sendMessageClient;
    
    
    
@@ -80,7 +83,8 @@
            //非管理员需要根据角色和用户配置查询允许的站点数据
            if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                List<Integer> data = userSiteClient.getSiteIds(sysUser.getUserId()).getData();
                List<Integer> data1 = roleSiteClient.getSiteIds(sysUser.getRoleId()).getData();
                List<SysUserRoleVo> data2 = sysUserRoleClient.getRoleByUserId(sysUser.getUserId()).getData();
                List<Integer> data1 = roleSiteClient.getSiteIds(data2.get(0).getRoleId()).getData();
                data.addAll(data1);
                siteIds = new HashSet<>(data);
            }
@@ -112,11 +116,22 @@
            return ajaxResult;
        }
        long count = this.count(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getCode, dto.getCode())
                .eq(TChargingGun::getDelFlag, 0));
                .eq(TChargingGun::getDelFlag, 0).eq(TChargingGun::getChargingPileId, dto.getChargingPileId()));
        if(count > 0){
            return AjaxResult.error("接口编码已存在");
        }
        this.save(dto);
        TChargingPile chargingPile = chargingPileService.getById(dto.getChargingPileId());
        //下发硬件充电二维码
        String code_prefix = "https://mxcd.zhinenganguan.com?No=";
        QrCodeDelivery qrCodeDelivery = new QrCodeDelivery();
        qrCodeDelivery.setCharging_pile_code(chargingPile.getCode());
        qrCodeDelivery.setCode_format(1);
        qrCodeDelivery.setPrefix_length(code_prefix.length());
        qrCodeDelivery.setCode_prefix(code_prefix);
        qrCodeDelivery.setQr_code(code_prefix + chargingPile.getCode() + dto.getCode());
        sendMessageClient.qrCodeDelivery(qrCodeDelivery);
        return AjaxResult.success();
    }
    
@@ -137,11 +152,22 @@
            return ajaxResult;
        }
        TChargingGun one = this.getOne(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getCode, dto.getCode())
                .eq(TChargingGun::getDelFlag, 0));
                .eq(TChargingGun::getDelFlag, 0).eq(TChargingGun::getChargingPileId, dto.getChargingPileId()));
        if(null != one && !dto.getId().equals(one.getId())){
            return AjaxResult.error("接口编码已存在");
        }
        this.updateById(dto);
        TChargingPile chargingPile = chargingPileService.getById(dto.getChargingPileId());
        //下发硬件充电二维码
        String code_prefix = "https://mxcd.zhinenganguan.com?No=";
        QrCodeDelivery qrCodeDelivery = new QrCodeDelivery();
        qrCodeDelivery.setCharging_pile_code(chargingPile.getCode());
        qrCodeDelivery.setCode_format(1);
        qrCodeDelivery.setPrefix_length(code_prefix.length());
        qrCodeDelivery.setCode_prefix(code_prefix);
        qrCodeDelivery.setQr_code(code_prefix + chargingPile.getCode() + dto.getCode());
        sendMessageClient.qrCodeDelivery(qrCodeDelivery);
        return AjaxResult.success();
    }
@@ -182,6 +208,91 @@
        return map;
    }
    @Override
    public GunStatusStatisticsVO gunStatusStatistics(List<Integer> siteIds) {
        GunStatusStatisticsVO gunStatusStatisticsVO = new GunStatusStatisticsVO();
        if(CollectionUtils.isEmpty(siteIds)){
//            List<Map<Integer, Integer>> modeStatisticsNull = new ArrayList<>();
//                HashMap<Integer, Integer> objectObjectHashMap1 = new HashMap<>();
//            objectObjectHashMap1.put(1, 0);
//            modeStatisticsNull.add(objectObjectHashMap1);
//            HashMap<Integer, Integer> objectObjectHashMap2= new HashMap<>();
//            objectObjectHashMap2.put(2, 0);
//            modeStatisticsNull.add(objectObjectHashMap2);
//            HashMap<Integer, Integer> objectObjectHashMap3= new HashMap<>();
//            objectObjectHashMap3.put(3, 0);
//            modeStatisticsNull.add(objectObjectHashMap3);
//            gunStatusStatisticsVO.setModeStatistics(modeStatisticsNull);
//            Map<Integer, Integer> statusStatisticsNull = new HashMap<>();
//            statusStatisticsNull.put(1, 0);
//            statusStatisticsNull.put(2, 0);
//            statusStatisticsNull.put(3, 0);
//            gunStatusStatisticsVO.setStatusStatistics(statusStatisticsNull);
            List<StatusModeStatisticsVO> statusModeStatistics = new ArrayList<>();
            for (int i = 1; i < 4; i++) {
                StatusModeStatisticsVO statusModeStatisticsVO = new StatusModeStatisticsVO();
                statusModeStatisticsVO.setChargeMode(i);
                statusModeStatisticsVO.setChargingCount(0);
                statusModeStatisticsVO.setFilledCount(0);
                statusModeStatisticsVO.setInsertCount(0);
                statusModeStatisticsVO.setFreeCount(0);
                statusModeStatistics.add(statusModeStatisticsVO);
            }
            gunStatusStatisticsVO.setStatusModeStatistics(statusModeStatistics);
        }
        List<Map<String, Object>> modeStatistics = this.baseMapper.getModeStatistics(siteIds);
        if(CollectionUtils.isEmpty(modeStatistics)){
            Map<String, Object> modeStatistics1 = new HashMap<>();
            modeStatistics1.put("1", "0");
            modeStatistics1.put("2", "0");
            modeStatistics1.put("3", "0");
            modeStatistics.add(modeStatistics1);
        }
        gunStatusStatisticsVO.setModeStatistics(modeStatistics);
        List<Map<String, Integer>> statusStatistics = new ArrayList<>();
        // 离线
        Long count = this.baseMapper.selectCount(Wrappers.lambdaQuery(TChargingGun.class)
                .eq(TChargingGun::getStatus, 1));
        HashMap<String, Integer> objectObjectHashMap1 = new HashMap<>();
        objectObjectHashMap1.put("charge_mode",1);
        objectObjectHashMap1.put("modeCount", count.intValue());
        statusStatistics.add(objectObjectHashMap1);
//        statusStatistics.put(1, count.intValue());
        // 故障
        count = this.baseMapper.selectCount(Wrappers.lambdaQuery(TChargingGun.class)
                .eq(TChargingGun::getStatus, 7));
        HashMap<String, Integer> objectObjectHashMap2 = new HashMap<>();
//        objectObjectHashMap2.put("2", count.intValue());
        objectObjectHashMap2.put("charge_mode",2);
        objectObjectHashMap2.put("modeCount", count.intValue());
        statusStatistics.add(objectObjectHashMap2);
//        statusStatistics.put(2, count.intValue());
        // 充电中
        count = this.baseMapper.selectCount(Wrappers.lambdaQuery(TChargingGun.class)
                .in(TChargingGun::getStatus, Arrays.asList(3,4,5,6)));
       HashMap<String, Integer> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("charge_mode",3);
        objectObjectHashMap.put("modeCount", count.intValue());
        statusStatistics.add(objectObjectHashMap);
//        statusStatistics.put(3, count.intValue());
        gunStatusStatisticsVO.setStatusStatistics(statusStatistics);
        List<StatusModeStatisticsVO> statusModeStatisticsVOS = new ArrayList<>();
        StatusModeStatisticsVO statusModeStatistics1 = this.baseMapper.getStatusModeStatistics(siteIds,1);
        StatusModeStatisticsVO statusModeStatistics2 = this.baseMapper.getStatusModeStatistics(siteIds,2);
        StatusModeStatisticsVO statusModeStatistics3 = this.baseMapper.getStatusModeStatistics(siteIds,3);
        statusModeStatisticsVOS.add(statusModeStatistics1);
        statusModeStatisticsVOS.add(statusModeStatistics2);
        statusModeStatisticsVOS.add(statusModeStatistics3);
        gunStatusStatisticsVO.setStatusModeStatistics(statusModeStatisticsVOS);
        return gunStatusStatisticsVO;
    }
    private ChargingGunCountVO getGunCount(Integer chargeMode, List<TChargingGun> list){
        ChargingGunCountVO chargingGunCountVO = new ChargingGunCountVO();
        chargingGunCountVO.setTotalCount(list.stream().filter(tChargingGun -> tChargingGun.getChargeMode().equals(chargeMode)).collect(Collectors.toList()).size());