| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.entity.TDept; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.WebUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.system.dto.AddDrDisplacementDTO; |
| | | import com.ruoyi.system.model.DrDisplacement; |
| | | import com.ruoyi.system.model.DrDisplacementHouse; |
| | | import com.ruoyi.system.model.DrDisplacementReturnHouse; |
| | | import com.ruoyi.system.model.LandReported; |
| | | import com.ruoyi.system.query.DrDisplacementListQuery; |
| | | import com.ruoyi.system.query.LandReportedListQuery; |
| | | import com.ruoyi.system.service.DrDisplacementHouseService; |
| | | import com.ruoyi.system.service.DrDisplacementReturnHouseService; |
| | | import com.ruoyi.system.service.DrDisplacementService; |
| | | import com.ruoyi.system.service.LandReportedService; |
| | | import com.ruoyi.system.vo.DrDisplacementListVO; |
| | | import com.ruoyi.system.vo.DrDisplacementStatisticsVO; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.ehcache.impl.persistence.DefaultDiskResourceService; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.net.URLEncoder; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @since 2025-10-17 |
| | | */ |
| | | @RestController |
| | | @Api(tags = "拆迁情况管理") |
| | | @RequestMapping("/dr-displacement") |
| | | public class DrDisplacementController { |
| | | |
| | | @Resource |
| | | private DrDisplacementService drDisplacementService; |
| | | @Resource |
| | | private DrDisplacementHouseService drDisplacementHouseService; |
| | | @Resource |
| | | private DrDisplacementReturnHouseService drDisplacementReturnHouseService; |
| | | |
| | | @ApiOperation(value = "拆迁统计") |
| | | @PostMapping(value = "/statistics") |
| | | public R<Map<Double,Map<String,Integer>>> statistics() { |
| | | List<DrDisplacementReturnHouse> houses = drDisplacementReturnHouseService.list(); |
| | | |
| | | // 定义需要统计的面积段 |
| | | List<Double> areaList = Arrays.asList(30.0, 60.0, 80.0, 90.0, 100.0, 110.0, 120.0); |
| | | |
| | | // 初始化结果集 |
| | | Map<Double, Map<String,Integer>> result = areaList.stream() |
| | | .collect(Collectors.toMap( |
| | | area -> area, |
| | | area -> { |
| | | Map<String, Integer> typeMap = new HashMap<>(); |
| | | typeMap.put("营业房", 0); |
| | | typeMap.put("库房", 0); |
| | | typeMap.put("住房", 0); |
| | | return typeMap; |
| | | } |
| | | )); |
| | | |
| | | // 按面积分组统计 |
| | | Map<Double, List<DrDisplacementReturnHouse>> groupedByArea = houses.stream() |
| | | .collect(Collectors.groupingBy(DrDisplacementReturnHouse::getArea)); |
| | | |
| | | // 处理统计数据 |
| | | groupedByArea.forEach((area, houseList) -> { |
| | | if (result.containsKey(area)) { |
| | | houseList.forEach(house -> { |
| | | String returnType = getReturnTypeString(house.getReturnType()); |
| | | result.get(area).merge(returnType, house.getQuantity(), Integer::sum); |
| | | }); |
| | | } |
| | | }); |
| | | return R.ok(result); |
| | | } |
| | | |
| | | |
| | | |
| | | private String getReturnTypeString(Integer returnType) { |
| | | switch (returnType) { |
| | | case 0: return "营业房"; |
| | | case 1: return "住房"; |
| | | case 2: return "库房"; |
| | | default: return "未知"; |
| | | } |
| | | } |
| | | @ApiOperation(value = "拆迁情况分页列表") |
| | | @PostMapping(value = "/pageList") |
| | | public R<DrDisplacementListVO> pageList(@RequestBody DrDisplacementListQuery query) { |
| | | DrDisplacementListVO drDisplacementListVO = new DrDisplacementListVO(); |
| | | PageInfo<DrDisplacement> drDisplacementPageInfo = drDisplacementService.pageList(query); |
| | | if (drDisplacementPageInfo.getRecords().isEmpty()){ |
| | | drDisplacementListVO.setTotalCount(0); |
| | | drDisplacementListVO.setTotalArea(0.0); |
| | | drDisplacementListVO.setPageList(new PageInfo<>()); |
| | | return R.ok(drDisplacementListVO); |
| | | } |
| | | Map<Integer, List<DrDisplacementHouse>> houseMap = drDisplacementHouseService.lambdaQuery() |
| | | .in(DrDisplacementHouse::getDisplacementId, drDisplacementPageInfo.getRecords() |
| | | .stream().map(DrDisplacement::getId).collect(Collectors.toList())) |
| | | .list().stream().collect(Collectors.groupingBy(DrDisplacementHouse::getDisplacementId)); |
| | | |
| | | for (DrDisplacement record : drDisplacementPageInfo.getRecords()) { |
| | | StringBuilder temp = new StringBuilder(); |
| | | List<DrDisplacementHouse> drDisplacementHouses = houseMap.get(record.getId()); |
| | | if (drDisplacementHouses!=null){ |
| | | for (DrDisplacementHouse house : drDisplacementHouses) { |
| | | temp.append(house.getConstructionType()).append(","); |
| | | } |
| | | record.setConstructionTypes(temp.substring(0, temp.length() - 1)); |
| | | } |
| | | } |
| | | List<DrDisplacement> list = drDisplacementService.lambdaQuery() |
| | | .like(StringUtils.hasLength(query.getName()), DrDisplacement::getName, query.getName()) |
| | | .eq(query.getCommunityId() != null, DrDisplacement::getCommunityId, query.getCommunityId()) |
| | | .like(StringUtils.hasLength(query.getPhone()), DrDisplacement::getPhone, query.getPhone()) |
| | | .like(StringUtils.hasLength(query.getIdCard()), DrDisplacement::getIdCard, query.getIdCard()).list(); |
| | | double totalArea = 0.0; |
| | | for (DrDisplacement drDisplacement : list) { |
| | | totalArea += drDisplacement.getTotalArea(); |
| | | } |
| | | drDisplacementListVO.setTotalCount(list.size()); |
| | | drDisplacementListVO.setTotalArea(totalArea); |
| | | drDisplacementListVO.setPageList(drDisplacementPageInfo); |
| | | return R.ok(drDisplacementListVO); |
| | | } |
| | | @ApiOperation(value = "拆迁情况导出") |
| | | @Log(title = "拆迁情况导出", businessType = BusinessType.OTHER) |
| | | @PostMapping(value = "/export") |
| | | public void export(@RequestBody DrDisplacementListQuery query) { |
| | | List<DrDisplacement> list = drDisplacementService.lambdaQuery() |
| | | .like(StringUtils.hasLength(query.getName()), DrDisplacement::getName, query.getName()) |
| | | .eq(query.getCommunityId() != null, DrDisplacement::getCommunityId, query.getCommunityId()) |
| | | .like(StringUtils.hasLength(query.getPhone()), DrDisplacement::getPhone, query.getPhone()) |
| | | .like(StringUtils.hasLength(query.getIdCard()), DrDisplacement::getIdCard, query.getIdCard()).list(); |
| | | if (!list.isEmpty()){ |
| | | Map<Integer, List<DrDisplacementHouse>> houseMap = drDisplacementHouseService.lambdaQuery() |
| | | .in(DrDisplacementHouse::getDisplacementId, list |
| | | .stream().map(DrDisplacement::getId).collect(Collectors.toList())) |
| | | .list().stream().collect(Collectors.groupingBy(DrDisplacementHouse::getDisplacementId)); |
| | | for (DrDisplacement record : list) { |
| | | StringBuilder temp = new StringBuilder(); |
| | | List<DrDisplacementHouse> drDisplacementHouses = houseMap.get(record.getId()); |
| | | if (drDisplacementHouses!=null){ |
| | | for (DrDisplacementHouse house : drDisplacementHouses) { |
| | | temp.append(house.getConstructionType()).append(","); |
| | | } |
| | | record.setConstructionTypes(temp.substring(0, temp.length() - 1)); |
| | | } |
| | | } |
| | | } |
| | | //1.获取excel模板 |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), DrDisplacement.class, list); |
| | | HttpServletResponse response = WebUtils.response(); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | ServletOutputStream outputStream = null; |
| | | try { |
| | | String fileName = URLEncoder.encode("拆迁情况.xls", "utf-8"); |
| | | response.setHeader("Content-dispodition", "attachment;filename=" + fileName); |
| | | outputStream = response.getOutputStream(); |
| | | workbook.write(outputStream); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | outputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | @ApiOperation(value = "添加") |
| | | @Transactional |
| | | @Log(title = "拆迁情况-添加", businessType = BusinessType.INSERT) |
| | | @PostMapping(value = "/add") |
| | | public R<Boolean> save(@RequestBody AddDrDisplacementDTO entity) { |
| | | drDisplacementService.save(entity); |
| | | List<DrDisplacementHouse> drDisplacementHouses = entity.getDrDisplacementHouses(); |
| | | for (DrDisplacementHouse drDisplacementHouse : drDisplacementHouses) { |
| | | drDisplacementHouse.setDisplacementId(entity.getId()); |
| | | } |
| | | drDisplacementHouseService.saveBatch(drDisplacementHouses); |
| | | List<DrDisplacementReturnHouse> drDisplacementReturnHouses = entity.getDrDisplacementReturnHouses(); |
| | | for (DrDisplacementReturnHouse drDisplacementReturnHouse : drDisplacementReturnHouses) { |
| | | drDisplacementReturnHouse.setDisplacementId(entity.getId()); |
| | | } |
| | | drDisplacementReturnHouseService.saveBatch(entity.getDrDisplacementReturnHouses()); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation(value = "修改") |
| | | @Transactional |
| | | @Log(title = "拆迁情况-修改", businessType = BusinessType.UPDATE) |
| | | @PostMapping(value = "/edit") |
| | | public R<Boolean> edit(@RequestBody AddDrDisplacementDTO entity) { |
| | | drDisplacementService.updateById(entity); |
| | | drDisplacementHouseService.remove(new LambdaQueryWrapper<DrDisplacementHouse>() |
| | | .eq(DrDisplacementHouse::getDisplacementId, entity.getId())); |
| | | List<DrDisplacementHouse> drDisplacementHouses = entity.getDrDisplacementHouses(); |
| | | for (DrDisplacementHouse drDisplacementHouse : drDisplacementHouses) { |
| | | drDisplacementHouse.setDisplacementId(entity.getId()); |
| | | } |
| | | drDisplacementHouseService.saveBatch(drDisplacementHouses); |
| | | drDisplacementReturnHouseService.remove(new LambdaQueryWrapper<DrDisplacementReturnHouse>() |
| | | .eq(DrDisplacementReturnHouse::getDisplacementId, entity.getId())); |
| | | List<DrDisplacementReturnHouse> drDisplacementReturnHouses = entity.getDrDisplacementReturnHouses(); |
| | | for (DrDisplacementReturnHouse drDisplacementReturnHouse : drDisplacementReturnHouses) { |
| | | drDisplacementReturnHouse.setDisplacementId(entity.getId()); |
| | | } |
| | | drDisplacementReturnHouseService.saveBatch(entity.getDrDisplacementReturnHouses()); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ApiOperation(value = "详情") |
| | | @GetMapping(value = "/detail") |
| | | public R<AddDrDisplacementDTO> detail(String id) { |
| | | AddDrDisplacementDTO addDrDisplacementDTO = new AddDrDisplacementDTO(); |
| | | DrDisplacement drDisplacement = drDisplacementService.getById(id); |
| | | BeanUtils.copyProperties(drDisplacement, addDrDisplacementDTO); |
| | | List<DrDisplacementHouse> drDisplacementHouses = drDisplacementHouseService.lambdaQuery().eq(DrDisplacementHouse::getDisplacementId, id).list(); |
| | | List<DrDisplacementReturnHouse> drDisplacementReturnHouses = drDisplacementReturnHouseService.lambdaQuery().eq(DrDisplacementReturnHouse::getDisplacementId, id).list(); |
| | | addDrDisplacementDTO.setDrDisplacementHouses(drDisplacementHouses); |
| | | addDrDisplacementDTO.setDrDisplacementReturnHouses(drDisplacementReturnHouses); |
| | | return R.ok(addDrDisplacementDTO); |
| | | } |
| | | |
| | | @Log(title = "拆迁情况-删除", businessType = BusinessType.DELETE) |
| | | @Transactional |
| | | @ApiOperation(value = "拆迁情况-删除") |
| | | @DeleteMapping(value = "/delete") |
| | | public R delete(@RequestParam String ids) { |
| | | drDisplacementService.removeBatchByIds(Arrays.asList(ids.split(","))); |
| | | drDisplacementHouseService.remove(new LambdaQueryWrapper<DrDisplacementHouse>() |
| | | .in(DrDisplacementHouse::getDisplacementId, Arrays.asList(ids.split(",")))); |
| | | drDisplacementReturnHouseService.remove(new LambdaQueryWrapper<DrDisplacementReturnHouse>() |
| | | .in(DrDisplacementReturnHouse::getDisplacementId, Arrays.asList(ids.split(",")))); |
| | | return R.ok(); |
| | | } |
| | | } |