package com.panzhihua.service_community.service.impl; import static java.util.Objects.isNull; import static java.util.Objects.nonNull; import java.util.ArrayList; import java.util.Date; import java.util.List; import javax.annotation.Resource; import com.panzhihua.common.model.vos.community.ComMngVillageVO; import com.panzhihua.common.utlis.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.panzhihua.common.model.dtos.community.ComPropertyPublicityDTO; import com.panzhihua.common.model.dtos.community.PageComPropertyPublicityDTO; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.community.ComMngStructAreaVO; import com.panzhihua.service_community.dao.ComMngStructAreaDAO; import com.panzhihua.service_community.dao.ComPropertyDao; import com.panzhihua.service_community.dao.ComPropertyPublicityDAO; import com.panzhihua.service_community.entity.ComProperty; import com.panzhihua.service_community.model.dos.ComMngStructAreaDO; import com.panzhihua.service_community.model.dos.ComPropertyPublicityDO; import com.panzhihua.service_community.service.ComPropertyPublicityService; import lombok.extern.slf4j.Slf4j; /** * @title: ComPropertyPublicityServiceImpl * @projectName: 成都呐喊信息技术有限公司-智慧社区项目 * @description: 物业宣传服务实现类 * @author: hans * @date: 2021/11/11 13:57 */ @Service @Slf4j public class ComPropertyPublicityServiceImpl extends ServiceImpl implements ComPropertyPublicityService { @Resource private ComPropertyDao comPropertyDao; @Resource private ComMngStructAreaDAO comMngStructAreaDAO; /** * 分页查询物业宣传 * @param pageComPropertyPublicityDTO * @return */ @Override public R pageComPropertyPublicity(PageComPropertyPublicityDTO pageComPropertyPublicityDTO) { Long userId = pageComPropertyPublicityDTO.getUserId(); ComProperty comProperty = comPropertyDao.selectOne(new QueryWrapper().lambda().eq(ComProperty::getUserId, userId)); if (nonNull(comProperty)) { //用户为物业 pageComPropertyPublicityDTO.setPropertyId(comProperty.getId()); pageComPropertyPublicityDTO.setVillageId(comProperty.getAreaId()); } else { //非物业用户查看是否拥有菜单权限 List menuList = this.baseMapper.retrieveUserMenuList(userId); if (menuList.isEmpty() || !menuList.contains("物业宣传栏")) { return R.fail("暂无权限"); } } Page page = new Page<>(); page.setSize(pageComPropertyPublicityDTO.getPageSize()); page.setCurrent(pageComPropertyPublicityDTO.getPageNum()); return R.ok(this.baseMapper.pageComPropertyPublicity(page, pageComPropertyPublicityDTO)); } /** * 新增物业宣传 * @param comPropertyPublicityDTO * @return */ @Override public R addComPropertyPublicity(ComPropertyPublicityDTO comPropertyPublicityDTO) { Long userId = comPropertyPublicityDTO.getUserId(); ComProperty comProperty = comPropertyDao.selectOne(new QueryWrapper().lambda().eq(ComProperty::getUserId, userId)); if (isNull(comProperty)) { return R.fail("暂无权限"); } comPropertyPublicityDTO.setPropertyId(comProperty.getId()); ComPropertyPublicityDO publicityDO = new ComPropertyPublicityDO(); BeanUtils.copyProperties(comPropertyPublicityDTO, publicityDO); Date nowDate = new Date(); publicityDO.setCreatedAt(nowDate); publicityDO.setUpdatedAt(nowDate); int result = this.baseMapper.insert(publicityDO); if (result > 0) { return R.ok(); } return R.fail("添加失败"); } /** * 修改物业宣传 * @param comPropertyPublicityDTO * @return */ @Override public R updateComPropertyPublicity(ComPropertyPublicityDTO comPropertyPublicityDTO) { ComPropertyPublicityDO comPropertyPublicityDO = this.baseMapper.selectById(comPropertyPublicityDTO.getId()); if (isNull(comPropertyPublicityDO)) { return R.fail("信息不存在"); } BeanUtils.copyProperties(comPropertyPublicityDTO, comPropertyPublicityDO); comPropertyPublicityDO.setUpdatedAt(new Date()); int result = this.baseMapper.updateById(comPropertyPublicityDO); if (result > 0) { return R.ok(); } return R.fail("修改失败"); } /** * 查看物业宣传信息 * @param id * @return */ @Override public R getComPropertyPublicity(Long id) { return R.ok(this.baseMapper.selectDetail(id)); } /** * 删除物业宣传 * @param id * @return */ @Override public R deleteComPropertyPublicity(Long id) { this.baseMapper.deleteById(id); return R.ok(); } /** * 物业公司列表 * * @param villageId * @param communityId * @return */ @Override public R listProperty(Long villageId, Long communityId) { List propertyList; if (nonNull(villageId)) { propertyList = comPropertyDao.selectList(new QueryWrapper().lambda() .eq(ComProperty::getCommunityId, communityId).eq(ComProperty::getAreaId, villageId)); } else { propertyList = comPropertyDao.selectList(new QueryWrapper().lambda().eq(ComProperty::getCommunityId, communityId)); } return R.ok(propertyList); } /** * 分页查询物业宣传-小程序 * @param pageComPropertyPublicityDTO * @return */ @Override public R pageComPropertyPublicityApplet(PageComPropertyPublicityDTO pageComPropertyPublicityDTO) { Page page = new Page<>(); page.setSize(pageComPropertyPublicityDTO.getPageSize()); page.setCurrent(pageComPropertyPublicityDTO.getPageNum()); return R.ok(this.baseMapper.pageComPropertyPublicityApplet(page, pageComPropertyPublicityDTO)); } /** * 增加物业宣传浏览量 * @param id * @return */ @Override public R incrView(Long id) { this.baseMapper.incrView(id); return R.ok(); } }