| | |
| | | */ |
| | | package org.springblade.modules.discuss.service.impl; |
| | | |
| | | import com.alibaba.excel.EasyExcelFactory; |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.ExcelWriter; |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder; |
| | | import com.alibaba.excel.write.metadata.style.WriteCellStyle; |
| | | import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; |
| | | import com.alibaba.fastjson.JSON; |
| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.poi.ss.usermodel.HorizontalAlignment; |
| | | import org.jetbrains.annotations.Nullable; |
| | | import org.springblade.common.constant.CommonConstant; |
| | | import org.springblade.common.utils.SpringUtils; |
| | | import org.springblade.core.redis.cache.BladeRedis; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.SpringUtil; |
| | | import org.springblade.modules.discuss.entity.PublicDiscussEntity; |
| | | import org.springblade.modules.discuss.entity.TopicsEntity; |
| | | import org.springblade.modules.discuss.entity.UserTopicsEntity; |
| | | import org.springblade.modules.discuss.excel.UserTopicsExcel; |
| | | import org.springblade.modules.discuss.excel.householdExcel; |
| | | import org.springblade.modules.discuss.excel.holdExcel; |
| | | import org.springblade.modules.discuss.mapper.UserTopicsMapper; |
| | | import org.springblade.modules.discuss.service.IPublicDiscussService; |
| | | import org.springblade.modules.discuss.service.ITopicsService; |
| | |
| | | import org.springblade.modules.discuss.vo.UserTopicsVO; |
| | | import org.springblade.modules.district.entity.DistrictEntity; |
| | | import org.springblade.modules.district.service.IDistrictService; |
| | | import org.springblade.modules.house.entity.HouseEntity; |
| | | import org.springblade.modules.house.entity.HouseholdEntity; |
| | | import org.springblade.modules.house.excel.HouseHoldExcel; |
| | | import org.springblade.modules.house.service.IHouseService; |
| | | import org.springblade.modules.house.service.IHouseholdService; |
| | | import org.springblade.modules.house.vo.HouseholdVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public String batchSave(TopicsVO topics) throws Exception { |
| | | if (StringUtils.isNotBlank(topics.getPhone())) { |
| | | Object validateCode = redisTemplate.get(SMS_VALIDATE_PHONE + topics.getPhone()); |
| | | if (validateCode == null) { |
| | | return "验证码已过期"; |
| | | } |
| | | if (!validateCode.toString().equals(topics.getCode())) { |
| | | return "验证码错误"; |
| | | } |
| | | //删除验证码 |
| | | redisTemplate.del(SMS_VALIDATE_PHONE + topics.getPhone()); |
| | | } |
| | | // if (StringUtils.isNotBlank(topics.getPhone())) { |
| | | // Object validateCode = redisTemplate.get(SMS_VALIDATE_PHONE + topics.getPhone()); |
| | | // if (validateCode == null) { |
| | | // return "验证码已过期"; |
| | | // } |
| | | // if (!validateCode.toString().equals(topics.getCode())) { |
| | | // return "验证码错误"; |
| | | // } |
| | | // //删除验证码 |
| | | // redisTemplate.del(SMS_VALIDATE_PHONE + topics.getPhone()); |
| | | // } |
| | | // 判断是否一户一票 还是一人一票 |
| | | List<TopicsVO> topicsList = topics.getChildren(); |
| | | IHouseholdService householdService = SpringUtils.getBean(IHouseholdService.class); |
| | |
| | | |
| | | @Override |
| | | public void handleExcel(OutputStream out, UserTopicsVO userTopics) { |
| | | ExcelWriter excelWriter = EasyExcelFactory.write(out).build(); |
| | | //设置内容样式 |
| | | WriteCellStyle contentStyle = new WriteCellStyle(); |
| | | contentStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);//居中 |
| | | contentStyle.setWrapped(true);//自动换行 |
| | | //设置头部样式 |
| | | WriteCellStyle headerStyle = new WriteCellStyle(); |
| | | headerStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); |
| | | //设置策略 |
| | | HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headerStyle, contentStyle); |
| | | WriteSheet proposalSheet = EasyExcelFactory.writerSheet(0, "委员提案").head(HouseHoldExcel.class).registerWriteHandler(horizontalCellStyleStrategy).build(); |
| | | WriteSheet publicopinionSheet = EasyExcelFactory.writerSheet(1, "社情民意").head(HouseHoldExcel.class).registerWriteHandler(horizontalCellStyleStrategy).build(); |
| | | excelWriter.write(getProposal(userTopics), proposalSheet); |
| | | excelWriter.write(getPublicopinion(userTopics), publicopinionSheet); |
| | | |
| | | // 设置excel工作簿 |
| | | ExcelWriter excelWriter = EasyExcel.write(out) |
| | | .build(); |
| | | |
| | | // List<householdExcel> userList = new ArrayList<>(); |
| | | // for (int i = 0; i < 10; i++) { |
| | | // HouseHoldExcel houseHoldExcel = new HouseHoldExcel(); |
| | | // houseHoldExcel.setHouseCode(i+"1"); |
| | | // } |
| | | //设置自动换行 |
| | | |
| | | WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); |
| | | contentWriteCellStyle.setWrapped(true); |
| | | |
| | | List<holdExcel> proposal = getProposal(userTopics); |
| | | ExcelWriterSheetBuilder userExcelSheet = new ExcelWriterSheetBuilder(); |
| | | userExcelSheet.registerWriteHandler(new HorizontalCellStyleStrategy(null,contentWriteCellStyle)); |
| | | userExcelSheet.sheetName("小区投票人员"); |
| | | userExcelSheet.sheetNo(0); |
| | | userExcelSheet.head(holdExcel.class); |
| | | excelWriter.write(proposal, userExcelSheet.build()); |
| | | |
| | | |
| | | // List<householdExcel> classInfoList = new ArrayList<>(); |
| | | // for (int i = 0; i < 10; i++) { |
| | | // HouseHoldExcel houseHoldExcel = new HouseHoldExcel(); |
| | | // houseHoldExcel.setHouseCode(i+"1"); |
| | | // } |
| | | List<UserTopicsExcel> publicopinion = getPublicopinion(userTopics); |
| | | ExcelWriterSheetBuilder classExcelSheet = new ExcelWriterSheetBuilder(); |
| | | classExcelSheet.registerWriteHandler(new HorizontalCellStyleStrategy(null,contentWriteCellStyle)); |
| | | classExcelSheet.sheetName("投票记录"); |
| | | classExcelSheet.sheetNo(1); |
| | | classExcelSheet.head(UserTopicsExcel.class); |
| | | excelWriter.write(publicopinion, classExcelSheet.build()); |
| | | |
| | | excelWriter.finish(); |
| | | |
| | | |
| | | // ExcelWriter excelWriter = EasyExcelFactory.write(out).build(); |
| | | // //设置内容样式 |
| | | // WriteCellStyle contentStyle = new WriteCellStyle(); |
| | | // contentStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);//居中 |
| | | // contentStyle.setWrapped(true);//自动换行 |
| | | // //设置头部样式 |
| | | // WriteCellStyle headerStyle = new WriteCellStyle(); |
| | | // headerStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); |
| | | // //设置策略 |
| | | // HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headerStyle, contentStyle); |
| | | // WriteSheet proposalSheet = EasyExcelFactory.writerSheet(0, "委员提案").head(HouseHoldExcel.class).registerWriteHandler(horizontalCellStyleStrategy).build(); |
| | | // WriteSheet publicopinionSheet = EasyExcelFactory.writerSheet(1, "社情民意").head(HouseHoldExcel.class).registerWriteHandler(horizontalCellStyleStrategy).build(); |
| | | // excelWriter.write(getProposal(userTopics), proposalSheet); |
| | | // excelWriter.write(getPublicopinion(userTopics), publicopinionSheet); |
| | | |
| | | |
| | | } |
| | | |
| | | //首页-房屋记录 |
| | | private List<householdExcel> getProposal(UserTopicsVO userTopics) { |
| | | List<householdExcel> list = new ArrayList<>(); |
| | | private List<holdExcel> getProposal(UserTopicsVO userTopics) { |
| | | List<holdExcel> list = new ArrayList<>(); |
| | | JSONArray objects1 = JSON.parseArray(userTopics.getDistrictId()); |
| | | List<String> collect1 = objects1.stream().map(item -> (String)item).collect(Collectors.toList()); |
| | | List<String> collect1 = objects1.stream().map(item -> (String) item).collect(Collectors.toList()); |
| | | IDistrictService bean3 = SpringUtils.getBean(IDistrictService.class); |
| | | List<DistrictEntity> list3 = bean3.list(Wrappers.<DistrictEntity>lambdaQuery().in(DistrictEntity::getId, collect1)); |
| | | List<String> aoiCodeList = list3.stream().map(item -> item.getAoiCode() ).collect(Collectors.toList()); |
| | | List<String> aoiCodeList = list3.stream().map(item -> item.getAoiCode()).collect(Collectors.toList()); |
| | | userTopics.setAoiCodeList(aoiCodeList); |
| | | List<householdExcel> householdList = baseMapper.getHouseholdList(userTopics); |
| | | // |
| | | // householdExcel vo = new householdExcel(); |
| | | // list.add(vo); |
| | | // IHouseService bean = SpringUtils.getBean(IHouseService.class); |
| | | // JSONArray objects = JSON.parseArray(userTopics.getDistrictId()); |
| | | // |
| | | // List<HouseEntity> list1 = bean.list(Wrappers.<HouseEntity>lambdaQuery().in(HouseEntity::getDistrictCode, aoiCodeList)); |
| | | // |
| | | // IHouseholdService bean1 = SpringUtils.getBean(IHouseholdService.class); |
| | | // |
| | | // IUserTopicsService bean2 = SpringUtils.getBean(IUserTopicsService.class); |
| | | // |
| | | // for (HouseEntity houseEntity : list1) { |
| | | // householdExcel householdExcel = new householdExcel(); |
| | | // householdExcel.setArea(houseEntity.getArea()); |
| | | // householdExcel.setBuilding(houseEntity.getBuilding()); |
| | | // householdExcel.setRoom(houseEntity.getRoom()); |
| | | // householdExcel.setRemark(houseEntity.getRemark()); |
| | | // // 查询住户 |
| | | // List<HouseholdEntity> list2 = bean1.list(Wrappers.<HouseholdEntity>lambdaQuery() |
| | | // .eq(HouseholdEntity::getHouseCode, houseEntity.getHouseCode()) |
| | | // .eq(HouseholdEntity::getIsDeleted, 0) |
| | | // .ne(HouseholdEntity::getRelationship, 18)); |
| | | // // 判断住户是否有投票 |
| | | // for (HouseholdEntity householdEntity : list2) { |
| | | // householdExcel.setName(householdEntity.getName()); |
| | | // householdExcel.setPhone(householdEntity.getPhoneNumber()); |
| | | // long count = bean2.count(Wrappers.<UserTopicsEntity>lambdaQuery() |
| | | // .eq(UserTopicsEntity::getHouseholdId, householdEntity.getId())); |
| | | // if (count > 0) { |
| | | // // 查询选择的结果 |
| | | // userTopics.setDiscussContent("管理规约"); |
| | | // userTopics.setHouseholdId(householdEntity.getId()); |
| | | // UserTopicsVO getresult = baseMapper.getresult(userTopics); |
| | | // if (getresult != null) { |
| | | // householdExcel.setManagementRegulations(getresult.getOptionContent()); |
| | | // } |
| | | // userTopics.setDiscussContent("议事规则"); |
| | | // UserTopicsVO getresult2 = baseMapper.getresult(userTopics); |
| | | // if (getresult2 != null) { |
| | | // householdExcel.setRulesOfProcedure(getresult2.getOptionContent()); |
| | | // } |
| | | // householdExcel.setVoteFlag("是"); |
| | | // break; |
| | | // } else { |
| | | // householdExcel.setVoteFlag("否"); |
| | | // } |
| | | // } |
| | | // 添加 |
| | | list.addAll(householdList); |
| | | // } |
| | | List<holdExcel> householdList = baseMapper.getHouseholdList(userTopics); |
| | | householdList.stream().forEach(item -> { |
| | | if (StringUtils.isBlank(item.getOptionContent())) { |
| | | item.setVoteFlag("否"); |
| | | } else { |
| | | ITopicsService bean = SpringUtils.getBean(ITopicsService.class); |
| | | |
| | | List<Long> longs = Func.toLongList(item.getOptionContent()); |
| | | for (Long aLong : longs) { |
| | | TopicsEntity topics = bean.getById(aLong); |
| | | if (StringUtils.isNotBlank(topics.getDiscussContent()) && topics.getDiscussContent().equals("管理规约")) { |
| | | item.setManagementRegulations(topics.getOptionContent()); |
| | | } |
| | | if (StringUtils.isNotBlank(topics.getDiscussContent()) && topics.getDiscussContent().equals("议事规则")) { |
| | | item.setRulesOfProcedure(topics.getOptionContent()); |
| | | } |
| | | } |
| | | |
| | | item.setVoteFlag("是"); |
| | | } |
| | | }); |
| | | // 添加 |
| | | list.addAll(householdList); |
| | | return list; |
| | | } |
| | | |
| | |
| | | private List<UserTopicsExcel> getPublicopinion(UserTopicsVO userTopics) { |
| | | List<UserTopicsExcel> list = new ArrayList<>(); |
| | | List<UserTopicsExcel> userTopicsExcels = baseMapper.getresultTwo(userTopics); |
| | | UserTopicsExcel vo = new UserTopicsExcel(); |
| | | list.add(vo); |
| | | list.addAll(userTopicsExcels); |
| | | return list; |
| | | } |