package org.jeecg.modules.demo.hzz.shjsgc.shxmxx.controller; import java.io.UnsupportedEncodingException; import java.io.IOException; import java.net.URLDecoder; import java.util.*; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.def.NormalExcelConstants; import org.jeecgframework.poi.excel.entity.ExportParams; import org.jeecgframework.poi.excel.entity.ImportParams; import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; import org.jeecg.common.system.vo.LoginUser; import org.apache.shiro.SecurityUtils; import org.jeecg.common.api.vo.Result; import org.jeecg.common.system.query.QueryGenerator; import org.jeecg.common.util.oConvertUtils; import org.jeecg.modules.demo.hzz.shjsgc.shxmxx.entity.RmJgjlb; import org.jeecg.modules.demo.hzz.shjsgc.shxmxx.entity.RmShxmxxb; import org.jeecg.modules.demo.hzz.shjsgc.shxmxx.vo.RmShxmxxbPage; import org.jeecg.modules.demo.hzz.shjsgc.shxmxx.service.IRmShxmxxbService; import org.jeecg.modules.demo.hzz.shjsgc.shxmxx.service.IRmJgjlbService; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import lombok.extern.slf4j.Slf4j; import com.alibaba.fastjson.JSON; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.jeecg.common.aspect.annotation.AutoLog; /** * @Description: 涉河项目信息表 * @Author: jeecg-boot * @Date: 2022-02-19 * @Version: V1.0 */ @Api(tags="涉河项目信息表") @RestController @RequestMapping("/hzz.shjsgc.shxmxx/rmShxmxxb") @Slf4j public class RmShxmxxbController { @Autowired private IRmShxmxxbService rmShxmxxbService; @Autowired private IRmJgjlbService rmJgjlbService; /** * 分页列表查询 * * @param rmShxmxxb * @param pageNo * @param pageSize * @param req * @return */ @AutoLog(value = "涉河项目信息表-分页列表查询") @ApiOperation(value="涉河项目信息表-分页列表查询", notes="涉河项目信息表-分页列表查询") @GetMapping(value = "/list") public Result queryPageList(RmShxmxxb rmShxmxxb, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) { QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(rmShxmxxb, req.getParameterMap()); Page page = new Page(pageNo, pageSize); IPage pageList = rmShxmxxbService.page(page, queryWrapper); return Result.OK(pageList); } /** * 添加 * * @param rmShxmxxbPage * @return */ @AutoLog(value = "涉河项目信息表-添加") @ApiOperation(value="涉河项目信息表-添加", notes="涉河项目信息表-添加") @PostMapping(value = "/add") public Result add(@RequestBody RmShxmxxbPage rmShxmxxbPage) { RmShxmxxb rmShxmxxb = new RmShxmxxb(); BeanUtils.copyProperties(rmShxmxxbPage, rmShxmxxb); rmShxmxxbService.saveMain(rmShxmxxb, rmShxmxxbPage.getRmJgjlbList()); return Result.OK("添加成功!"); } /** * 编辑 * * @param rmShxmxxbPage * @return */ @AutoLog(value = "涉河项目信息表-编辑") @ApiOperation(value="涉河项目信息表-编辑", notes="涉河项目信息表-编辑") @PostMapping(value = "/edit") public Result edit(@RequestBody RmShxmxxbPage rmShxmxxbPage) { RmShxmxxb rmShxmxxb = new RmShxmxxb(); BeanUtils.copyProperties(rmShxmxxbPage, rmShxmxxb); RmShxmxxb rmShxmxxbEntity = rmShxmxxbService.getById(rmShxmxxb.getId()); if(rmShxmxxbEntity==null) { return Result.error("未找到对应数据"); } rmShxmxxbService.updateMain(rmShxmxxb, rmShxmxxbPage.getRmJgjlbList()); return Result.OK("编辑成功!"); } /** * 通过id删除 * * @param id * @return */ @AutoLog(value = "涉河项目信息表-通过id删除") @ApiOperation(value="涉河项目信息表-通过id删除", notes="涉河项目信息表-通过id删除") @PostMapping(value = "/delete") public Result delete(@RequestParam(name="id",required=true) String id) { rmShxmxxbService.delMain(id); return Result.OK("删除成功!"); } /** * 批量删除 * * @param ids * @return */ @AutoLog(value = "涉河项目信息表-批量删除") @ApiOperation(value="涉河项目信息表-批量删除", notes="涉河项目信息表-批量删除") @PostMapping(value = "/deleteBatch") public Result deleteBatch(@RequestParam(name="ids",required=true) String ids) { this.rmShxmxxbService.delBatchMain(Arrays.asList(ids.split(","))); return Result.OK("批量删除成功!"); } /** * 通过id查询 * * @param id * @return */ @AutoLog(value = "涉河项目信息表-通过id查询") @ApiOperation(value="涉河项目信息表-通过id查询", notes="涉河项目信息表-通过id查询") @GetMapping(value = "/queryById") public Result queryById(@RequestParam(name="id",required=true) String id) { RmShxmxxb rmShxmxxb = rmShxmxxbService.getById(id); if(rmShxmxxb==null) { return Result.error("未找到对应数据"); } return Result.OK(rmShxmxxb); } /** * 通过id查询 * * @param id * @return */ @AutoLog(value = "监管记录通过主表ID查询") @ApiOperation(value="监管记录主表ID查询", notes="监管记录-通主表ID查询") @GetMapping(value = "/queryRmJgjlbByMainId") public Result queryRmJgjlbListByMainId(@RequestParam(name="id",required=true) String id) { List rmJgjlbList = rmJgjlbService.selectByMainId(id); return Result.OK(rmJgjlbList); } /** * 导出excel * * @param request * @param rmShxmxxb */ @RequestMapping(value = "/exportXls") public ModelAndView exportXls(HttpServletRequest request, RmShxmxxb rmShxmxxb) { // Step.1 组装查询条件查询数据 QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(rmShxmxxb, request.getParameterMap()); LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); //Step.2 获取导出数据 List queryList = rmShxmxxbService.list(queryWrapper); // 过滤选中数据 String selections = request.getParameter("selections"); List rmShxmxxbList = new ArrayList(); if(oConvertUtils.isEmpty(selections)) { rmShxmxxbList = queryList; }else { List selectionList = Arrays.asList(selections.split(",")); rmShxmxxbList = queryList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList()); } // Step.3 组装pageList List pageList = new ArrayList(); for (RmShxmxxb main : rmShxmxxbList) { RmShxmxxbPage vo = new RmShxmxxbPage(); BeanUtils.copyProperties(main, vo); List rmJgjlbList = rmJgjlbService.selectByMainId(main.getId()); vo.setRmJgjlbList(rmJgjlbList); pageList.add(vo); } // Step.4 AutoPoi 导出Excel ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); mv.addObject(NormalExcelConstants.FILE_NAME, "涉河项目信息表列表"); mv.addObject(NormalExcelConstants.CLASS, RmShxmxxbPage.class); mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("涉河项目信息表数据", "导出人:"+sysUser.getRealname(), "涉河项目信息表")); mv.addObject(NormalExcelConstants.DATA_LIST, pageList); return mv; } /** * 通过excel导入数据 * * @param request * @param response * @return */ @RequestMapping(value = "/importExcel", method = RequestMethod.POST) public Result importExcel(HttpServletRequest request, HttpServletResponse response) { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; Map fileMap = multipartRequest.getFileMap(); for (Map.Entry entity : fileMap.entrySet()) { MultipartFile file = entity.getValue();// 获取上传文件对象 ImportParams params = new ImportParams(); params.setTitleRows(2); params.setHeadRows(1); params.setNeedSave(true); try { List list = ExcelImportUtil.importExcel(file.getInputStream(), RmShxmxxbPage.class, params); for (RmShxmxxbPage page : list) { RmShxmxxb po = new RmShxmxxb(); BeanUtils.copyProperties(page, po); rmShxmxxbService.saveMain(po, page.getRmJgjlbList()); } return Result.OK("文件导入成功!数据行数:" + list.size()); } catch (Exception e) { log.error(e.getMessage(),e); return Result.error("文件导入失败:"+e.getMessage()); } finally { try { file.getInputStream().close(); } catch (IOException e) { e.printStackTrace(); } } } return Result.OK("文件导入失败!"); } /** * 总项目数 * * * @return */ @AutoLog(value = "涉河项目信息表-总项目数") @ApiOperation(value="涉河项目信息表-总项目数", notes="涉河项目信息表-总项目数") @PostMapping(value = "/count") public Result countters(){ String count = rmShxmxxbService.rmshxmcount(); return Result.OK("查询成功!",count); } /** * 在建项目 * * * @return */ @AutoLog(value = "涉河项目信息表-在建项目") @ApiOperation(value="涉河项目信息表-在建项目", notes="涉河项目信息表-在建项目") @PostMapping(value = "/zjxm") public Result zjxm(){ List> selectjsqk = rmShxmxxbService.selectjsqk(); return Result.OK("查询成功!",selectjsqk); } /** * 拟建项目 * * * @return */ @AutoLog(value = "涉河项目信息表-拟建项目") @ApiOperation(value="涉河项目信息表-拟建项目", notes="涉河项目信息表-拟建项目") @PostMapping(value = "/njxm") public Result njxm(){ List> selectnjqk = rmShxmxxbService.selectnjqk(); return Result.OK("查询成功!",selectnjqk); } /** * 总项目数 * * * @return */ @AutoLog(value = "涉河项目信息表-已建项目数") @ApiOperation(value="涉河项目信息表-已建项目数", notes="涉河项目信息表-已建项目数") @PostMapping(value = "/yjcount") public Result yjcountter(){ String count = rmShxmxxbService.yjcount(); return Result.OK("查询成功!",count); } @AutoLog(value = "涉河项目信息表-已建项目数") @ApiOperation(value="涉河项目信息表-已建项目数", notes="涉河项目信息表-已建项目数") @PostMapping(value = "/zjcount") public Result zjcountter(){ int count = rmShxmxxbService.zjcount(); String s = Integer.toString(count); return Result.OK("查询成功!",s); } @AutoLog(value = "涉河项目信息表-拟建项目数") @ApiOperation(value="涉河项目信息表-拟建项目数", notes="涉河项目信息表-拟建项目数") @PostMapping(value = "/njcount") public Result njcountter(){ int count = rmShxmxxbService.njcount(); String s = Integer.toString(count); return Result.OK("查询成功!",s); } @AutoLog(value = "涉河项目信息表-饼图总项目数") @ApiOperation(value="涉河项目信息表-饼图总项目数", notes="涉河项目信息表-饼图总 项目数") @PostMapping(value = "/xmlxcount") public Result xmlxcountter(){ List xmcount = rmShxmxxbService.xmcount(); return Result.OK("查询成功!",xmcount); } /** * 河流长度 * * * @return */ @AutoLog(value = "涉河项目信息表-河流长度") @ApiOperation(value="涉河项目信息表-河流长度", notes="涉河项目信息表-河流长度") @PostMapping(value = "/findAllhlcd") public Result findAll(){ List> allhlcd = rmShxmxxbService.findAllhlcd(); return Result.OK("查询成功!",allhlcd); } // /** // * 河流长度 // * // * // * @return // */ // @AutoLog(value = "涉河项目信息表-河流长度") // @ApiOperation(value="涉河项目信息表-河流长度", notes="涉河项目信息表-河流长度") // @PostMapping(value = "/xmlxtjshir") // public Result xmlxtj(){ // List> countxmlx = rmShxmxxbService.countxmlx(); // return Result.OK("查询成功!",countxmlx); // } /** * 监管事件 * * * @return */ @AutoLog(value = "监管事件") @ApiOperation(value="监管事件", notes="监管事件") @PostMapping(value = "/countjg") public Result coutjg(){ List> countjg = rmShxmxxbService.countjg(); return Result.OK("查询成功!",countjg); } }