| | |
| | | */ |
| | | package org.sxkj.system.controller; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.tenant.annotation.NonDS; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.BeanUtil; |
| | | import org.springblade.core.tool.utils.DateUtil; |
| | | import org.sxkj.system.entity.Region; |
| | | import org.sxkj.system.excel.DeptImportExcel; |
| | | import org.sxkj.system.excel.RegionExcel; |
| | | import org.sxkj.system.excel.RegionImportExcel; |
| | | import org.sxkj.system.excel.RegionImporter; |
| | | import org.sxkj.system.param.RegionAddParam; |
| | | import org.sxkj.system.param.RegionPageParam; |
| | | import org.sxkj.system.service.IRegionService; |
| | | import org.sxkj.system.util.excel.RegionSheetWriteHandler; |
| | | import org.sxkj.system.vo.RegionVO; |
| | | import org.sxkj.system.vo.TreeVo; |
| | | import org.sxkj.system.wrapper.RegionWrapper; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.validation.Valid; |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 行政区划表 控制器 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 行政区划表 自定义分页 |
| | | */ |
| | | @GetMapping("/page") |
| | | @ApiOperationSupport(order = 3) |
| | | @ApiOperation(value = "分页", notes = " ") |
| | | public R<IPage<RegionVO>> page(RegionPageParam regionPageParam, Query query) { |
| | | IPage<RegionVO> pages = regionService.selectRegionPage(Condition.getPage(query), regionPageParam); |
| | | return R.data(pages); |
| | | } |
| | | |
| | | /** |
| | | * 懒加载列表 |
| | | */ |
| | | @GetMapping("/lazy-list") |
| | |
| | | /** |
| | | * 新增 行政区划表 |
| | | */ |
| | | @PostMapping("/save") |
| | | @ApiOperationSupport(order = 5) |
| | | @ApiOperation(value = "新增", notes = "传入region") |
| | | @ApiLog("行政区划数据新增") |
| | | public R save(@Valid @RequestBody Region region) { |
| | | return R.status(regionService.save(region)); |
| | | } |
| | | // @PostMapping("/save") |
| | | // @ApiOperationSupport(order = 5) |
| | | // @ApiOperation(value = "新增", notes = "传入region") |
| | | // @ApiLog("行政区划数据新增") |
| | | // public R save(@Valid @RequestBody RegionAddParam region) { |
| | | // Region regionEntity = Objects.requireNonNull(BeanUtil.copy(region, Region.class)); |
| | | // return R.status(regionService.save(regionEntity)); |
| | | // } |
| | | |
| | | /** |
| | | * 修改 行政区划表 |
| | |
| | | @ApiOperation(value = "修改", notes = "传入region") |
| | | @ApiLog("行政区划数据修改") |
| | | public R update(@Valid @RequestBody Region region) { |
| | | region.setUpdateTime(DateUtil.now()); |
| | | return R.status(regionService.updateById(region)); |
| | | } |
| | | |
| | |
| | | @ApiOperationSupport(order = 7) |
| | | @ApiOperation(value = "新增或修改", notes = "传入region") |
| | | @ApiLog("行政区划数据新增或修改") |
| | | public R submit(@Valid @RequestBody Region region) { |
| | | return R.status(regionService.submit(region)); |
| | | public R submit(@Valid @RequestBody RegionAddParam region) { |
| | | Region regionEntity = Objects.requireNonNull(BeanUtil.copy(region, Region.class)); |
| | | regionEntity.setUpdateTime(DateUtil.now()); |
| | | regionEntity.setCreateTime(DateUtil.now()); |
| | | return R.status(regionService.submit(regionEntity)); |
| | | } |
| | | |
| | | |
| | |
| | | @ApiOperation(value = "导入行政区划", notes = "传入excel") |
| | | public R importRegion(MultipartFile file, Integer isCovered) { |
| | | RegionImporter regionImporter = new RegionImporter(regionService, isCovered == 1); |
| | | ExcelUtil.save(file, regionImporter, RegionExcel.class); |
| | | ExcelUtil.save(file, regionImporter, RegionImportExcel.class); |
| | | return R.success("操作成功"); |
| | | } |
| | | |
| | |
| | | /** |
| | | * 导出模板 |
| | | */ |
| | | // @GetMapping("export-template") |
| | | // @ApiOperationSupport(order = 12) |
| | | // @ApiOperation(value = "导出模板") |
| | | // public void exportUser(HttpServletResponse response) { |
| | | // List<RegionImportExcel> list = new ArrayList<>(); |
| | | // ExcelUtil.export(response, "行政区划模板", "行政区划表", list, RegionImportExcel.class); |
| | | // } |
| | | |
| | | @GetMapping("export-template") |
| | | @ApiOperationSupport(order = 12) |
| | | @ApiOperationSupport(order = 16) |
| | | @ApiOperation(value = "导出模板") |
| | | public void exportUser(HttpServletResponse response) { |
| | | List<RegionExcel> list = new ArrayList<>(); |
| | | ExcelUtil.export(response, "行政区划模板", "行政区划表", list, RegionExcel.class); |
| | | public void exportUser(HttpServletResponse response) throws IOException { |
| | | // 设置响应头 |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding(StandardCharsets.UTF_8.name()); |
| | | String fileName = URLEncoder.encode("行政区划模板", StandardCharsets.UTF_8.name()); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); |
| | | |
| | | // 准备空数据列表 |
| | | List<RegionImportExcel> list = new ArrayList<>(); |
| | | |
| | | // 使用EasyExcel导出,并注册RegionSheetWriteHandler |
| | | EasyExcel.write(response.getOutputStream(), RegionImportExcel.class) |
| | | .registerWriteHandler(new RegionSheetWriteHandler()) |
| | | .sheet("行政区划表") |
| | | .doWrite(list); |
| | | } |
| | | |
| | | /** |