package com.iailab.module.prod.service.impl;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.iailab.common.enums.CommonConstant;
|
import com.iailab.framework.common.service.impl.BaseServiceImpl;
|
import com.iailab.common.utils.DateUtils;
|
import com.iailab.common.utils.HttpsRequest;
|
import com.iailab.module.data.dto.FeignHttpApiDTO;
|
import com.iailab.module.data.api.IFeignDataApi;
|
import com.iailab.module.prod.dao.PrdDayDutyDao;
|
import com.iailab.module.prod.entity.PrdDayDutyEntity;
|
import com.iailab.module.prod.service.PrdDayDutyService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import javax.annotation.Resource;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.CollectionUtils;
|
|
import java.util.*;
|
|
/**
|
* @author PanZhibao
|
* @Description
|
* @createTime 2024年05月26日
|
*/
|
@Slf4j
|
@Service
|
public class PrdDayDutyServiceImpl extends BaseServiceImpl<PrdDayDutyDao, PrdDayDutyEntity> implements PrdDayDutyService {
|
|
private String HTTP_API_CODE = "Prd.DayDuty";
|
|
@Resource
|
private IFeignDataApi feignDataApi;
|
|
@Resource
|
private HttpsRequest httpsRequest;
|
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void syncData() {
|
Calendar calendar = Calendar.getInstance();
|
String endDate = DateUtils.format(calendar.getTime());
|
calendar.add(Calendar.DAY_OF_YEAR, -5);
|
String startDate = DateUtils.format(calendar.getTime());
|
|
|
FeignHttpApiDTO apiDTO = feignDataApi.getHttpApi(HTTP_API_CODE);
|
Map<String, String> params = new HashMap<>();
|
String responseStr = httpsRequest.doGet(apiDTO.getUrl() + "&startDate=" + startDate + "&endDate=" + endDate, params, "utf-8", "");
|
JSONObject responseObj = JSON.parseObject(responseStr);
|
if (!CommonConstant.STA_TRUE.equals(responseObj.get("sta").toString())) {
|
log.info("接口异常");
|
}
|
JSONArray dataArray = responseObj.getJSONArray(CommonConstant.ZX_RES);
|
if (CollectionUtils.isEmpty(dataArray)) {
|
return;
|
}
|
this.deleteByDate(startDate, endDate);
|
List<PrdDayDutyEntity> dataList = dataArray.toJavaList(PrdDayDutyEntity.class);
|
dataList.forEach(entity -> {
|
if (StringUtils.isNotBlank(entity.getBanci())) {
|
entity.setId(UUID.randomUUID().toString());
|
if (entity.getArrive() == null) {
|
entity.setArrive(entity.getNumber());
|
}
|
insert(entity);
|
}
|
});
|
}
|
|
private void deleteByDate(String start, String end) {
|
QueryWrapper<PrdDayDutyEntity> wrapper = new QueryWrapper<>();
|
wrapper.ge("date", start).le("date", end);
|
baseDao.delete(wrapper);
|
}
|
|
|
|
}
|