| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.jetbrains.annotations.Nullable; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | 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.DateUtil; |
| | | 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.district.entity.DistrictEntity; |
| | | import org.springblade.modules.district.service.IDistrictService; |
| | | import org.springblade.modules.house.entity.HouseholdEntity; |
| | | import org.springblade.modules.house.excel.HouseHoldExcel; |
| | | import org.springblade.modules.house.service.IHouseholdService; |
| | | import org.springblade.modules.house.service.impl.HouseServiceImpl; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import javax.annotation.Resource; |
| | | import java.io.OutputStream; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | private ITopicsService topicsService; |
| | | public static final String SMS_VALIDATE_PHONE = "sms:validate:code:"; |
| | | |
| | | private static final Logger logger = LoggerFactory.getLogger(UserTopicsServiceImpl.class); |
| | | |
| | | |
| | | @Autowired |
| | | private BladeRedis redisTemplate; |
| | | |
| | | @Override |
| | | public IPage<UserTopicsVO> selectUserTopicsPage(IPage<UserTopicsVO> page, UserTopicsVO userTopics) { |
| | | if (StringUtils.isNotBlank(userTopics.getDistrictId())) { |
| | | List<String> longs = JSON.parseArray(userTopics.getDistrictId()).toJavaList(String.class); |
| | | List<String> longs = Arrays.asList(userTopics.getDistrictId().split(",")); |
| | | IDistrictService bean = SpringUtils.getBean(IDistrictService.class); |
| | | List<DistrictEntity> list = bean.list(Wrappers.<DistrictEntity>lambdaQuery().in(DistrictEntity::getId, longs)); |
| | | List<String> collect = list.stream().map(item -> |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public String batchSave(TopicsVO topics) throws Exception { |
| | | List<TopicsVO> topicsList = topics.getChildren(); |
| | | if (topicsList == null || topicsList.isEmpty()) { |
| | | return "你未选选项内容"; |
| | | } |
| | | IPublicDiscussService bean = SpringUtil.getBean(IPublicDiscussService.class); |
| | | PublicDiscussEntity discussEntity = bean.getOne(Wrappers.<PublicDiscussEntity>lambdaQuery().eq(PublicDiscussEntity::getArticleId, topicsList.get(0).getArticleId())); |
| | | // 判断是否在开始和结束时间内 |
| | | if (discussEntity.getStartTime().getTime() > System.currentTimeMillis() || discussEntity.getEndTime().getTime() < System.currentTimeMillis()) { |
| | | return "目前不在投票时间内,投票时间:" + DateUtil.formatDateTime(discussEntity.getStartTime()) + " 至 " + DateUtil.formatDateTime(discussEntity.getEndTime()); |
| | | } |
| | | if (StringUtils.isNotBlank(topics.getPhone())) { |
| | | if (StringUtils.isBlank(topics.getCode())) { |
| | | return "验证码不能为空!"; |
| | |
| | | redisTemplate.del(SMS_VALIDATE_PHONE + topics.getPhone()); |
| | | } |
| | | // 判断是否一户一票 还是一人一票 |
| | | List<TopicsVO> topicsList = topics.getChildren(); |
| | | IHouseholdService householdService = SpringUtils.getBean(IHouseholdService.class); |
| | | HouseholdEntity householdEntity = householdService.getOne(Wrappers.<HouseholdEntity>lambdaQuery() |
| | | .eq(HouseholdEntity::getHouseCode, topicsList.get(0).getHouseCode()) |
| | | .eq(HouseholdEntity::getAssociatedUserId, AuthUtil.getUserId()) |
| | | .eq(HouseholdEntity::getIsDeleted, 0) |
| | | .last("limit 1")); |
| | | IPublicDiscussService bean = SpringUtil.getBean(IPublicDiscussService.class); |
| | | PublicDiscussEntity one = bean.getOne(Wrappers.<PublicDiscussEntity>lambdaQuery().eq(PublicDiscussEntity::getArticleId, topicsList.get(0).getArticleId())); |
| | | if (ObjectUtils.isEmpty(householdEntity)) { |
| | | logger.error("未查询到住户信息!", JSON.toJSONString(topics)); |
| | | return "未查询到住户信息!"; |
| | | } |
| | | // 一户一票 |
| | | if (one.getVoteRestrictions().equals(CommonConstant.NUMBER_ONE)) { |
| | | if (discussEntity.getVoteRestrictions().equals(CommonConstant.NUMBER_ONE)) { |
| | | long count = count(Wrappers.<UserTopicsEntity>lambdaQuery() |
| | | .eq(UserTopicsEntity::getHouseCode, topicsList.get(0).getHouseCode()) |
| | | .eq(UserTopicsEntity::getArticleId, topicsList.get(0).getArticleId())); |
| | |
| | | @Override |
| | | public List<UserTopicsExcel> exportUser(UserTopicsVO userTopics) { |
| | | if (StringUtils.isNotBlank(userTopics.getDistrictId())) { |
| | | List<String> longs = JSON.parseArray(userTopics.getDistrictId()).toJavaList(String.class); |
| | | List<String> longs = Arrays.asList(userTopics.getDistrictId().split(",")); |
| | | IDistrictService bean = SpringUtils.getBean(IDistrictService.class); |
| | | List<DistrictEntity> list = bean.list(Wrappers.<DistrictEntity>lambdaQuery().in(DistrictEntity::getId, longs)); |
| | | List<String> collect = list.stream().map(item -> |
| | |
| | | excelWriter.write(publicopinion, classExcelSheet.build()); |
| | | // 完成Excel写入并释放资源 |
| | | excelWriter.finish(); |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | List<holdExcel> resultList = new ArrayList<>(); |
| | | try { |
| | | // 检查区域ID字符串是否有效 |
| | | JSONArray objects1 = validateAndParseDistrictId(userTopics.getDistrictId()); |
| | | List<String> strings = validateAndParseDistrictId(userTopics.getDistrictId()); |
| | | // 获取区域服务和话题服务的实例 |
| | | IDistrictService districtService = SpringUtils.getBean(IDistrictService.class); |
| | | ITopicsService topicsService = SpringUtils.getBean(ITopicsService.class); |
| | | // 处理区域ID并查询对应的区域实体列表 |
| | | List<String> aoiCodeList = processDistrictIds(districtService, objects1); |
| | | List<String> aoiCodeList = processDistrictIds(districtService, strings); |
| | | // 设置AOI代码列表到用户话题对象中 |
| | | userTopics.setAoiCodeList(aoiCodeList); |
| | | // 查询并处理房屋列表信息 |
| | |
| | | * @return 返回一个JSONArray对象,包含解析后的区域ID。 |
| | | * @throws IllegalArgumentException 如果区域ID字符串为空或空白字符串,抛出此异常。 |
| | | */ |
| | | private JSONArray validateAndParseDistrictId(String districtIdStr) throws IllegalArgumentException { |
| | | private List<String> validateAndParseDistrictId(String districtIdStr) throws IllegalArgumentException { |
| | | // 验证区域ID字符串是否为空 |
| | | if (StringUtils.isBlank(districtIdStr)) { |
| | | throw new IllegalArgumentException("区域ID不能为空"); |
| | | } |
| | | // 解析区域ID字符串为JSONArray对象 |
| | | return JSON.parseArray(districtIdStr); |
| | | return Arrays.asList(districtIdStr.split(",")); |
| | | } |
| | | |
| | | private List<String> processDistrictIds(IDistrictService districtService, JSONArray districtIds) { |
| | | private List<String> processDistrictIds(IDistrictService districtService, List<String> districtIds) { |
| | | List<String> collect1 = districtIds.stream().map(item -> (String) item).collect(Collectors.toList()); |
| | | List<DistrictEntity> list3 = districtService.list(Wrappers.<DistrictEntity>lambdaQuery().in(DistrictEntity::getId, collect1)); |
| | | return list3.stream().map(item -> item.getAoiCode()).collect(Collectors.toList()); |