| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import liquibase.pro.packaged.H; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.jetbrains.annotations.Nullable; |
| | | import org.springblade.common.constant.CommonConstant; |
| | |
| | | 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.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.HouseholdEntity; |
| | | import org.springblade.modules.house.service.IHouseholdService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | userTopics.setAoiCodeList(collect); |
| | | } |
| | | } |
| | | return page.setRecords(baseMapper.selectUserTopicsPage(page, userTopics)); |
| | | IHouseholdService householdService = SpringUtils.getBean(IHouseholdService.class); |
| | | HouseholdEntity householdEntity = householdService.getOne(Wrappers.<HouseholdEntity>lambdaQuery() |
| | | .eq(HouseholdEntity::getHouseCode, userTopics.getHouseCode()) |
| | | .eq(HouseholdEntity::getAssociatedUserId, AuthUtil.getUserId()) |
| | | .eq(HouseholdEntity::getIsDeleted, 0) |
| | | .last("limit 1")); |
| | | if (householdEntity != null) { |
| | | userTopics.setHouseholdId(householdEntity.getId()); |
| | | } |
| | | List<UserTopicsVO> userTopicsVOS = baseMapper.selectUserTopicsPage(page, userTopics); |
| | | return page.setRecords(userTopicsVOS); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean batchSave(List<TopicsVO> topics) throws Exception { |
| | | public String batchSave(List<TopicsVO> topics) throws Exception { |
| | | // 判断是否一户一票 还是一人一票 |
| | | IHouseholdService householdService = SpringUtils.getBean(IHouseholdService.class); |
| | | HouseholdEntity householdEntity = householdService.getOne(Wrappers.<HouseholdEntity>lambdaQuery() |
| | | .eq(HouseholdEntity::getHouseCode, topics.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, topics.get(0).getArticleId())); |
| | | // 一户一票 |
| | | if (one.getVoteRestrictions().equals(CommonConstant.NUMBER_ONE)) { |
| | | long count = count(Wrappers.<UserTopicsEntity>lambdaQuery() |
| | | .eq(UserTopicsEntity::getHouseCode, topics.get(0).getHouseCode()) |
| | | .eq(UserTopicsEntity::getArticleId,topics.get(0).getArticleId())); |
| | | if (count > 1) { |
| | | throw new Exception("您的房屋已投票,不能重复投票!"); |
| | | .eq(UserTopicsEntity::getArticleId, topics.get(0).getArticleId())); |
| | | if (count > 0) { |
| | | return "您的房屋已投票,不能重复投票!"; |
| | | } |
| | | } else { |
| | | // |
| | | long count = count(Wrappers.<UserTopicsEntity>lambdaQuery() |
| | | .eq(UserTopicsEntity::getUserId, AuthUtil.getUserId()) |
| | | .eq(UserTopicsEntity::getArticleId,topics.get(0).getArticleId())); |
| | | if (count > 1) { |
| | | throw new Exception("您的已投票,不能重复投票!"); |
| | | .eq(UserTopicsEntity::getHouseholdId, householdEntity.getId()) |
| | | .eq(UserTopicsEntity::getArticleId, topics.get(0).getArticleId())); |
| | | if (count > 0) { |
| | | return "您已投票,不能重复投票!"; |
| | | } |
| | | } |
| | | Boolean userTopics = getaBoolean(topics); |
| | | if (userTopics != null) return userTopics; |
| | | return false; |
| | | for (TopicsVO topic : topics) { |
| | | if (topic.getMandatoryFlag().equals(2)) { |
| | | if (topic.getOptionNumberMin() > 1) { |
| | | JSONArray objects1 = JSON.parseArray(topic.getSelected()); |
| | | if (objects1.size() < topic.getOptionNumberMin()) { |
| | | return topic.getDiscussContent() + ":议题最少需要选择" + topic.getOptionNumberMin() + "项"; |
| | | } |
| | | } |
| | | if (topic.getOptionNumber() > 1) { |
| | | JSONArray objects1 = JSON.parseArray(topic.getSelected()); |
| | | if (objects1.size() > topic.getOptionNumber()) { |
| | | return topic.getDiscussContent() + ":议题最多需要选择" + topic.getOptionNumber() + "项"; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | Boolean userTopics = getaBoolean(topics,householdEntity); |
| | | if (userTopics) return "200"; |
| | | return "操作失败!"; |
| | | } |
| | | |
| | | @Nullable |
| | | private Boolean getaBoolean(List<TopicsVO> topics) { |
| | | private Boolean getaBoolean(List<TopicsVO> topics,HouseholdEntity householdEntity) { |
| | | List<UserTopicsEntity> objects = new ArrayList<>(); |
| | | Boolean result = false; |
| | | for (TopicsVO topic : topics) { |
| | | UserTopicsEntity userTopicsEntity = new UserTopicsEntity(); |
| | | userTopicsEntity.setUserId(AuthUtil.getUserId()); |
| | | userTopicsEntity.setHouseholdId(householdEntity.getId()); |
| | | userTopicsEntity.setSelected(topic.getSelected()); |
| | | userTopicsEntity.setTopicsId(topic.getId()); |
| | | userTopicsEntity.setPublicDiscussId(topic.getPublicDiscussId()); |
| | |
| | | } |
| | | UserTopicsEntity userTopics = new UserTopicsEntity(); |
| | | userTopics.setSelected(topic.getSelected()); |
| | | userTopics.setUserId(AuthUtil.getUserId()); |
| | | userTopics.setHouseholdId(householdEntity.getId()); |
| | | userTopics.setPublicDiscussId(topic.getPublicDiscussId()); |
| | | userTopics.setTopicsId(Integer.valueOf(topic.getSelected())); |
| | | userTopics.setArticleId(topic.getArticleId()); |
| | |
| | | objectUpdateWrapper.setSql("number = number + 1"); |
| | | objectUpdateWrapper.eq("id", topic.getSelected()); |
| | | topicsService.update(null, objectUpdateWrapper); |
| | | return save(userTopics); |
| | | result = save(userTopics); |
| | | } else { |
| | | // 多选 |
| | | if (StringUtils.isBlank(topic.getSelected())) { |
| | |
| | | for (Object o : objects1) { |
| | | UserTopicsEntity userTopics = new UserTopicsEntity(); |
| | | userTopics.setSelected(topic.getSelected()); |
| | | userTopics.setUserId(AuthUtil.getUserId()); |
| | | userTopics.setHouseholdId(householdEntity.getId()); |
| | | userTopics.setPublicDiscussId(topic.getPublicDiscussId()); |
| | | userTopics.setArticleId(topic.getArticleId()); |
| | | userTopics.setHouseCode(topic.getHouseCode()); |
| | |
| | | objectUpdateWrapper.eq("id", o); |
| | | topicsService.update(null, objectUpdateWrapper); |
| | | } |
| | | return saveBatch(objectsTwo); |
| | | result = saveBatch(objectsTwo); |
| | | } |
| | | } |
| | | return null; |
| | | return result; |
| | | } |
| | | |
| | | |
| | |
| | | public Integer getCount(Integer id) { |
| | | List<UserTopicsEntity> list = list(Wrappers.<UserTopicsEntity>lambdaQuery() |
| | | .eq(UserTopicsEntity::getPublicDiscussId, id) |
| | | .groupBy(UserTopicsEntity::getUserId)); |
| | | .groupBy(UserTopicsEntity::getHouseholdId)); |
| | | return list.size(); |
| | | } |
| | | |
| | | @Override |
| | | public List<UserTopicsExcel> exportUser(UserTopicsVO userTopics) { |
| | | if (StringUtils.isNotBlank(userTopics.getDistrictId())) { |
| | | List<String> longs = JSON.parseArray(userTopics.getDistrictId()).toJavaList(String.class); |
| | | 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 -> |
| | | item.getAoiCode() |
| | | ).collect(Collectors.toList()); |
| | | if (collect != null) { |
| | | userTopics.setAoiCodeList(collect); |
| | | } |
| | | } |
| | | List<UserTopicsExcel> userTopicsExcels = baseMapper.exportUser(userTopics); |
| | | return userTopicsExcels; |
| | | } |
| | | |
| | | @Override |
| | | public Boolean saveUserTopicsEntity(UserTopicsEntity userTopics) { |
| | | IHouseholdService householdService = SpringUtils.getBean(IHouseholdService.class); |
| | | HouseholdEntity householdEntity = householdService.getOne(Wrappers.<HouseholdEntity>lambdaQuery() |
| | | .eq(HouseholdEntity::getHouseCode, userTopics.getHouseCode()) |
| | | .eq(HouseholdEntity::getAssociatedUserId, AuthUtil.getUserId()) |
| | | .eq(HouseholdEntity::getIsDeleted, 0) |
| | | .last("limit 1")); |
| | | if (householdEntity != null) { |
| | | userTopics.setHouseholdId(householdEntity.getId()); |
| | | } |
| | | return save(userTopics); |
| | | } |
| | | } |