| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.ExcelImportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import cn.afterturn.easypoi.excel.entity.ImportParams; |
| | | import cn.hutool.json.JSONObject; |
| | | 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.exception.ServiceException; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.WebUtils; |
| | | import com.ruoyi.system.export.OldsterImport; |
| | | import com.ruoyi.system.model.TNotice; |
| | | import com.ruoyi.system.model.TOldster; |
| | | import com.ruoyi.system.query.BannerListQuery; |
| | | import com.ruoyi.system.query.OldsterListQuery; |
| | | import com.ruoyi.system.service.TOldsterService; |
| | | import com.ruoyi.system.service.TOldsterService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.net.URLEncoder; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @since 2025-11-06 |
| | | */ |
| | | @RestController |
| | | @Slf4j |
| | | @RequestMapping("/t-oldster") |
| | | @Api(tags = "老人户籍信息") |
| | | public class TOldsterController { |
| | | @Autowired |
| | | private TOldsterService oldsterService; |
| | | @ApiOperation(value = "老人户籍信息分页列表") |
| | | @PostMapping(value = "/pageList") |
| | | public R<PageInfo<TOldster>> pageList(@RequestBody OldsterListQuery query) { |
| | | return R.ok(oldsterService.pageList(query)); |
| | | } |
| | | |
| | | @ApiOperation(value = "添加") |
| | | @Transactional |
| | | @Log(title = "老人户籍信息-添加", businessType = BusinessType.INSERT) |
| | | @PostMapping(value = "/add") |
| | | public R<Boolean> save(@RequestBody TOldster dto) { |
| | | oldsterService.save(dto); |
| | | return R.ok(); |
| | | } |
| | | @ApiOperation(value = "修改") |
| | | @Log(title = "老人户籍信息-修改", businessType = BusinessType.UPDATE) |
| | | @PostMapping(value = "/edit") |
| | | public R<Boolean> edit(@RequestBody TOldster dto) { |
| | | oldsterService.updateById(dto); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 查看老人户籍信息详情 |
| | | */ |
| | | @ApiOperation(value = "查看老人户籍信息详情") |
| | | @GetMapping(value = "/getDetailById") |
| | | public R<TOldster> getDetailById(@RequestParam String id) { |
| | | return R.ok(oldsterService.getById(id)); |
| | | } |
| | | |
| | | /** |
| | | * 删除老人户籍信息 |
| | | */ |
| | | @Log(title = "老人户籍信息-删除", businessType = BusinessType.DELETE) |
| | | @ApiOperation(value = "老人户籍信息-删除") |
| | | @DeleteMapping(value = "/deleteById") |
| | | public R<Boolean> deleteById(@RequestParam String id) { |
| | | return R.ok(oldsterService.removeById(id)); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除老人户籍信息 |
| | | */ |
| | | @Log(title = "老人户籍信息-批量删除", businessType = BusinessType.DELETE) |
| | | @ApiOperation(value = "老人户籍信息-批量删除") |
| | | @DeleteMapping(value = "/deleteByIds") |
| | | public R<Boolean> deleteByIds(@RequestBody List<String> ids) { |
| | | return R.ok(oldsterService.removeByIds(ids)); |
| | | } |
| | | @ApiOperation(value = "导入模板下载") |
| | | @GetMapping("/import-template") |
| | | public void importTemplate() { |
| | | List<OldsterImport> assetHouseInspectionImports = new ArrayList<>(); |
| | | OldsterImport temp = new OldsterImport(); |
| | | assetHouseInspectionImports.add(temp); |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), OldsterImport.class, assetHouseInspectionImports); |
| | | HttpServletResponse response = WebUtils.response(); |
| | | ServletOutputStream outputStream = null; |
| | | try { |
| | | String fileName = URLEncoder.encode("老人户籍信息导入模板.xls", "utf-8"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + fileName); |
| | | response.setHeader("content-Type", "application/vnd.ms-excel"); |
| | | response.setHeader("Pragma", "no-cache"); |
| | | response.setHeader("Cache-Control", "no-cache"); |
| | | outputStream = response.getOutputStream(); |
| | | workbook.write(outputStream); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | System.out.println("老人户籍信息导入模板下载失败!"); |
| | | } finally { |
| | | try { |
| | | outputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | @Log(title = "老人户籍信息-老人户籍信息导入", businessType = BusinessType.INSERT) |
| | | @ApiOperation(value = "老人户籍信息导入") |
| | | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) |
| | | @PostMapping("/import") |
| | | public R<String> importInfo(@RequestPart("file") MultipartFile file) { |
| | | List<TOldster> oldsters = new ArrayList<>(); |
| | | ImportParams params = new ImportParams(); |
| | | params.setHeadRows(1); //表头行数 |
| | | InputStream inputStream = null; |
| | | List<OldsterImport> assetHouseInspectionImports; |
| | | try { |
| | | inputStream = file.getInputStream(); |
| | | assetHouseInspectionImports = ExcelImportUtil.importExcel(inputStream, |
| | | OldsterImport.class, params); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("老人户籍信息导入失败:{}", e.getMessage()); |
| | | throw new ServiceException("老人户籍信息导入失败!"); |
| | | } finally { |
| | | try { |
| | | inputStream.close(); |
| | | } catch (IOException e) { |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | | if (CollectionUtils.isEmpty(assetHouseInspectionImports)) { |
| | | throw new ServiceException("老人户籍信息数据为空!"); |
| | | } |
| | | JSONObject result = new JSONObject(); |
| | | int i = 1; |
| | | for (OldsterImport oldsterImport : assetHouseInspectionImports) { |
| | | if (!StringUtils.hasLength(oldsterImport.getOldsterName())){ |
| | | result.append("第"+i+"行:[", "老人姓名"+"]不能为空"); |
| | | i++; |
| | | continue; |
| | | } |
| | | if (!StringUtils.hasLength(oldsterImport.getOldsterSexStr())){ |
| | | result.append("第"+i+"行:[", "老人性别"+"]不能为空"); |
| | | i++; |
| | | continue; |
| | | } |
| | | if (!StringUtils.hasLength(oldsterImport.getContactPhone())){ |
| | | result.append("第"+i+"行:[", "联系方式"+"]不能为空"); |
| | | i++; |
| | | continue; |
| | | } |
| | | if (!StringUtils.hasLength(oldsterImport.getOldsterTypeStr())){ |
| | | result.append("第"+i+"行:[", "人员类型"+"]不能为空"); |
| | | i++; |
| | | continue; |
| | | } |
| | | if (!StringUtils.hasLength(oldsterImport.getAddress())){ |
| | | result.append("第"+i+"行:[", "居住地址"+"]不能为空"); |
| | | i++; |
| | | continue; |
| | | } |
| | | TOldster tOldster = new TOldster(); |
| | | BeanUtils.copyProperties(oldsterImport, tOldster); |
| | | if(StringUtils.hasLength(oldsterImport.getBirthDateStr())){ |
| | | try{ |
| | | LocalDate localDate = DateUtils.stringToLocalDate(oldsterImport.getBirthDateStr()); |
| | | tOldster.setBirthDate(localDate); |
| | | }catch (Exception e){ |
| | | result.append("第"+i+"行:[", "出生日期"+"]格式错误"); |
| | | i++; |
| | | continue; |
| | | } |
| | | } |
| | | switch (oldsterImport.getOldsterSexStr()){ |
| | | case "男": |
| | | tOldster.setOldsterSex(1); |
| | | break; |
| | | case "女": |
| | | tOldster.setOldsterSex(2); |
| | | break; |
| | | } |
| | | switch (oldsterImport.getOldsterTypeStr()){ |
| | | case "独居老人": |
| | | tOldster.setOldsterType(1); |
| | | break; |
| | | case "高龄老人": |
| | | tOldster.setOldsterType(2); |
| | | break; |
| | | case "散居特困供养老人": |
| | | tOldster.setOldsterType(3); |
| | | break; |
| | | case "失能老人": |
| | | tOldster.setOldsterType(4); |
| | | break; |
| | | } |
| | | oldsters.add(tOldster); |
| | | i++; |
| | | } |
| | | oldsterService.saveBatch(oldsters); |
| | | if(!result.isEmpty()){ |
| | | return R.fail(result.toString()); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | } |
| | | |