parent
78e8d31dd7
commit
68fcfdd242
|
|
@ -6,6 +6,7 @@ import com.gunshi.project.hsz.common.model.JcskSlB;
|
|||
import com.gunshi.project.hsz.common.model.so.JcskSlBPageSo;
|
||||
import com.gunshi.project.hsz.common.validate.markers.Insert;
|
||||
import com.gunshi.project.hsz.common.validate.markers.Update;
|
||||
import com.gunshi.project.hsz.entity.dto.ExportCommonDto;
|
||||
import com.gunshi.project.hsz.entity.so.HisWaterDataPageSo;
|
||||
import com.gunshi.project.hsz.entity.vo.HisWaterDataVo;
|
||||
import com.gunshi.project.hsz.mapper.HisWaterDataMapper;
|
||||
|
|
@ -63,10 +64,14 @@ public class HisWaterDataController {
|
|||
|
||||
@Operation(summary = "导出")
|
||||
@PostMapping("/export")
|
||||
public void export(@RequestBody @Validated HisWaterDataPageSo pageSo, HttpServletResponse response) {
|
||||
pageSo.getPageSo().setPageSize(99999);
|
||||
Page<HisWaterDataVo> hisWaterDataPage = hisWaterDataService.pageQuery(pageSo);
|
||||
List<HisWaterDataVo> records = hisWaterDataPage.getRecords();
|
||||
public void export(@RequestBody ExportCommonDto dto, HttpServletResponse response) {
|
||||
List<HisWaterDataVo> records = hisWaterDataService.selectList(dto);
|
||||
hisWaterDataService.export(records,response);
|
||||
}
|
||||
|
||||
@Operation(summary = "年份列表")
|
||||
@GetMapping("/year/list")
|
||||
public R<List<HisWaterData>> yearList(){
|
||||
return R.ok(hisWaterDataService.yearList());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,5 +10,5 @@ import java.util.List;
|
|||
@Data
|
||||
public class HisWaterDataVo extends HisWaterData{
|
||||
|
||||
private List<HisWaterData> list;
|
||||
private List<HisWaterData> children;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.gunshi.project.hsz.mapper;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.gunshi.project.hsz.entity.dto.ExportCommonDto;
|
||||
import com.gunshi.project.hsz.entity.so.HisWaterDataPageSo;
|
||||
import com.gunshi.project.hsz.entity.vo.HisWaterDataVo;
|
||||
import com.gunshi.project.hsz.model.HisWaterData;
|
||||
|
|
@ -10,6 +11,8 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface HisWaterDataMapper extends BaseMapper<HisWaterData> {
|
||||
|
||||
|
|
@ -19,4 +22,18 @@ public interface HisWaterDataMapper extends BaseMapper<HisWaterData> {
|
|||
""")
|
||||
Page<HisWaterDataVo> queryPage(Page<Object> page, @Param("obj") HisWaterDataPageSo queryWrapper);
|
||||
|
||||
@Select("""
|
||||
<script>
|
||||
select * from his_water_data where type = 1
|
||||
<if test="dto.ids != null and dto.ids.size() > 0">
|
||||
and id in
|
||||
<foreach collection="dto.ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
order by year desc
|
||||
</script>
|
||||
""")
|
||||
List<HisWaterDataVo> selectYearList(@Param("dto") ExportCommonDto dto);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,9 +30,6 @@ public class HisWaterData {
|
|||
@Schema(description = "月份平均蓄水量")
|
||||
private BigDecimal avgWater;
|
||||
|
||||
@TableField(exist = false)
|
||||
@Schema(description = "年度总蓄水量")
|
||||
private BigDecimal totalWater;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import com.gunshi.project.hsz.entity.dto.ExportCommonDto;
|
||||
import com.gunshi.project.hsz.entity.so.HisWaterDataPageSo;
|
||||
import com.gunshi.project.hsz.entity.vo.HisWaterDataVo;
|
||||
import com.gunshi.project.hsz.mapper.HisWaterDataMapper;
|
||||
|
|
@ -48,9 +49,9 @@ public class HisWaterDataService extends ServiceImpl<HisWaterDataMapper, HisWate
|
|||
for (HisWaterDataVo record : records) {
|
||||
LambdaQueryWrapper<HisWaterData> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(HisWaterData::getYear, record.getYear())
|
||||
.eq(HisWaterData::getType,record.getType())
|
||||
.eq(HisWaterData::getType,2)
|
||||
.orderByAsc(HisWaterData::getMonth);
|
||||
record.setList(this.list(queryWrapper));
|
||||
record.setChildren(this.list(queryWrapper));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -58,7 +59,11 @@ public class HisWaterDataService extends ServiceImpl<HisWaterDataMapper, HisWate
|
|||
checkParam(dto);
|
||||
HisWaterData hisWaterData = new HisWaterData();
|
||||
BeanUtils.copyProperties(dto,hisWaterData);
|
||||
List<HisWaterData> list = dto.getList();
|
||||
List<HisWaterData> list = dto.getChildren();
|
||||
list.stream().forEach(o ->{
|
||||
o.setId(null);
|
||||
});
|
||||
hisWaterData.setId(null);
|
||||
list.add(hisWaterData);
|
||||
boolean flag = saveBatch(list);
|
||||
return flag;
|
||||
|
|
@ -75,8 +80,8 @@ public class HisWaterDataService extends ServiceImpl<HisWaterDataMapper, HisWate
|
|||
if(this.count(queryWrapper ) > 0){
|
||||
throw new IllegalArgumentException("该年份已存在历史降雨资料");
|
||||
}
|
||||
Long len = dto.getList().stream().map(HisWaterData::getMonth).distinct().collect(Collectors.counting());
|
||||
if(dto.getList().size() != len.intValue()){
|
||||
Long len = dto.getChildren().stream().map(HisWaterData::getMonth).distinct().collect(Collectors.counting());
|
||||
if(dto.getChildren().size() != len.intValue()){
|
||||
throw new IllegalArgumentException("月份不可重复");
|
||||
}
|
||||
}
|
||||
|
|
@ -88,7 +93,7 @@ public class HisWaterDataService extends ServiceImpl<HisWaterDataMapper, HisWate
|
|||
BeanUtils.copyProperties(dto,hisWaterData);
|
||||
updateById(hisWaterData);
|
||||
deleteMonthData(dto.getYear());
|
||||
List<HisWaterData> list = dto.getList();
|
||||
List<HisWaterData> list = dto.getChildren();
|
||||
return saveBatch(list);
|
||||
}
|
||||
|
||||
|
|
@ -139,8 +144,8 @@ public class HisWaterDataService extends ServiceImpl<HisWaterDataMapper, HisWate
|
|||
dataList.add(headerRow);
|
||||
|
||||
// 添加月份数据
|
||||
if (yearData.getList() != null) {
|
||||
for (HisWaterData monthData : yearData.getList()) {
|
||||
if (yearData.getChildren() != null) {
|
||||
for (HisWaterData monthData : yearData.getChildren()) {
|
||||
List<Object> monthRow = new ArrayList<>();
|
||||
monthRow.add(monthData.getMonth() + "月");
|
||||
monthRow.add(monthData.getAvgWater());
|
||||
|
|
@ -151,7 +156,7 @@ public class HisWaterDataService extends ServiceImpl<HisWaterDataMapper, HisWate
|
|||
// 添加年度总蓄水量行
|
||||
List<Object> totalRow = new ArrayList<>();
|
||||
totalRow.add("年度总蓄水量");
|
||||
totalRow.add(yearData.getTotalWater());
|
||||
totalRow.add(yearData.getAvgWater());
|
||||
dataList.add(totalRow);
|
||||
|
||||
// 添加空行分隔
|
||||
|
|
@ -174,4 +179,18 @@ public class HisWaterDataService extends ServiceImpl<HisWaterDataMapper, HisWate
|
|||
throw new RuntimeException("导出Excel失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
public List<HisWaterData> yearList() {
|
||||
LambdaQueryWrapper<HisWaterData> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(HisWaterData::getType,1);
|
||||
return this.baseMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
public List<HisWaterDataVo> selectList(ExportCommonDto dto) {
|
||||
List<HisWaterDataVo> hisWaterDataVos = this.baseMapper.selectYearList(dto);
|
||||
if(!hisWaterDataVos.isEmpty()){
|
||||
queryChild(hisWaterDataVos);
|
||||
}
|
||||
return hisWaterDataVos;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue