|
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.dto.echarts.SeriesItem;
|
import com.iailab.common.enums.CommonConstant;
|
import com.iailab.framework.common.page.PageData;
|
import com.iailab.framework.common.service.impl.BaseServiceImpl;
|
import com.iailab.framework.common.util.object.ConvertUtils;
|
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.PrdDayProdDao;
|
import com.iailab.module.prod.dao.PrdPlanMonDao;
|
import com.iailab.module.prod.dto.PrdDayProdDTO;
|
import com.iailab.module.prod.entity.PrdDayProdEntity;
|
import com.iailab.module.prod.entity.PrdPlanMonEntity;
|
import com.iailab.module.prod.service.PrdDayProdService;
|
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 javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.text.SimpleDateFormat;
|
import java.time.LocalDate;
|
import java.time.format.DateTimeFormatter;
|
import java.util.*;
|
|
/**
|
* @author PanZhibao
|
* @Description
|
* @createTime 2024年05月14日
|
*/
|
@Slf4j
|
@Service
|
public class PrdDayProdServiceImpl extends BaseServiceImpl<PrdDayProdDao, PrdDayProdEntity> implements PrdDayProdService {
|
|
@Resource
|
private PrdPlanMonDao prdPlanMonDao;
|
|
private String HTTP_API_CODE = "Prd.DayProd";
|
|
@Resource
|
private IFeignDataApi feignDataApi;
|
|
@Resource
|
private HttpsRequest httpsRequest;
|
|
@Override
|
public PageData<PrdDayProdDTO> page(Map<String, Object> params) {
|
IPage<PrdDayProdEntity> page = baseDao.selectPage(
|
getPage(params, Constant.CREATE_DATE, false),
|
getWrapper(params)
|
);
|
return getPageData(page, PrdDayProdDTO.class);
|
}
|
|
private QueryWrapper<PrdDayProdEntity> getWrapper(Map<String, Object> params){
|
String rq = (String)params.get("rq");
|
|
QueryWrapper<PrdDayProdEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq(StringUtils.isNotBlank(rq), "rq", rq)
|
.orderByAsc("rq");
|
|
return wrapper;
|
}
|
|
@Override
|
public PrdDayProdDTO get(String id) {
|
PrdDayProdEntity entity = baseDao.selectById(id);
|
|
return ConvertUtils.sourceToTarget(entity, PrdDayProdDTO.class);
|
}
|
|
@Override
|
public void save(PrdDayProdDTO dto) {
|
PrdDayProdEntity entity = ConvertUtils.sourceToTarget(dto, PrdDayProdEntity.class);
|
|
insert(entity);
|
}
|
|
@Override
|
public void update(PrdDayProdDTO dto) {
|
PrdDayProdEntity entity = ConvertUtils.sourceToTarget(dto, PrdDayProdEntity.class);
|
|
updateById(entity);
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void delete(String[] ids) {
|
baseDao.deleteBatchIds(Arrays.asList(ids));
|
}
|
|
@Override
|
public BarLineDTO barLine(String length,String type) {
|
|
BarLineDTO barLineDTO = new BarLineDTO();
|
List<SeriesItem> seriesItemList = new ArrayList<>();
|
List<Object[]> data = new ArrayList();
|
//获取当前月份天数
|
int lengthOfMonth = LocalDate.now().lengthOfMonth();
|
|
//获取月计划
|
PrdPlanMonEntity planMonEntity = prdPlanMonDao.selectOne(new QueryWrapper<PrdPlanMonEntity>()
|
.eq("rq", new SimpleDateFormat("MM").format(new Date()))
|
);
|
BigDecimal planDay = planMonEntity==null?new BigDecimal(0):planMonEntity.getXxPlan().divide(new BigDecimal(lengthOfMonth),2,BigDecimal.ROUND_HALF_UP);
|
|
switch (type) {
|
case "混煤":
|
this.list().stream().forEach(
|
item->{
|
Object[] dataItem = new Object[2];
|
dataItem[0] = item.getRq();
|
dataItem[1] = item.getMixedCoal();
|
if(item.getMixedCoal()!=null){
|
data.add(dataItem);
|
}
|
barLineDTO.setValueName("混煤产量");
|
}
|
);
|
break;
|
case "原煤":
|
this.list().stream().forEach(
|
item->{
|
Object[] dataItem = new Object[2];
|
dataItem[0] = item.getRq();
|
dataItem[1] = item.getRawCoal();
|
if(item.getRawCoal()!=null){
|
data.add(dataItem);
|
}
|
barLineDTO.setValueName("原煤入洗量");
|
}
|
);
|
break;
|
case "洗中块":
|
this.list().stream().forEach(
|
item->{
|
Object[] dataItem = new Object[2];
|
dataItem[0] = item.getRq();
|
dataItem[1] = item.getMediumCoal();
|
if(item.getMediumCoal()!=null){
|
data.add(dataItem);
|
}
|
barLineDTO.setValueName("洗中块产量");
|
}
|
);
|
break;
|
case "洗小块":
|
this.list().stream().forEach(
|
item->{
|
Object[] dataItem = new Object[2];
|
dataItem[0] = item.getRq();
|
dataItem[1] = item.getSmallCoal();
|
if(item.getSmallCoal()!=null){
|
data.add(dataItem);
|
}
|
barLineDTO.setValueName("洗小块产量");
|
}
|
);
|
break;
|
case "矸石":
|
this.list().stream().forEach(
|
item->{
|
Object[] dataItem = new Object[2];
|
dataItem[0] = item.getRq();
|
dataItem[1] = item.getGangue();
|
if(item.getGangue()!=null){
|
data.add(dataItem);
|
}
|
barLineDTO.setValueName("矸石产量");
|
}
|
);
|
break;
|
default:
|
break;
|
}
|
|
SeriesItem seriesItem = new SeriesItem();
|
seriesItem.setData(data);
|
seriesItemList.add(seriesItem);
|
//barLineDTO.setLegend(this.getLastMonthDates(Integer.parseInt(length)));
|
barLineDTO.setSeries(seriesItemList);
|
return barLineDTO;
|
}
|
|
@Override
|
public BigDecimal currentValue(String type) {
|
switch (type) {
|
case "混煤":
|
//混煤
|
return baseDao.selectOne(
|
new QueryWrapper<PrdDayProdEntity>()
|
.eq("rq",new SimpleDateFormat("yyyy-MM-dd").format(new Date())))==null
|
?new BigDecimal(0)
|
:baseDao.selectOne(
|
new QueryWrapper<PrdDayProdEntity>()
|
.eq("rq",new SimpleDateFormat("yyyy-MM-dd").format(new Date()))).getMixedCoal();
|
case "原煤":
|
//入洗量
|
return baseDao.selectOne(
|
new QueryWrapper<PrdDayProdEntity>()
|
.eq("rq",new SimpleDateFormat("yyyy-MM-dd").format(new Date())))==null
|
?new BigDecimal(0)
|
:baseDao.selectOne(
|
new QueryWrapper<PrdDayProdEntity>()
|
.eq("rq",new SimpleDateFormat("yyyy-MM-dd").format(new Date()))).getRawCoal();
|
case "洗中块":
|
return baseDao.selectOne(
|
new QueryWrapper<PrdDayProdEntity>()
|
.eq("rq",new SimpleDateFormat("yyyy-MM-dd").format(new Date())))==null
|
?new BigDecimal(0)
|
:baseDao.selectOne(
|
new QueryWrapper<PrdDayProdEntity>()
|
.eq("rq",new SimpleDateFormat("yyyy-MM-dd").format(new Date()))).getMediumCoal();
|
case "洗小块":
|
return baseDao.selectOne(
|
new QueryWrapper<PrdDayProdEntity>()
|
.eq("rq",new SimpleDateFormat("yyyy-MM-dd").format(new Date())))==null
|
?new BigDecimal(0)
|
:baseDao.selectOne(
|
new QueryWrapper<PrdDayProdEntity>()
|
.eq("rq",new SimpleDateFormat("yyyy-MM-dd").format(new Date()))).getSmallCoal();
|
case "矸石":
|
return baseDao.selectOne(
|
new QueryWrapper<PrdDayProdEntity>()
|
.eq("rq",new SimpleDateFormat("yyyy-MM-dd").format(new Date())))==null
|
?new BigDecimal(0)
|
:baseDao.selectOne(
|
new QueryWrapper<PrdDayProdEntity>()
|
.eq("rq",new SimpleDateFormat("yyyy-MM-dd").format(new Date()))).getGangue();
|
default:
|
break;
|
}
|
return null;
|
}
|
public List<String> getLastMonthDates(int length) {
|
List<String> dateList = new ArrayList<>();
|
LocalDate currentDate = LocalDate.now();
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
for (int i = length-1; i >= 0; i--) {
|
dateList.add(currentDate.minusDays(i).format(formatter));
|
}
|
|
return dateList;
|
}
|
|
public List<PrdDayProdEntity> list(){
|
List<PrdDayProdEntity> prdDayProdList = baseDao.selectList(
|
new QueryWrapper<PrdDayProdEntity>()
|
.le("rq",new SimpleDateFormat("yyyy-MM-dd").format(new Date()))
|
.ge("rq",LocalDate.now().minusDays(29).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))
|
.orderByAsc("rq")
|
);
|
return prdDayProdList;
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void syncData(String paramDate) {
|
Calendar calendar = Calendar.getInstance();
|
calendar.add(Calendar.HOUR_OF_DAY, -12);
|
String rq = StringUtils.isNotBlank(paramDate) ? paramDate : DateUtils.format(calendar.getTime());
|
FeignHttpApiDTO apiDTO = feignDataApi.getHttpApi(HTTP_API_CODE);
|
Map<String, String> params = new HashMap<>();
|
String responseStr = httpsRequest.doGet(apiDTO.getUrl() + "&date=" + 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;
|
}
|
this.deleteByDate(rq);
|
PrdDayProdEntity entity = dataObj.toJavaObject(PrdDayProdEntity.class);
|
entity.setId(UUID.randomUUID().toString());
|
entity.setRq(rq);
|
entity.setCreateDate(new Date());
|
entity.setUpdateDate(new Date());
|
insert(entity);
|
}
|
|
private void deleteByDate(String date) {
|
QueryWrapper<PrdDayProdEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq(StringUtils.isNotBlank(date), "rq", date);
|
baseDao.delete(wrapper);
|
}
|
}
|