You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

101 lines
3.8 KiB

/**
* 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.controller;
import com.epmet.commons.tools.distributedlock.DistributedLock;
import com.epmet.commons.tools.feign.ResultDataResolver;
import com.epmet.commons.tools.redis.RedisKeys;
import com.epmet.commons.tools.redis.RedisUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.service.IcResiUserDataSyncService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* 用户基础信息同步计算入口
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2021-10-26
*/
@Slf4j
@RestController
@RequestMapping("icResiUserDataSync")
public class IcResiUserDataSyncController implements ResultDataResolver {
@Autowired
private IcResiUserDataSyncService icResiUserDataSyncService;
@Autowired
private RedisUtils redisUtils;
@Autowired
private DistributedLock distributedLock;
/**
* 获取录入居民的数量
*
* @Param formDTO
* @Return {@link Result<Map<String, Integer>>}
* @Author zhaoqifeng
* @Date 2022/6/30 9:35
*/
@PostMapping("icDataSyncTask")
public Result<Boolean> icDataSyncTask(@RequestParam("customerId") String customerId) {
RLock lock = null;
String key = RedisKeys.getDataSyncKey("resi");
try {
lock = distributedLock.getLock(RedisKeys.getLockByMethodName("icDataSyncTask"),
30L, 30L, TimeUnit.SECONDS);
if (StringUtils.isBlank(customerId)) {
Object customerIdObj = redisUtils.sPop(key);
while (customerIdObj != null) {
try {
icResiUserDataSyncService.icDataSyncTask(customerIdObj.toString());
log.debug("icDataSyncTask customerId:{} execute success", customerIdObj);
customerIdObj = redisUtils.sPop(key);
} catch (Exception e) {
log.error("icDataSyncTask exception msg:{},customerId:{}", e.getMessage(), customerIdObj);
redisUtils.sAdd(key, customerIdObj);
}
log.debug("icDataSyncTask finish customerId:{} execute success", customerIdObj);
}
} else {
icResiUserDataSyncService.icDataSyncTask(customerId);
log.debug("icDataSyncTask customerId:{} execute success", customerId);
}
} catch (Exception e) {
if (StringUtils.isNotBlank(customerId)) {
redisUtils.sAdd(key, customerId);
}
log.error("icDataSyncTask exception msg:{},customerId:{}", e.getMessage(), customerId);
} finally {
distributedLock.unLock(lock);
}
return new Result<Boolean>().ok(true);
}
}