From d678db8fe85e51b65403f3edae4bff18aa23ee15 Mon Sep 17 00:00:00 2001 From: cloudroam <cloudroam> Date: 星期二, 01 七月 2025 10:28:07 +0800 Subject: [PATCH] add:影视景点管理 --- src/main/java/com/mzl/flower/service/film/impl/FilmWorksServiceImpl.java | 269 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 247 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/mzl/flower/service/film/impl/FilmWorksServiceImpl.java b/src/main/java/com/mzl/flower/service/film/impl/FilmWorksServiceImpl.java index 4fa277e..e6e0575 100644 --- a/src/main/java/com/mzl/flower/service/film/impl/FilmWorksServiceImpl.java +++ b/src/main/java/com/mzl/flower/service/film/impl/FilmWorksServiceImpl.java @@ -11,11 +11,14 @@ import com.mzl.flower.dto.request.system.UserInfoDTO; import com.mzl.flower.dto.response.customer.CustomerDTO; import com.mzl.flower.dto.response.film.FilmWorksVO; +import com.mzl.flower.dto.response.system.MenuTreeDTO; import com.mzl.flower.entity.film.FilmWorks; +import com.mzl.flower.entity.system.Role; import com.mzl.flower.mapper.customer.CustomerMapper; import com.mzl.flower.mapper.film.FilmWorksMapper; import com.mzl.flower.service.film.FilmWorksService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.mzl.flower.service.system.RoleService; import com.mzl.flower.utils.DateUtils; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; @@ -24,7 +27,11 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.time.LocalDate; +import java.util.ArrayList; import java.util.List; /** @@ -42,31 +49,63 @@ private final FilmWorksMapper filmWorksMapper; private final CustomerMapper customerMapper; + private final RoleService roleService; @Override public void saveFilmWorks(FilmWorksDTO filmWorksDTO) { + //获取当前人员角色,判断是不是编辑角色 + List<String> roleIds = new ArrayList<>(); + List<Role> roleList = roleService.getUserRoleList(SecurityUtils.getUserId()); + for (Role role : roleList) { + roleIds.add(role.getId()); + } + if (!roleIds.contains("8f9ef89f6b2d4d8e9ea1fc8d2f25ce69")) { + throw new ValidationException("非编辑角色不能新增"); + } // 转换 FilmWorks filmWorks = new FilmWorks(); BeanUtils.copyProperties(filmWorksDTO, filmWorks); filmWorks.create(); - filmWorks.setStatus(Constants.COMMON_PUBLISH_STATUS.unpublished.name()); + filmWorks.setStatus(Constants.COMMON_PUBLISH_STATUS.pending_review.name()); filmWorksMapper.insert(filmWorks); } @Override public void updateFilmWorks(FilmWorksDTO filmWorksDTO) { - FilmWorks filmWork = filmWorksMapper.selectById(filmWorksDTO.getId()); FilmWorks filmWorks = new FilmWorks(); - BeanUtils.copyProperties(filmWorksDTO,filmWorks); + //系统生成的内容无需管理 + if ("sys".equals(filmWorksDTO.getType())) { + filmWorks = filmWorksMapper.selectById(filmWorksDTO.getId()); + filmWorks.setFilmContent(filmWorksDTO.getFilmContent()); + //生成之后变成待审核 + if(StringUtils.isNotBlank(filmWorks.getFilmContent())){ + filmWorks.setStatus(Constants.COMMON_PUBLISH_STATUS.pending_review.name()); + }else{ + filmWorks.setStatus(Constants.COMMON_PUBLISH_STATUS.create_failed.name()); + } - if (filmWork != null) { - filmWorks.setClassify(filmWork.getClassify()); - filmWorks.setCreateBy(filmWork.getCreateBy()); - filmWorks.setCreateTime(filmWork.getCreateTime()); - filmWorks.setStatus(filmWork.getStatus()); + } else { + List<String> roleIds = new ArrayList<>(); + List<Role> roleList = roleService.getUserRoleList(SecurityUtils.getUserId()); + for (Role role : roleList) { + roleIds.add(role.getId()); + } + if (!roleIds.contains("8f9ef89f6b2d4d8e9ea1fc8d2f25ce69")) { + throw new ValidationException("非编辑角色不能修改"); + } + filmWorks = filmWorksMapper.selectById(filmWorksDTO.getId()); + //判断影视作品状态 + if(Constants.COMMON_PUBLISH_STATUS.published.name().equals(filmWorks.getStatus()) ){ + throw new ValidationException("发布作品不能编辑"); + } + + if(Constants.COMMON_PUBLISH_STATUS.approved.name().equals(filmWorks.getStatus()) ){ + throw new ValidationException("审核作品不能编辑"); + } + BeanUtils.copyProperties(filmWorksDTO, filmWorks); + filmWorks.update(SecurityUtils.getUserId()); + filmWorks.setStatus(Constants.COMMON_PUBLISH_STATUS.pending_review.name()); } - - filmWorks.update(SecurityUtils.getUserId()); filmWorksMapper.updateById(filmWorks); } @@ -87,8 +126,33 @@ if(StringUtils.isNotBlank(dto.getCreateDateEndStr())){ dto.setCreateDateEnd(DateUtils.dateToLocalDateTime(dto.getCreateDateEndStr(),false)); } + if (!StringUtils.isEmpty(dto.getCategory()) && Constants.FILM_CATEGORY.all.getDesc().equals(dto.getCategory())) { + //当时全部的时时候值设置为空,表示查询全部 + dto.setCategory(null); + } + + //todo 这里的用户ID可能为空,用户存在不登录的情况下访问,传null + try { + dto.setUserId(SecurityUtils.getUserId()); + } catch (Exception e) { + dto.setUserId(null); + } List<FilmWorksVO> list = filmWorksMapper.queryPage(dto,page); + // 测试前端展示用代码,部署发布不适用 +// list.forEach(l->{ +// if (l.getCoverUrl().contains("doubanio")) { +// String encodedUrl = null; +// try { +// encodedUrl = URLEncoder.encode(l.getCoverUrl(), String.valueOf(StandardCharsets.UTF_8)); +// } catch (UnsupportedEncodingException e) { +// throw new RuntimeException(e); +// } +// l.setCoverUrl("https://images.weserv.nl/?url=" + encodedUrl); +// } +// }); page.setRecords(list); + + return page; } @@ -98,17 +162,118 @@ } @Override + public List<FilmWorksVO> pendingCreate() { + return filmWorksMapper.pendingCreate(); + } + + @Override public void changeStatus(Long id) { + //获取当前人员角色,判断是不是审核角色 + List<String> roleIds = new ArrayList<>(); + List<Role> roleList = roleService.getUserRoleList(SecurityUtils.getUserId()); + for (Role role : roleList) { + roleIds.add(role.getId()); + } + if (!roleIds.contains("77462b362bad4c88a7a5c64cbdd25d91")) { + throw new ValidationException("非运营角色不能发布"); + } FilmWorks filmWork = filmWorksMapper.selectById(id); if (filmWork == null) { throw new ValidationException("找不到id为" + id + "的公告"); } - if (Constants.COMMON_PUBLISH_STATUS.published.name().equals(filmWork.getStatus())) { - filmWork.setStatus(Constants.COMMON_PUBLISH_STATUS.unpublished.name()); - } else { - filmWork.setStatus(Constants.COMMON_PUBLISH_STATUS.published.name()); - filmWork.setPublishDate(LocalDate.now()); + if (Constants.COMMON_PUBLISH_STATUS.approved.name().equals(filmWork.getStatus()) || Constants.COMMON_PUBLISH_STATUS.published.name().equals(filmWork.getStatus()) || Constants.COMMON_PUBLISH_STATUS.unpublished.name().equals(filmWork.getStatus())) { + if (Constants.COMMON_PUBLISH_STATUS.published.name().equals(filmWork.getStatus())) { + filmWork.setStatus(Constants.COMMON_PUBLISH_STATUS.unpublished.name()); + } else { + filmWork.setStatus(Constants.COMMON_PUBLISH_STATUS.published.name()); + filmWork.setPublishDate(LocalDate.now()); + } + filmWorksMapper.updateById(filmWork); + }else{ + throw new ValidationException("非审核通过或者发布状态,不能操作"); } + } + + + @Override + public void changeCreateStatus(Long id) { + //获取当前人员角色,判断是不是审核角色 + List<String> roleIds = new ArrayList<>(); + List<Role> roleList = roleService.getUserRoleList(SecurityUtils.getUserId()); + for (Role role : roleList) { + roleIds.add(role.getId()); + } + if (!roleIds.contains("8f9ef89f6b2d4d8e9ea1fc8d2f25ce69")) { + throw new ValidationException("非编辑角色不能操作"); + } + FilmWorks filmWork = filmWorksMapper.selectById(id); + if (filmWork == null) { + throw new ValidationException("找不到id为" + id + "的作品"); + } + if (Constants.COMMON_PUBLISH_STATUS.pending_create.name().equals(filmWork.getStatus()) || Constants.COMMON_PUBLISH_STATUS.create_cancel.name().equals(filmWork.getStatus()) || Constants.COMMON_PUBLISH_STATUS.create_failed.name().equals(filmWork.getStatus())) { + if (Constants.COMMON_PUBLISH_STATUS.create_cancel.name().equals(filmWork.getStatus())) { + filmWork.setStatus(Constants.COMMON_PUBLISH_STATUS.pending_create.name()); + } else if (Constants.COMMON_PUBLISH_STATUS.create_failed.name().equals(filmWork.getStatus())) { + filmWork.setStatus(Constants.COMMON_PUBLISH_STATUS.pending_create.name()); + } else { + filmWork.setStatus(Constants.COMMON_PUBLISH_STATUS.create_cancel.name()); + filmWork.setPublishDate(LocalDate.now()); + } + filmWorksMapper.updateById(filmWork); + }else{ + throw new ValidationException("当前状态,不能操作"); + } + } + + + @Override + public void changeTopState(Long id) { + //获取当前人员角色,判断是不是审核角色 + List<String> roleIds = new ArrayList<>(); + List<Role> roleList = roleService.getUserRoleList(SecurityUtils.getUserId()); + for (Role role : roleList) { + roleIds.add(role.getId()); + } + if (!roleIds.contains("77462b362bad4c88a7a5c64cbdd25d91")) { + throw new ValidationException("非运营角色不能置顶"); + } + FilmWorks filmWork = filmWorksMapper.selectById(id); + if (filmWork == null) { + throw new ValidationException("找不到id为" + id + "的公告"); + } + if (Constants.COMMON_PUBLISH_STATUS.unpublished.name().equals(filmWork.getStatus())) { + throw new ValidationException("未发布作品不能置顶,请先发布"); + } + + FilmWorks filmWorkTop = filmWorksMapper.getTopStickyWeight(); + if (!ObjectUtils.isEmpty(filmWorkTop)) { + filmWork.setStickyWeight(filmWorkTop.getStickyWeight() + 100); + } else { + filmWork.setStickyWeight(100); + } + filmWorksMapper.updateById(filmWork); + } + + + @Override + public void changeDownState(Long id) { + //获取当前人员角色,判断是不是审核角色 + List<String> roleIds = new ArrayList<>(); + List<Role> roleList = roleService.getUserRoleList(SecurityUtils.getUserId()); + for (Role role : roleList) { + roleIds.add(role.getId()); + } + if (!roleIds.contains("77462b362bad4c88a7a5c64cbdd25d91")) { + throw new ValidationException("非运营角色不能清除权重"); + } + FilmWorks filmWork = filmWorksMapper.selectById(id); + if (filmWork == null) { + throw new ValidationException("找不到id为" + id + "的公告"); + } + if (Constants.COMMON_PUBLISH_STATUS.unpublished.name().equals(filmWork.getStatus())) { + throw new ValidationException("未发布作品无需清除权重"); + } + filmWork.setStickyWeight(0); filmWorksMapper.updateById(filmWork); } @@ -119,6 +284,16 @@ @Override public void batchPublish(BatchDTO dto) { + //获取当前人员角色,判断是不是审核角色 + List<String> roleIds = new ArrayList<>(); + List<Role> roleList = roleService.getUserRoleList(SecurityUtils.getUserId()); + for (Role role : roleList) { + roleIds.add(role.getId()); + } + if (!roleIds.contains("77462b362bad4c88a7a5c64cbdd25d91")) { + throw new ValidationException("非运营角色不能发布"); + } + List<FilmWorks> list = filmWorksMapper.selectList(new LambdaQueryWrapper<FilmWorks>().in(FilmWorks::getId, dto.getIds())); for (FilmWorks filmWork : list) { filmWork.setStatus(Constants.COMMON_PUBLISH_STATUS.published.name()); @@ -129,15 +304,65 @@ @Override public FilmWorksVO detail(Long id) { - FilmWorks filmWork = filmWorksMapper.selectById(id); - if(filmWork==null){ + // userId 可以是空,因为用户可以登录 + + String userId = SecurityUtils.getUserId(); + FilmWorksVO filmWorksVO = filmWorksMapper.selectInfoById(id,userId); + if(filmWorksVO==null){ return null; } - FilmWorksVO filmWorksVO = new FilmWorksVO(); - BeanUtils.copyProperties(filmWork,filmWorksVO); - CustomerDTO currentCustomer = customerMapper.getCurrentCustomer(filmWork.getCreateBy()); - filmWorksVO.setNickname(currentCustomer.getNickName()); - filmWorksVO.setAvatar(currentCustomer.getCover()); + CustomerDTO currentCustomer = customerMapper.getCurrentCustomer(filmWorksVO.getCreateBy()); + if(!ObjectUtils.isEmpty(currentCustomer)){ + filmWorksVO.setNickname(currentCustomer.getNickName()); + filmWorksVO.setAvatar(currentCustomer.getCover()); + } + return filmWorksVO; } + + @Override + public void batchApproved(BatchDTO dto) { + //获取当前人员角色,判断是不是审核角色 + List<String> roleIds = new ArrayList<>(); + List<Role> roleList = roleService.getUserRoleList(SecurityUtils.getUserId()); + for (Role role : roleList) { + roleIds.add(role.getId()); + } + if (!roleIds.contains("86a36a0b789c4d0e840f7b807c09459b")) { + throw new ValidationException("非审核角色不能审批"); + } + List<FilmWorks> list = filmWorksMapper.selectList(new LambdaQueryWrapper<FilmWorks>().in(FilmWorks::getId, dto.getIds())); + //判断所有的状态都是待审核 + if (!list.stream().allMatch(filmWork -> Constants.COMMON_PUBLISH_STATUS.pending_review.name().equals(filmWork.getStatus()) || Constants.COMMON_PUBLISH_STATUS.rejected.name().equals(filmWork.getStatus()))) { + throw new ValidationException("只有待审核或者审核拒绝的才能批量审核"); + } + for (FilmWorks filmWork : list) { + filmWork.setStatus(Constants.COMMON_PUBLISH_STATUS.approved.name()); + filmWork.setAuditDate(LocalDate.now()); + filmWorksMapper.updateById(filmWork); + } + } + + @Override + public void batchRejected(BatchDTO dto) { + //获取当前人员角色,判断是不是审核角色 + List<String> roleIds = new ArrayList<>(); + List<Role> roleList = roleService.getUserRoleList(SecurityUtils.getUserId()); + for (Role role : roleList) { + roleIds.add(role.getId()); + } + if (!roleIds.contains("86a36a0b789c4d0e840f7b807c09459b")) { + throw new ValidationException("非审核角色不能审批"); + } + List<FilmWorks> list = filmWorksMapper.selectList(new LambdaQueryWrapper<FilmWorks>().in(FilmWorks::getId, dto.getIds())); + //判断所有的状态都是待审核或者审核通过 + if (!list.stream().allMatch(filmWork -> Constants.COMMON_PUBLISH_STATUS.pending_review.name().equals(filmWork.getStatus()) || Constants.COMMON_PUBLISH_STATUS.approved.name().equals(filmWork.getStatus()))) { + throw new ValidationException("只有待审核或者审核通过的状态才能批量审核"); + } + for (FilmWorks filmWork : list) { + filmWork.setStatus(Constants.COMMON_PUBLISH_STATUS.rejected.name()); + filmWork.setAuditDate(LocalDate.now()); + filmWorksMapper.updateById(filmWork); + } + } } -- Gitblit v1.9.3