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