parent
f4774578fb
commit
bd874cbd64
@ -0,0 +1,43 @@
|
||||
package com.glxp.udidl.admin.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
|
||||
/**
|
||||
* Redis配置类
|
||||
*/
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory cf) {
|
||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>();
|
||||
redisTemplate.setConnectionFactory(cf);
|
||||
redisTemplate.setValueSerializer(RedisSerializer.json());
|
||||
redisTemplate.setHashValueSerializer(RedisSerializer.string());
|
||||
redisTemplate.setKeySerializer(RedisSerializer.string());
|
||||
redisTemplate.setHashKeySerializer(RedisSerializer.string());
|
||||
redisTemplate.afterPropertiesSet();
|
||||
Jackson2JsonRedisSerializer<Object> serializer = new Jackson2JsonRedisSerializer<>(Object.class);
|
||||
ObjectMapper objectMapper = new ObjectMapper()
|
||||
.registerModule(new ParameterNamesModule())
|
||||
.registerModule(new Jdk8Module())
|
||||
.registerModule(new JavaTimeModule());
|
||||
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||
objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
|
||||
serializer.setObjectMapper(objectMapper);
|
||||
redisTemplate.setValueSerializer(serializer);
|
||||
return redisTemplate;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.glxp.udidl.admin.controller.device;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.glxp.udidl.admin.annotation.AuthRuleAnnotation;
|
||||
import com.glxp.udidl.admin.entity.udid.Contactlist;
|
||||
import com.glxp.udidl.admin.enums.ResultEnum;
|
||||
import com.glxp.udidl.admin.req.UpdateUdiRequest;
|
||||
import com.glxp.udidl.admin.res.BaseResponse;
|
||||
import com.glxp.udidl.admin.service.dataSync.DeviceUpdateService;
|
||||
import com.glxp.udidl.admin.util.ResultVOUtils;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 数据更新接口
|
||||
*/
|
||||
@RestController
|
||||
public class UdiUpdateController {
|
||||
|
||||
@Resource
|
||||
private DeviceUpdateService deviceUpdateService;
|
||||
|
||||
@ApiOperation(value = "更新医疗器械信息接口", response = Contactlist.class)
|
||||
@AuthRuleAnnotation("udi/update/updateUdiData")
|
||||
@GetMapping("udi/update/updateUdiData")
|
||||
public BaseResponse updateData(UpdateUdiRequest updateUdiRequest) {
|
||||
if (StrUtil.isBlank(updateUdiRequest.getStartDate()) || StrUtil.isBlank(updateUdiRequest.getEndDate())) {
|
||||
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "未指定更新时间");
|
||||
}
|
||||
deviceUpdateService.updateUdiData(updateUdiRequest);
|
||||
return ResultVOUtils.success();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.glxp.udidl.admin.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 更新医疗器械信息接口请求参数
|
||||
*/
|
||||
@Data
|
||||
public class UpdateUdiRequest {
|
||||
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
private String startDate;
|
||||
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
private String endDate;
|
||||
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
package com.glxp.udidl.admin.service.dataSync;
|
||||
|
||||
import cn.hutool.core.date.DateField;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.glxp.udidl.admin.constant.Constant;
|
||||
import com.glxp.udidl.admin.entity.info.CompanyEntity;
|
||||
import com.glxp.udidl.admin.entity.udid.JobLog;
|
||||
import com.glxp.udidl.admin.entity.udid.TokenEntity;
|
||||
import com.glxp.udidl.admin.req.UpdateUdiRequest;
|
||||
import com.glxp.udidl.admin.req.udid.TokenRequest;
|
||||
import com.glxp.udidl.admin.service.info.CompanyService;
|
||||
import com.glxp.udidl.admin.service.inout.DeviceService;
|
||||
import com.glxp.udidl.admin.service.inout.ProductInfoService;
|
||||
import com.glxp.udidl.admin.service.udi.JobLogService;
|
||||
import com.glxp.udidl.admin.util.HttpClient;
|
||||
import com.glxp.udidl.admin.util.RedisUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class DeviceUpdateService {
|
||||
|
||||
private String token;
|
||||
private String url = "sharing/get";
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private CompanyService companyService;
|
||||
@Resource
|
||||
private JobLogService jobLogService; //日志
|
||||
@Resource
|
||||
private DeviceSaveService deviceSaveService;
|
||||
@Resource
|
||||
private DeviceService deviceService;
|
||||
@Resource
|
||||
private ProductInfoService productInfoService;
|
||||
|
||||
@Async
|
||||
public void updateUdiData(UpdateUdiRequest updateUdiRequest) {
|
||||
log.info("开始更新数据,更新时间段为: {} - {}", updateUdiRequest.getStartDate(), updateUdiRequest.getEndDate());
|
||||
//解析更新参数
|
||||
DateTime startDate = DateUtil.parse(updateUdiRequest.getStartDate(), DatePattern.SIMPLE_MONTH_PATTERN);
|
||||
DateTime endDate = DateUtil.parse(updateUdiRequest.getEndDate(), DatePattern.SIMPLE_MONTH_PATTERN);
|
||||
|
||||
List<DateTime> dateRanges = DateUtil.rangeToList(startDate, endDate, DateField.MONTH);
|
||||
|
||||
JobLog jobLog = new JobLog();
|
||||
jobLog.setCreateTime(new Date());
|
||||
jobLog.setStatus(0);
|
||||
jobLog.setType(Constant.LOG_TYPE_INFO);
|
||||
jobLog.setDownloadType(Constant.DOWNLOAD_TYPE_MANUAL);
|
||||
jobLogService.insert(jobLog);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前token
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getToken() {
|
||||
token = redisUtil.get("UDI_UPDATE_TOKEN");
|
||||
if (StrUtil.isEmpty(token)) {
|
||||
//查询下载数据使用的appid
|
||||
CompanyEntity companyEntity = companyService.findByTaskType(Constant.TASK_TYPE_UPDATE);
|
||||
TokenRequest tokenRequest = new TokenRequest();
|
||||
tokenRequest.setAppId(companyEntity.getAppId());
|
||||
tokenRequest.setAppSecret(companyEntity.getAppSecret());
|
||||
tokenRequest.setTyshxydm(companyEntity.getTyshxydm());
|
||||
String response = HttpClient.post("token/get", tokenRequest);
|
||||
TokenEntity tokenEntity = JSONObject.parseObject(response, TokenEntity.class);
|
||||
token = tokenEntity.getAccessToken();
|
||||
redisUtil.setEx("UDI_UPDATE_TOKEN", token, 1 * 60 * 60 * 6);
|
||||
}
|
||||
return token;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue