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 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 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 wrapper = new QueryWrapper<>(); wrapper.eq(StringUtils.isNotBlank(date), "date", date); baseDao.delete(wrapper); } }