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.baomidou.mybatisplus.core.metadata.IPage; import com.iailab.framework.common.constant.Constant; import com.iailab.common.dto.echarts.BarLineDTO; import com.iailab.common.enums.CommonConstant; import com.iailab.framework.common.page.PageData; import com.iailab.framework.common.service.impl.BaseServiceImpl; import com.iailab.common.utils.CommonUtils; import com.iailab.framework.common.util.object.ConvertUtils; 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.PrdPlanYearDao; import com.iailab.module.prod.dto.PrdPlanYearDTO; import com.iailab.module.prod.entity.PrdPlanYearEntity; import com.iailab.module.prod.service.PrdPlanYearService; 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.math.BigDecimal; import java.util.*; /** * @author PanZhibao * @Description * @createTime 2024年05月14日 */ @Slf4j @Service public class PrdPlanYearServiceImpl extends BaseServiceImpl implements PrdPlanYearService { private String HTTP_API_CODE = "Prd.YearPEI"; @Resource private IFeignDataApi feignDataApi; @Resource private HttpsRequest httpsRequest; @Override public PageData page(Map params) { IPage page = baseDao.selectPage( getPage(params, Constant.CREATE_DATE, false), getWrapper(params) ); return getPageData(page, PrdPlanYearDTO.class); } private QueryWrapper getWrapper(Map params){ String rq = (String)params.get("rq"); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq(StringUtils.isNotBlank(rq), "rq", rq) .orderByAsc("rq"); return wrapper; } @Override public PrdPlanYearDTO get(String id) { PrdPlanYearEntity entity = baseDao.selectById(id); return ConvertUtils.sourceToTarget(entity, PrdPlanYearDTO.class); } @Override public void save(PrdPlanYearDTO dto) { PrdPlanYearEntity entity = ConvertUtils.sourceToTarget(dto, PrdPlanYearEntity.class); insert(entity); } @Override public void update(PrdPlanYearDTO dto) { PrdPlanYearEntity entity = ConvertUtils.sourceToTarget(dto, PrdPlanYearEntity.class); updateById(entity); } @Override @Transactional(rollbackFor = Exception.class) public void delete(String[] ids) { baseDao.deleteBatchIds(Arrays.asList(ids)); } @Override public BarLineDTO barLine(String length) { return null; } @Override public BigDecimal currentValue() { return null; } @Override @Transactional(rollbackFor = Exception.class) public void syncData() { FeignHttpApiDTO apiDTO = feignDataApi.getHttpApi(HTTP_API_CODE); Map params = new HashMap<>(); String responseStr = httpsRequest.doGet(apiDTO.getUrl(), params, "utf-8", ""); JSONObject responseObj = JSON.parseObject(responseStr); if (!CommonConstant.STA_TRUE.equals(responseObj.get("sta").toString())) { log.info("接口异常"); } JSONObject res = responseObj.getJSONObject(CommonConstant.ZX_RES); JSONObject yearData = res.getJSONObject("yearData"); this.deleteByYear(yearData.get("year").toString()); PrdPlanYearEntity entity = new PrdPlanYearEntity(); entity.setId(UUID.randomUUID().toString()); entity.setRq(yearData.get("year").toString()); entity.setXxPlan(CommonUtils.getJSONValue(yearData.get("xxPlan"))); entity.setXxPerformance(CommonUtils.getJSONValue(yearData.get("xxPerformance"))); entity.setZqPlan(CommonUtils.getJSONValue(yearData.get("zqPlan"))); entity.setZqPerformance(CommonUtils.getJSONValue(yearData.get("zqPerformance"))); entity.setCreateDate(new Date()); entity.setUpdateDate(new Date()); insert(entity); } private void deleteByYear(String rq) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq(StringUtils.isNotBlank(rq), "rq", rq); baseDao.delete(wrapper); } }