houzhongjian
2024-07-23 a6de490948278991e47952e90671ddba4555e9a2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.iailab.module.prod.service.impl;
 
import com.alibaba.fastjson.JSON;
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.CommonUtils;
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.PrdTimeDayDao;
import com.iailab.module.prod.entity.PrdTimeDayEntity;
import com.iailab.module.prod.service.PrdTimeDayService;
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 java.util.*;
 
/**
 * @author PanZhibao
 * @Description
 * @createTime 2024年06月16日
 */
@Slf4j
@Service
public class PrdTimeDayServiceImpl extends BaseServiceImpl<PrdTimeDayDao, PrdTimeDayEntity> implements PrdTimeDayService {
 
    private String HTTP_API_CODE = "Prd.PrdTimeDistByDate";
 
    @Resource
    private IFeignDataApi feignDataApi;
 
    @Resource
    private HttpsRequest httpsRequest;
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void syncData(String iRq) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.HOUR_OF_DAY, -12);
        String rq = StringUtils.isNotBlank(iRq) ? iRq : DateUtils.format(calendar.getTime());
        FeignHttpApiDTO apiDTO = feignDataApi.getHttpApi(HTTP_API_CODE);
        Map<String, String> params = new HashMap<>();
        String responseStr = httpsRequest.doGet(apiDTO.getUrl() + "&startDate=" + rq + "&endDate=" + rq, params, "utf-8", "");
        JSONObject responseObj = JSON.parseObject(responseStr);
        if (!CommonConstant.STA_TRUE.equals(responseObj.get("sta").toString())) {
            log.info("接口异常");
        }
        JSONObject dataObj = responseObj.getJSONObject(CommonConstant.ZX_RES);
        if (dataObj == null) {
            return;
        }
        deleteByDate(rq);
        JSONObject xxData = dataObj.getJSONObject("xx");
        PrdTimeDayEntity entity = new PrdTimeDayEntity();
        entity.setId(UUID.randomUUID().toString());
        entity.setCreateDate(new Date());
        entity.setDate(rq);
        entity.setType("xx");
        entity.setRunMinutes(CommonUtils.getJSONValue(xxData.get("runMinutes")));
        entity.setOverhaulMinutes(CommonUtils.getJSONValue(xxData.get("overhaulMinutes")));
        entity.setAffectMinutes(CommonUtils.getJSONValue(xxData.get("affectMinutes")));
        insert(entity);
    }
 
    private void deleteByDate(String date) {
        QueryWrapper<PrdTimeDayEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(date), "date", date);
        baseDao.delete(wrapper);
    }
}