springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/dtos/community/ComMngPopulationTagDTO.java
New file @@ -0,0 +1,29 @@ package com.panzhihua.common.model.dtos.community; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.io.Serializable; import java.util.Date; /** * 实有人口DTO */ @Data public class ComMngPopulationTagDTO implements Serializable { private static final long serialVersionUID = 1L; /** * 主键id */ @ApiModelProperty(value="主键id") private Long id; /** * 标签字符串(多个以,隔开) */ @ApiModelProperty(value="标签字符串") private String label; } springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/service/community/CommunityService.java
@@ -1338,15 +1338,6 @@ R listSaveMngCarExcelVO(@RequestBody List<ComMngCarExcelVO> list, @RequestParam("communityId") Long communityId); /** * 分页查询实有人口 * @param comMngPopulationVO 查询参数 * @return 分页集合 */ @PostMapping("/common/data/population/page") R pagePopulation(ComMngPopulationDTO comMngPopulationVO); /** * 社区后台实有单位管理列表 * * @param pageComMngRealCompanyDTO @@ -1568,4 +1559,28 @@ */ @PostMapping("/village/import") R listSaveVillageServeExcelVO(@RequestBody List<ComMngVillageServeExcelVO> list, @RequestParam(value = "communityId") Long communityId); /** * 分页查询实有人口 * @param comMngPopulationVO 查询参数 * @return 分页集合 */ @PostMapping("/common/data/population/page") R pagePopulation(ComMngPopulationDTO comMngPopulationVO); /** * 根据id实有人口详细信息 * @param populationId 实有人口id * @return 实有人口详细信息 */ @PostMapping("/common/data/population/detail") R detailPopulation(@RequestParam(value = "populationId") Long populationId); /** * 根据id修改实有人口标签列表 * @param populationTagDTO 请求参数 * @return 修改结果 */ @PostMapping("/common/data/population/editTag") R editTagPopulation(ComMngPopulationTagDTO populationTagDTO); } springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/service/user/UserService.java
@@ -629,4 +629,11 @@ */ @PostMapping("/common/data/special/export") R specialUserExport(@RequestBody ExportSpecialUserDTO exportSpecialUserDTO); /** * 查询所有人员标签 * @return 标签集合 */ @PostMapping("listtag/getTag") R listTags(@RequestParam("communityId") Long communityId); } springcloud_k8s_panzhihuazhihuishequ/community_backstage/pom.xml
@@ -48,6 +48,27 @@ <groupId>com.github.xiaoymin</groupId> <artifactId>swagger-bootstrap-ui</artifactId> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-scratchpad</artifactId> <version>3.11-beta2</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.11-beta2</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml-schemas</artifactId> <version>3.11-beta2</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-excelant</artifactId> <version>3.11-beta2</version> </dependency> </dependencies> springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/CommonDataApi.java
@@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.jcraft.jsch.SftpException; import com.panzhihua.common.constants.Constants; import com.panzhihua.common.controller.BaseController; import com.panzhihua.common.listen.ComMngCarExcelListen; import com.panzhihua.common.listen.ComMngRealAssetsExcelListen; @@ -18,6 +19,7 @@ import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.community.*; import com.panzhihua.common.model.vos.user.ComMngTagVO; import com.panzhihua.common.model.vos.user.ComMngUserTagVO; import com.panzhihua.common.model.vos.user.InputUserInfoVO; import com.panzhihua.common.service.community.CommunityService; import com.panzhihua.common.service.user.UserService; @@ -25,6 +27,9 @@ import com.panzhihua.common.validated.AddGroup; import com.panzhihua.community_backstage.easyexcel.UploadEexcelUserDTOListener; import com.panzhihua.community_backstage.excel.CustomSheetWriteHandler; import com.panzhihua.community_backstage.model.dto.ExcelExportDto; import com.panzhihua.community_backstage.utils.ExportExcelUtil; import com.panzhihua.community_backstage.utils.ExportExcelWrapper; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; @@ -677,5 +682,47 @@ return communityService.pagePopulation(comMngPopulationVO); } @ApiOperation(value = "实有人口详情", response = ComMngPopulationVO.class) @PostMapping("/population/detail") public R detailPopulation(@RequestParam(value = "populationId") Long populationId) { return communityService.detailPopulation(populationId); } @ApiOperation(value = "实有人口标签修改", response = ComMngPopulationVO.class) @PostMapping("/population/editTag") public R editTagPopulation(@RequestBody ComMngPopulationTagDTO populationTagDTO) { return communityService.editTagPopulation(populationTagDTO); } @ApiOperation(value = "实有人口导出模板", response = ComMngPopulationVO.class) @PostMapping("/population/export") public void exportPopulation(HttpServletRequest request, HttpServletResponse response) { //获取登陆用户 LoginUserInfoVO loginUserInfo = this.getLoginUserInfo(); //获取登陆用户绑定社区id Long communityId = loginUserInfo.getCommunityId(); //创建Excel工具类对象 ExportExcelWrapper<ExcelExportDto> util = new ExportExcelWrapper<>(); //创建示范数据对象list List<ExcelExportDto> list = new ArrayList<>(); //创建表头数组集合 String[] columnNames = new String[50]; //加载默认表头数据 for (int i = 0; i < ExportExcelUtil.ExportField.length; i++) { columnNames[i] = ExportExcelUtil.ExportField[i]; } //查询当前社区标签列表 R tagsResult = userService.listTags(communityId); if(Constants.SUCCESS.equals(tagsResult.getCode())){ List<String> TagsList = (List<String>)tagsResult.getData(); //动态加载标签列表到表头 for (int i = 0; i < TagsList.size(); i++) { columnNames[ExportExcelUtil.ExportField.length + i] = TagsList.get(i) + "(是或否)"; } } //导出模板 util.exportExcel("实有人口导入模板", "实有人口导入模板", columnNames, list, response, ExportExcelUtil.EXCEl_FILE_2007); } } springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/model/dto/ExcelExportDto.java
New file @@ -0,0 +1,60 @@ package com.panzhihua.community_backstage.model.dto; import lombok.Data; @Data public class ExcelExportDto { /** * 家庭成员 */ private String name = "张三"; /** * 性别 */ private String sex = "男"; /** * 年龄 */ private String age = "25"; /** * 是否租住 */ private String isRent = "是"; /** * 街路巷 */ private String road = "樱花街"; /** * 门牌号 */ private String doorNo = "115"; /** * 楼排号 */ private String floor = "15栋"; /** * 单元号 */ private String unitNo = "10"; /** * 户室 */ private String houseNo = "1001"; /** * 民族 */ private String nation = "汉族"; /** * 政治面貌 */ private String politicalOutlook = "群众"; /** * 身份证 */ private String cardNo = "513421199508187219"; /** * 联系方式 */ private String phone = "13768548521"; } springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/utils/ExportExcelUtil.java
New file @@ -0,0 +1,430 @@ package com.panzhihua.community_backstage.utils; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.text.SimpleDateFormat; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import com.panzhihua.common.model.dtos.community.ComMngPopulationTagDTO; import com.panzhihua.community_backstage.model.dto.ExcelExportDto; import org.apache.commons.lang3.StringUtils; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFFont; import org.apache.poi.hssf.usermodel.HSSFRichTextString; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFCellStyle; import org.apache.poi.xssf.usermodel.XSSFColor; import org.apache.poi.xssf.usermodel.XSSFFont; import org.apache.poi.xssf.usermodel.XSSFRichTextString; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; /** * 导出Excel * @author liuyazhuang * * @param <T> */ public class ExportExcelUtil<T>{ // 2007 版本以上 最大支持1048576行 public final static String EXCEl_FILE_2007 = "2007"; // 2003 版本 最大支持65536 行 public final static String EXCEL_FILE_2003 = "2003"; public final static String[] ExportField = {"家庭成员","性别","年龄","是否租住","街路巷","门牌号","楼排号","单元号","户室","民族","政治面貌","身份证","联系方式"}; /** * <p> * 导出无头部标题行Excel <br> * 时间格式默认:yyyy-MM-dd hh:mm:ss <br> * </p> * * @param title 表格标题 * @param dataset 数据集合 * @param out 输出流 * @param version 2003 或者 2007,不传时默认生成2003版本 */ public void exportExcel(String title, Collection<T> dataset, OutputStream out, String version) { if(StringUtils.isEmpty(version) || EXCEL_FILE_2003.equals(version.trim())){ exportExcel2003(title, null, dataset, out, "yyyy-MM-dd HH:mm:ss"); }else{ exportExcel2007(title, null, dataset, out, "yyyy-MM-dd HH:mm:ss"); } } /** * <p> * 导出带有头部标题行的Excel <br> * 时间格式默认:yyyy-MM-dd hh:mm:ss <br> * </p> * * @param title 表格标题 * @param headers 头部标题集合 * @param dataset 数据集合 * @param out 输出流 * @param version 2003 或者 2007,不传时默认生成2003版本 */ public void exportExcel(String title,String[] headers, Collection<T> dataset, OutputStream out,String version) { if(StringUtils.isBlank(version) || EXCEL_FILE_2003.equals(version.trim())){ exportExcel2003(title, headers, dataset, out, "yyyy-MM-dd HH:mm:ss"); }else{ exportExcel2007(title, headers, dataset, out, "yyyy-MM-dd HH:mm:ss"); } } /** * <p> * 通用Excel导出方法,利用反射机制遍历对象的所有字段,将数据写入Excel文件中 <br> * 此版本生成2007以上版本的文件 (文件后缀:xlsx) * </p> * * @param title * 表格标题名 * @param headers * 表格头部标题集合 * @param dataset * 需要显示的数据集合,集合中一定要放置符合JavaBean风格的类的对象。此方法支持的 * JavaBean属性的数据类型有基本数据类型及String,Date * @param out * 与输出设备关联的流对象,可以将EXCEL文档导出到本地文件或者网络中 * @param pattern * 如果有时间数据,设定输出格式。默认为"yyyy-MM-dd hh:mm:ss" */ @SuppressWarnings({ "unchecked", "rawtypes" }) public void exportExcel2007(String title, String[] headers, Collection<T> dataset, OutputStream out, String pattern) { // 声明一个工作薄 XSSFWorkbook workbook = new XSSFWorkbook(); // 生成一个表格 XSSFSheet sheet = workbook.createSheet(title); // 设置表格默认列宽度为15个字节 sheet.setDefaultColumnWidth(20); // 生成一个样式 XSSFCellStyle style = workbook.createCellStyle(); // 设置这些样式 style.setFillForegroundColor(new XSSFColor(java.awt.Color.gray)); style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); style.setBorderBottom(XSSFCellStyle.BORDER_THIN); style.setBorderLeft(XSSFCellStyle.BORDER_THIN); style.setBorderRight(XSSFCellStyle.BORDER_THIN); style.setBorderTop(XSSFCellStyle.BORDER_THIN); style.setAlignment(XSSFCellStyle.ALIGN_CENTER); // 生成一个字体 XSSFFont font = workbook.createFont(); font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD); font.setFontName("宋体"); font.setColor(new XSSFColor(java.awt.Color.BLACK)); font.setFontHeightInPoints((short) 11); // 把字体应用到当前的样式 style.setFont(font); // 生成并设置另一个样式 XSSFCellStyle style2 = workbook.createCellStyle(); style2.setFillForegroundColor(new XSSFColor(java.awt.Color.WHITE)); style2.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); style2.setBorderBottom(XSSFCellStyle.BORDER_THIN); style2.setBorderLeft(XSSFCellStyle.BORDER_THIN); style2.setBorderRight(XSSFCellStyle.BORDER_THIN); style2.setBorderTop(XSSFCellStyle.BORDER_THIN); style2.setAlignment(XSSFCellStyle.ALIGN_CENTER); style2.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); // 生成另一个字体 XSSFFont font2 = workbook.createFont(); font2.setBoldweight(XSSFFont.BOLDWEIGHT_NORMAL); // 把字体应用到当前的样式 style2.setFont(font2); // 产生表格标题行 XSSFRow row = sheet.createRow(0); XSSFCell cellHeader; for (int i = 0; i < headers.length; i++) { cellHeader = row.createCell(i); cellHeader.setCellStyle(style); cellHeader.setCellValue(new XSSFRichTextString(headers[i])); } // 遍历集合数据,产生数据行 Iterator<T> it = dataset.iterator(); int index = 0; T t; Field[] fields; Field field; XSSFRichTextString richString; Pattern p = Pattern.compile("^//d+(//.//d+)?$"); Matcher matcher; String fieldName; String getMethodName; XSSFCell cell; Class tCls; Method getMethod; Object value; String textValue; SimpleDateFormat sdf = new SimpleDateFormat(pattern); while (it.hasNext()) { index++; row = sheet.createRow(index); t = (T) it.next(); // 利用反射,根据JavaBean属性的先后顺序,动态调用getXxx()方法得到属性值 fields = t.getClass().getDeclaredFields(); for (int i = 0; i < fields.length; i++) { cell = row.createCell(i); cell.setCellStyle(style2); field = fields[i]; fieldName = field.getName(); getMethodName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); try { tCls = t.getClass(); getMethod = tCls.getMethod(getMethodName, new Class[] {}); value = getMethod.invoke(t, new Object[] {}); // 判断值的类型后进行强制类型转换 textValue = null; if (value instanceof Integer) { cell.setCellValue((Integer) value); } else if (value instanceof Float) { textValue = String.valueOf((Float) value); cell.setCellValue(textValue); } else if (value instanceof Double) { textValue = String.valueOf((Double) value); cell.setCellValue(textValue); } else if (value instanceof Long) { cell.setCellValue((Long) value); } if (value instanceof Boolean) { textValue = "是"; if (!(Boolean) value) { textValue = "否"; } } else if (value instanceof Date) { textValue = sdf.format((Date) value); } else { // 其它数据类型都当作字符串简单处理 if (value != null) { textValue = value.toString(); } } if (textValue != null) { matcher = p.matcher(textValue); if (matcher.matches()) { // 是数字当作double处理 cell.setCellValue(Double.parseDouble(textValue)); } else { richString = new XSSFRichTextString(textValue); cell.setCellValue(richString); } } } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } finally { // 清理资源 } } } try { workbook.write(out); } catch (IOException e) { e.printStackTrace(); } } /** * <p> * 通用Excel导出方法,利用反射机制遍历对象的所有字段,将数据写入Excel文件中 <br> * 此方法生成2003版本的excel,文件名后缀:xls <br> * </p> * * @param title * 表格标题名 * @param headers * 表格头部标题集合 * @param dataset * 需要显示的数据集合,集合中一定要放置符合JavaBean风格的类的对象。此方法支持的 * JavaBean属性的数据类型有基本数据类型及String,Date * @param out * 与输出设备关联的流对象,可以将EXCEL文档导出到本地文件或者网络中 * @param pattern * 如果有时间数据,设定输出格式。默认为"yyyy-MM-dd hh:mm:ss" */ @SuppressWarnings({ "unchecked", "rawtypes" }) public void exportExcel2003(String title, String[] headers, Collection<T> dataset, OutputStream out, String pattern) { // 声明一个工作薄 HSSFWorkbook workbook = new HSSFWorkbook(); // 生成一个表格 HSSFSheet sheet = workbook.createSheet(title); // 设置表格默认列宽度为15个字节 sheet.setDefaultColumnWidth(20); // 生成一个样式 HSSFCellStyle style = workbook.createCellStyle(); // 设置这些样式 style.setFillForegroundColor(HSSFColor.GREY_50_PERCENT.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 生成一个字体 HSSFFont font = workbook.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); font.setFontName("宋体"); font.setColor(HSSFColor.WHITE.index); font.setFontHeightInPoints((short) 11); // 把字体应用到当前的样式 style.setFont(font); // 生成并设置另一个样式 HSSFCellStyle style2 = workbook.createCellStyle(); style2.setFillForegroundColor(HSSFColor.WHITE.index); style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style2.setBorderBottom(HSSFCellStyle.BORDER_THIN); style2.setBorderLeft(HSSFCellStyle.BORDER_THIN); style2.setBorderRight(HSSFCellStyle.BORDER_THIN); style2.setBorderTop(HSSFCellStyle.BORDER_THIN); style2.setAlignment(HSSFCellStyle.ALIGN_CENTER); style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 生成另一个字体 HSSFFont font2 = workbook.createFont(); font2.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); // 把字体应用到当前的样式 style2.setFont(font2); // 产生表格标题行 HSSFRow row = sheet.createRow(0); HSSFCell cellHeader; for (int i = 0; i < headers.length; i++) { cellHeader = row.createCell(i); cellHeader.setCellStyle(style); cellHeader.setCellValue(new HSSFRichTextString(headers[i])); } // 遍历集合数据,产生数据行 Iterator<T> it = dataset.iterator(); int index = 0; T t; Field[] fields; Field field; HSSFRichTextString richString; Pattern p = Pattern.compile("^//d+(//.//d+)?$"); Matcher matcher; String fieldName; String getMethodName; HSSFCell cell; Class tCls; Method getMethod; Object value; String textValue; SimpleDateFormat sdf = new SimpleDateFormat(pattern); while (it.hasNext()) { index++; row = sheet.createRow(index); t = (T) it.next(); // 利用反射,根据JavaBean属性的先后顺序,动态调用getXxx()方法得到属性值 fields = t.getClass().getDeclaredFields(); for (int i = 0; i < fields.length; i++) { cell = row.createCell(i); cell.setCellStyle(style2); field = fields[i]; fieldName = field.getName(); getMethodName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); try { tCls = t.getClass(); getMethod = tCls.getMethod(getMethodName, new Class[] {}); value = getMethod.invoke(t, new Object[] {}); // 判断值的类型后进行强制类型转换 textValue = null; if (value instanceof Integer) { cell.setCellValue((Integer) value); } else if (value instanceof Float) { textValue = String.valueOf((Float) value); cell.setCellValue(textValue); } else if (value instanceof Double) { textValue = String.valueOf((Double) value); cell.setCellValue(textValue); } else if (value instanceof Long) { cell.setCellValue((Long) value); } if (value instanceof Boolean) { textValue = "是"; if (!(Boolean) value) { textValue = "否"; } } else if (value instanceof Date) { textValue = sdf.format((Date) value); } else { // 其它数据类型都当作字符串简单处理 if (value != null) { textValue = value.toString(); } } if (textValue != null) { matcher = p.matcher(textValue); if (matcher.matches()) { // 是数字当作double处理 cell.setCellValue(Double.parseDouble(textValue)); } else { richString = new HSSFRichTextString(textValue); cell.setCellValue(richString); } } } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } finally { // 清理资源 } } } try { workbook.write(out); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) throws Exception{ ExportExcelUtil<ExcelExportDto> util = new ExportExcelUtil<ExcelExportDto>(); List<ExcelExportDto> mapList = new ArrayList<>(); String[] columnNames = new String[50]; for (int i = 0; i < ExportField.length; i++) { columnNames[i] = ExportField[i]; } for (int i = 0; i <= 6; i++) { columnNames[ExportField.length + i] = "1"; } util.exportExcel("实有人口导入模板", columnNames, mapList, new FileOutputStream("E:/实有人口导入模板.xls"), ExportExcelUtil.EXCEl_FILE_2007); } } springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/utils/ExportExcelWrapper.java
New file @@ -0,0 +1,42 @@ package com.panzhihua.community_backstage.utils; import java.net.URLEncoder; import java.util.Collection; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringUtils; /** * 包装类 * @author liuyazhuang * * @param <T> */ public class ExportExcelWrapper<T> extends ExportExcelUtil<T> { /** * <p> * 导出带有头部标题行的Excel <br> * 时间格式默认:yyyy-MM-dd hh:mm:ss <br> * </p> * * @param title 表格标题 * @param headers 头部标题集合 * @param dataset 数据集合 * @param version 2003 或者 2007,不传时默认生成2003版本 */ public void exportExcel(String fileName, String title, String[] headers, Collection<T> dataset, HttpServletResponse response,String version) { try { response.setContentType("application/vnd.ms-excel"); response.addHeader("Content-Disposition", "attachment;filename="+ URLEncoder.encode(fileName, "UTF-8") + ".xls"); if(StringUtils.isBlank(version) || EXCEL_FILE_2003.equals(version.trim())){ exportExcel2003(title, headers, dataset, response.getOutputStream(), "yyyy-MM-dd HH:mm:ss"); }else{ exportExcel2007(title, headers, dataset, response.getOutputStream(), "yyyy-MM-dd HH:mm:ss"); } } catch (Exception e) { e.printStackTrace(); } } } springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/api/CommonDataApi.java
@@ -3,6 +3,7 @@ import com.panzhihua.common.model.dtos.community.*; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.community.*; import com.panzhihua.common.service.user.UserService; import com.panzhihua.service_community.service.*; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; @@ -33,6 +34,7 @@ private ComMngProvinceService comMngProvinceService; @Resource private ComMngPopulationService comMngPopulationService; /** * 小程序用户车辆登记 @@ -255,4 +257,24 @@ public R pagePopulation(@RequestBody ComMngPopulationDTO comMngPopulationVO) { return comMngPopulationService.pagePopulation(comMngPopulationVO); } /** * 根据实有人口id查询详情 * @param populationId 实有人口id * @return 实有人口详情查询结果 */ @PostMapping("/population/detail") public R detailPopulation(@RequestParam(value = "populationId") Long populationId) { return comMngPopulationService.detailPopulation(populationId); } /** * 根据实有人口id修改标签列表 * @param populationTagDTO 请求参数 * @return 修改结果 */ @PostMapping("/population/editTag") public R editTagPopulation(@RequestBody ComMngPopulationTagDTO populationTagDTO) { return comMngPopulationService.editTagPopulation(populationTagDTO); } } springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/ComMngPopulationService.java
@@ -1,6 +1,7 @@ package com.panzhihua.service_community.service; import com.panzhihua.common.model.dtos.community.ComMngPopulationDTO; import com.panzhihua.common.model.dtos.community.ComMngPopulationTagDTO; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.community.ComMngPopulationVO; import org.springframework.cloud.openfeign.FeignClient; @@ -51,4 +52,10 @@ * @return 删除结果 */ R deletePopulation(Long populationId); /** * 根据实有人口id修改用户标签 * @param populationTagDTO 请求参数 * @return 修改结果 */ R editTagPopulation(ComMngPopulationTagDTO populationTagDTO); } springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngPopulationServiceImpl.java
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.panzhihua.common.model.dtos.community.ComMngPopulationDTO; import com.panzhihua.common.model.dtos.community.ComMngPopulationTagDTO; import com.panzhihua.common.model.dtos.community.PageComActDTO; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.community.ComActActivityVO; @@ -169,4 +170,24 @@ } return R.ok(populationVOS); } /** * 根据id修改实有人口标签 * @param populationTagDTO 请求参数 * @return 修改结果 */ @Override public R editTagPopulation(ComMngPopulationTagDTO populationTagDTO) { ComMngPopulationDO comMngPopulationDO = populationDAO.selectById(populationTagDTO.getId()); if (comMngPopulationDO == null) { return R.fail("未查询到人口记录"); } BeanUtils.copyProperties(populationTagDTO,comMngPopulationDO); int nub = populationDAO.updateById(comMngPopulationDO); if(nub < 1){ return R.fail(); } return R.ok(); } } springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/api/UserApi.java
@@ -151,6 +151,15 @@ } /** * 查询当前社区所有标签以及预设标签 * @return 标签集合 */ @PostMapping("listtag/getTag") public R listTags(@RequestParam("communityId") Long communityId){ return userService.listTags(communityId); } /** * 人员详情 * @param userId 用户id * @return 人员详情 springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/UserService.java
@@ -351,4 +351,10 @@ * @return */ R getSysUserVOByPhone(String phone); /** * 查询当前社区所有标签以及预设标签 * @return 标签集合 */ R listTags(Long communityId); } springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java
@@ -1533,4 +1533,19 @@ // boolean matches = encoder.matches("admin1234567", encode); // System.out.println(matches); } /** * 查询当前社区所有标签以及预设标签 * * @return 标签集合 */ @Override public R listTags(Long communityId) { List<String> list=new ArrayList<>(); List<ComMngUserTagDO> comMngUserTagDOS = comMngUserTagDAO.selectList(new QueryWrapper<ComMngUserTagDO>().eq("sysFlag",1).or().eq("communityId",communityId)); if (!ObjectUtils.isEmpty(comMngUserTagDOS)) { list=comMngUserTagDOS.stream().map(comMngUserTagDO -> comMngUserTagDO.getTagName()).collect(Collectors.toList()); } return R.ok(list); } }