作物信息统计接口

This commit is contained in:
蒾酒
2024-11-27 00:37:49 +08:00
parent 032f980f34
commit fea04d914c
5 changed files with 48 additions and 2 deletions

View File

@ -1,7 +1,10 @@
package com.fastbee.crop.mapper;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fastbee.crop.domain.AgricultureCropYield;
import org.apache.ibatis.annotations.Mapper;
/**
* 作物产量记录Mapper接口
@ -9,7 +12,8 @@ import com.fastbee.crop.domain.AgricultureCropYield;
* @author kerwincui
* @date 2024-11-26
*/
public interface AgricultureCropYieldMapper
@Mapper
public interface AgricultureCropYieldMapper extends BaseMapper<AgricultureCropYield>
{
/**
* 查询作物产量记录

View File

@ -58,4 +58,6 @@ public interface IAgricultureCropYieldService
* @return 结果
*/
public int deleteAgricultureCropYieldById(Long id);
List<?> selectAgricultureCropYieldStatistics(AgricultureCropYield agricultureCropYield);
}

View File

@ -1,6 +1,12 @@
package com.fastbee.crop.service.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fastbee.crop.mapper.AgricultureCropYieldMapper;
@ -90,4 +96,26 @@ public class AgricultureCropYieldServiceImpl implements IAgricultureCropYieldSer
{
return agricultureCropYieldMapper.deleteAgricultureCropYieldById(id);
}
@Override
public List<?> selectAgricultureCropYieldStatistics(AgricultureCropYield agricultureCropYield) {
List<AgricultureCropYield> list = new LambdaQueryChainWrapper<>(agricultureCropYieldMapper)
.select(AgricultureCropYield::getYieldValue,AgricultureCropYield::getHarvestYear,AgricultureCropYield::getHarvestMonth,AgricultureCropYield::getHarvestMonth,AgricultureCropYield::getId)
.eq(agricultureCropYield.getCropType()!=null,AgricultureCropYield::getCropType, agricultureCropYield.getCropType())
.eq(agricultureCropYield.getHarvestYear()!=null,AgricultureCropYield::getHarvestYear,agricultureCropYield.getHarvestYear())
.list();
//分组统计不同月份的
Map<String, List<AgricultureCropYield>> collect = list.stream().collect(Collectors.groupingBy(AgricultureCropYield::getHarvestMonth));
List<HashMap<String, Object>> result = new ArrayList<>();
collect.forEach((month, cropYieldList) -> {
System.out.println("月份: " + month);
HashMap<String, Object> props = new HashMap<>();
props.put("name", month+"");
props.put("value",cropYieldList.get(0).getYieldValue());
result.add(props);
});
return result;
}
}