forked from rongchao/epmet-cloud-rizhao
				
			
				 9 changed files with 307 additions and 1 deletions
			
			
		@ -0,0 +1,33 @@ | 
				
			|||
/** | 
				
			|||
 * Copyright 2018 人人开源 https://www.renren.io
 | 
				
			|||
 * <p> | 
				
			|||
 * This program is free software: you can redistribute it and/or modify | 
				
			|||
 * it under the terms of the GNU General Public License as published by | 
				
			|||
 * the Free Software Foundation, either version 3 of the License, or | 
				
			|||
 * (at your option) any later version. | 
				
			|||
 * <p> | 
				
			|||
 * This program is distributed in the hope that it will be useful, | 
				
			|||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
				
			|||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
				
			|||
 * GNU General Public License for more details. | 
				
			|||
 * <p> | 
				
			|||
 * You should have received a copy of the GNU General Public License | 
				
			|||
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			|||
 */ | 
				
			|||
 | 
				
			|||
package com.epmet.opendata.dao; | 
				
			|||
 | 
				
			|||
import com.epmet.commons.mybatis.dao.BaseDao; | 
				
			|||
import com.epmet.opendata.entity.GriderOnlineNumEntity; | 
				
			|||
import org.apache.ibatis.annotations.Mapper; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * 在线网格员人数 | 
				
			|||
 * | 
				
			|||
 * @author generator generator@elink-cn.com | 
				
			|||
 * @since v1.0.0 2021-10-14 | 
				
			|||
 */ | 
				
			|||
@Mapper | 
				
			|||
public interface GriderOnlineNumDao extends BaseDao<GriderOnlineNumEntity> { | 
				
			|||
 | 
				
			|||
} | 
				
			|||
@ -0,0 +1,61 @@ | 
				
			|||
/** | 
				
			|||
 * Copyright 2018 人人开源 https://www.renren.io
 | 
				
			|||
 * <p> | 
				
			|||
 * This program is free software: you can redistribute it and/or modify | 
				
			|||
 * it under the terms of the GNU General Public License as published by | 
				
			|||
 * the Free Software Foundation, either version 3 of the License, or | 
				
			|||
 * (at your option) any later version. | 
				
			|||
 * <p> | 
				
			|||
 * This program is distributed in the hope that it will be useful, | 
				
			|||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
				
			|||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
				
			|||
 * GNU General Public License for more details. | 
				
			|||
 * <p> | 
				
			|||
 * You should have received a copy of the GNU General Public License | 
				
			|||
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			|||
 */ | 
				
			|||
 | 
				
			|||
package com.epmet.opendata.entity; | 
				
			|||
 | 
				
			|||
import com.baomidou.mybatisplus.annotation.TableName; | 
				
			|||
import com.epmet.commons.mybatis.entity.BaseEpmetEntity; | 
				
			|||
import com.fasterxml.jackson.annotation.JsonFormat; | 
				
			|||
import lombok.Data; | 
				
			|||
import lombok.EqualsAndHashCode; | 
				
			|||
 | 
				
			|||
import java.util.Date; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * 用户巡查主记录 | 
				
			|||
 * | 
				
			|||
 * @author generator generator@elink-cn.com | 
				
			|||
 * @since v1.0.0 2021-10-14 | 
				
			|||
 */ | 
				
			|||
@Data | 
				
			|||
@EqualsAndHashCode(callSuper=false) | 
				
			|||
@TableName("grider_online_num") | 
				
			|||
public class GriderOnlineNumEntity extends BaseEpmetEntity { | 
				
			|||
 | 
				
			|||
	private static final long serialVersionUID = 1L; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 客户Id | 
				
			|||
     */ | 
				
			|||
	private String customerId; | 
				
			|||
 | 
				
			|||
	private String qxGridId; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 推送时间 | 
				
			|||
     */ | 
				
			|||
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | 
				
			|||
	private Date pushTime; | 
				
			|||
 | 
				
			|||
	/** | 
				
			|||
	 * 在线数 | 
				
			|||
	 */ | 
				
			|||
	private Integer onlineNum; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
 | 
				
			|||
} | 
				
			|||
@ -0,0 +1,38 @@ | 
				
			|||
/** | 
				
			|||
 * Copyright 2018 人人开源 https://www.renren.io
 | 
				
			|||
 * <p> | 
				
			|||
 * This program is free software: you can redistribute it and/or modify | 
				
			|||
 * it under the terms of the GNU General Public License as published by | 
				
			|||
 * the Free Software Foundation, either version 3 of the License, or | 
				
			|||
 * (at your option) any later version. | 
				
			|||
 * <p> | 
				
			|||
 * This program is distributed in the hope that it will be useful, | 
				
			|||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
				
			|||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
				
			|||
 * GNU General Public License for more details. | 
				
			|||
 * <p> | 
				
			|||
 * You should have received a copy of the GNU General Public License | 
				
			|||
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			|||
 */ | 
				
			|||
 | 
				
			|||
package com.epmet.opendata.service; | 
				
			|||
 | 
				
			|||
import com.epmet.commons.mybatis.service.BaseService; | 
				
			|||
import com.epmet.opendata.entity.GriderOnlineNumEntity; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * 用户巡查主记录 | 
				
			|||
 * | 
				
			|||
 * @author generator generator@elink-cn.com | 
				
			|||
 * @since v1.0.0 2021-10-14 | 
				
			|||
 */ | 
				
			|||
public interface GriderOnlineNumService extends BaseService<GriderOnlineNumEntity> { | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * desc:插入巡查中的网格员数据 | 
				
			|||
     * @return boolean | 
				
			|||
     */ | 
				
			|||
    Boolean insertData(String agencyId); | 
				
			|||
 | 
				
			|||
 | 
				
			|||
} | 
				
			|||
@ -0,0 +1,69 @@ | 
				
			|||
/** | 
				
			|||
 * Copyright 2018 人人开源 https://www.renren.io
 | 
				
			|||
 * <p> | 
				
			|||
 * This program is free software: you can redistribute it and/or modify | 
				
			|||
 * it under the terms of the GNU General Public License as published by | 
				
			|||
 * the Free Software Foundation, either version 3 of the License, or | 
				
			|||
 * (at your option) any later version. | 
				
			|||
 * <p> | 
				
			|||
 * This program is distributed in the hope that it will be useful, | 
				
			|||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
				
			|||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
				
			|||
 * GNU General Public License for more details. | 
				
			|||
 * <p> | 
				
			|||
 * You should have received a copy of the GNU General Public License | 
				
			|||
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			|||
 */ | 
				
			|||
 | 
				
			|||
package com.epmet.opendata.service.impl; | 
				
			|||
 | 
				
			|||
import com.alibaba.fastjson.JSON; | 
				
			|||
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; | 
				
			|||
import com.epmet.commons.tools.constant.NumConstant; | 
				
			|||
import com.epmet.commons.tools.constant.StrConstant; | 
				
			|||
import com.epmet.commons.tools.utils.Result; | 
				
			|||
import com.epmet.dto.form.PatrolCountFormDTO; | 
				
			|||
import com.epmet.dto.result.PatrolCountResultDTO; | 
				
			|||
import com.epmet.feign.EpmetUserOpenFeignClient; | 
				
			|||
import com.epmet.opendata.dao.GriderOnlineNumDao; | 
				
			|||
import com.epmet.opendata.entity.GriderOnlineNumEntity; | 
				
			|||
import com.epmet.opendata.service.GriderOnlineNumService; | 
				
			|||
import lombok.extern.slf4j.Slf4j; | 
				
			|||
import org.springframework.beans.factory.annotation.Autowired; | 
				
			|||
import org.springframework.stereotype.Service; | 
				
			|||
 | 
				
			|||
import java.util.Date; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * 用户巡查主记录 | 
				
			|||
 * | 
				
			|||
 * @author generator generator@elink-cn.com | 
				
			|||
 * @since v1.0.0 2021-10-14 | 
				
			|||
 */ | 
				
			|||
@Slf4j | 
				
			|||
@Service | 
				
			|||
public class GriderOnlineNumServiceImpl extends BaseServiceImpl<GriderOnlineNumDao, GriderOnlineNumEntity> implements GriderOnlineNumService { | 
				
			|||
@Autowired | 
				
			|||
private EpmetUserOpenFeignClient epmetUserOpenFeignClient; | 
				
			|||
    @Override | 
				
			|||
    public Boolean insertData(String agencyId) { | 
				
			|||
        PatrolCountFormDTO param = new PatrolCountFormDTO(); | 
				
			|||
        param.setAgencyId(agencyId); | 
				
			|||
        Result<PatrolCountResultDTO> patrolCountResult = epmetUserOpenFeignClient.patrolCount(param); | 
				
			|||
 | 
				
			|||
        log.debug("insertData patrolCountResult return:{}", JSON.toJSONString(patrolCountResult)); | 
				
			|||
        if (patrolCountResult == null || !patrolCountResult.success()) { | 
				
			|||
            log.warn("insertData patrolCount fail,return null"); | 
				
			|||
            return false; | 
				
			|||
        } | 
				
			|||
        PatrolCountResultDTO data = patrolCountResult.getData(); | 
				
			|||
        int count = data.getPatrollingCount() == null ? NumConstant.ZERO : data.getPatrollingCount(); | 
				
			|||
        GriderOnlineNumEntity entity = new GriderOnlineNumEntity(); | 
				
			|||
        entity.setCustomerId(StrConstant.PY_CUSTOMER); | 
				
			|||
        entity.setPushTime(new Date()); | 
				
			|||
        entity.setOnlineNum(count); | 
				
			|||
        baseDao.insert(entity); | 
				
			|||
        return true; | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -0,0 +1,71 @@ | 
				
			|||
package com.epmet.opendata.task; | 
				
			|||
 | 
				
			|||
import com.epmet.commons.tools.constant.NumConstant; | 
				
			|||
import com.epmet.commons.tools.constant.StrConstant; | 
				
			|||
import com.epmet.commons.tools.distributedlock.DistributedLock; | 
				
			|||
import com.epmet.commons.tools.redis.RedisKeys; | 
				
			|||
import com.epmet.commons.tools.utils.DateUtils; | 
				
			|||
import com.epmet.opendata.service.GriderOnlineNumService; | 
				
			|||
import lombok.extern.slf4j.Slf4j; | 
				
			|||
import org.redisson.api.RLock; | 
				
			|||
import org.springframework.beans.factory.annotation.Autowired; | 
				
			|||
import org.springframework.scheduling.annotation.Scheduled; | 
				
			|||
import org.springframework.stereotype.Component; | 
				
			|||
 | 
				
			|||
import java.util.Date; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * desc: | 
				
			|||
 * | 
				
			|||
 * @author: LiuJanJun | 
				
			|||
 * @date: 2022/4/12 4:21 下午 | 
				
			|||
 * @version: 1.0 | 
				
			|||
 */ | 
				
			|||
@Slf4j | 
				
			|||
@Component | 
				
			|||
public class ExtractBizDataToOpenData { | 
				
			|||
 | 
				
			|||
    @Autowired | 
				
			|||
    private DistributedLock distributedLock; | 
				
			|||
 | 
				
			|||
    @Autowired | 
				
			|||
    private GriderOnlineNumService griderOnlineNumService; | 
				
			|||
 | 
				
			|||
    @Scheduled(cron = "0 30 */2 * * *") | 
				
			|||
    //@Scheduled(cron = "0/15 * * * * *")
 | 
				
			|||
    public void extractGridMemberPatrollingCount() { | 
				
			|||
        String currentTime = DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN); | 
				
			|||
        log.info("extractGridMemberPatrollingCount start,date:{}", currentTime); | 
				
			|||
        RLock rLock = null; | 
				
			|||
        try { | 
				
			|||
            rLock = distributedLock.tryLock(RedisKeys.getLockByMethodName("extractGridMemberPatrollingCount")); | 
				
			|||
            if (rLock == null || !rLock.isLocked()) { | 
				
			|||
                log.warn("tryLock method extractGridMemberPatrollingCount fail"); | 
				
			|||
                return; | 
				
			|||
            } | 
				
			|||
            boolean patrolCountResult; | 
				
			|||
            int retryTime = NumConstant.THREE; | 
				
			|||
            do { | 
				
			|||
                //StrConstant.PY_ROOT_AGENCY
 | 
				
			|||
                patrolCountResult = griderOnlineNumService.insertData(StrConstant.PY_ROOT_AGENCY); | 
				
			|||
                if (!patrolCountResult) { | 
				
			|||
                    break; | 
				
			|||
                } | 
				
			|||
                //如果 重试次数为1了 就让歇个 5分钟
 | 
				
			|||
                if (retryTime == 1) { | 
				
			|||
                    Thread.sleep(NumConstant.FIVE * NumConstant.SIXTY * NumConstant.ONE_THOUSAND); | 
				
			|||
                } | 
				
			|||
            } while (retryTime-- > 0); | 
				
			|||
            if (!patrolCountResult) { | 
				
			|||
                log.error("插入网格员在线人数失败,请检查原因,时间:{}", currentTime); | 
				
			|||
            } | 
				
			|||
 | 
				
			|||
        } catch (Exception e) { | 
				
			|||
            log.warn("tryLock method extractGridMemberPatrollingCount fail"); | 
				
			|||
        } finally { | 
				
			|||
            distributedLock.unLock(rLock); | 
				
			|||
        } | 
				
			|||
        log.info("extractGridMemberPatrollingCount end"); | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
} | 
				
			|||
@ -0,0 +1,13 @@ | 
				
			|||
CREATE TABLE `grider_online_num` ( | 
				
			|||
                                     `ID` varchar(64) NOT NULL COMMENT '主键', | 
				
			|||
                                     `CUSTOMER_ID` varchar(64) NOT NULL COMMENT '客户Id', | 
				
			|||
                                     `ONLINE_NUM` int(11) NOT NULL COMMENT '在线人数', | 
				
			|||
                                     `PUSH_TIME` datetime NOT NULL COMMENT '推送时间', | 
				
			|||
                                     `DEL_FLAG` bigint(1) NOT NULL DEFAULT '0' COMMENT '删除标识 0.未删除 1.已删除', | 
				
			|||
                                     `REVISION` int(11) NOT NULL COMMENT '乐观锁', | 
				
			|||
                                     `CREATED_BY` varchar(64) NOT NULL COMMENT '创建人', | 
				
			|||
                                     `CREATED_TIME` datetime NOT NULL COMMENT '创建时间', | 
				
			|||
                                     `UPDATED_BY` varchar(64) NOT NULL COMMENT '更新人', | 
				
			|||
                                     `UPDATED_TIME` datetime NOT NULL COMMENT '更新时间', | 
				
			|||
                                     PRIMARY KEY (`ID`) | 
				
			|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='网格员在线人数'; | 
				
			|||
@ -0,0 +1,6 @@ | 
				
			|||
<?xml version="1.0" encoding="UTF-8"?> | 
				
			|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | 
				
			|||
 | 
				
			|||
<mapper namespace="com.epmet.opendata.dao.GriderOnlineNumDao"> | 
				
			|||
 | 
				
			|||
</mapper> | 
				
			|||
					Loading…
					
					
				
		Reference in new issue