package top.lvzhiqiang.service.impl; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import top.lvzhiqiang.config.WebAppConfig; import top.lvzhiqiang.entity.VideoGenres; import top.lvzhiqiang.entity.VideoInfo; import top.lvzhiqiang.mapper.VideoInfoInfantryMapper; import top.lvzhiqiang.mapper.VideoInfoMapper; import top.lvzhiqiang.mapper.VideoInfoPoolMapper; import top.lvzhiqiang.mapper.VideoInfoUncensoredMapper; import top.lvzhiqiang.service.VideoInfoService; import javax.annotation.Resource; import java.io.File; import java.util.List; import java.util.Map; /** * 电影信息ServiceImpl * * @author lvzhiqiang * 2022/4/4 15:28 */ @Service public class VideoInfoServiceImpl extends BaseServiceImpl implements VideoInfoService { @Resource private VideoInfoMapper videoInfoMapper; @Resource private VideoInfoPoolMapper videoInfoPoolMapper; @Resource private VideoInfoUncensoredMapper videoInfoUncensoredMapper; @Resource private VideoInfoInfantryMapper videoInfoInfantryMapper; @Value("${spring.profiles.active}") private String env; /** * 查询所有 * * @return */ @Override public List findAll() { return videoInfoMapper.findAll(); } /** * 分页查询所有 * * @return */ @Override public PageInfo findAll(int pageNo, int pageSize) { PageHelper.startPage(pageNo, pageSize); List videoInfoList = videoInfoMapper.findAll(); PageInfo videoInfoPageInfo = new PageInfo<>(videoInfoList); return videoInfoPageInfo; } @Override public PageInfo getVideoInfoPage(Map params) { Object bigType = params.get("bigType"); List videoInfoList; // 转换成like paramsToLike(params, "keyword"); // 分页 paramsToPagination(params); // 排序 paramsToSort(params); if ("骑兵".equals(bigType)) { videoInfoList = videoInfoMapper.getVideoInfoList(params); } else if ("步兵".equals(bigType)) { Object genres = params.get("genres"); if (null == genres) { List videoGenresList = videoInfoInfantryMapper.findGenres(); params.put("genres", videoGenresList.get(0).getName()); } videoInfoList = videoInfoInfantryMapper.getVideoInfoInfantryList(params); } else if ("流出".equals(bigType)) { videoInfoList = videoInfoUncensoredMapper.getVideoInfoUncensoredList(params); } else if ("码池".equals(bigType)) { videoInfoList = videoInfoPoolMapper.getVideoInfoPoolList(params); } else { videoInfoList = videoInfoMapper.getVideoInfoList(params); } PageInfo videoInfoPageInfo = new PageInfo<>(videoInfoList); return videoInfoPageInfo; } /** * 影片信息详情 * * @param type * @param code * @return */ @Override public VideoInfo getVideoInfoDetail(String type, String code) { VideoInfo videoInfo; if ("qibing".equals(type)) { videoInfo = videoInfoMapper.getVideoInfoDetail(code); if (videoInfo == null) { return null; } String qibingPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && env.equals(x.getEnv()) && "apics_path".equals(x.getCodeKey())).findFirst().get().getCodeValue(); String imgPrefixPath = "骑兵步兵/".concat(videoInfo.getIdentificationCode()).concat("/img_gf/"); videoInfo.setImgPrefixPath(imgPrefixPath); // 获取样品图像-官方 File imgGFFile = new File(qibingPath, imgPrefixPath); if (imgGFFile.exists()) { File[] files = imgGFFile.listFiles(); for (File file : files) { videoInfo.getImgGFList().add(file.getName()); } } // 获取样品图像-私有 File imgSYFile = new File(qibingPath, "骑兵步兵/".concat(videoInfo.getIdentificationCode()).concat("/img_sy/")); if (imgSYFile.exists()) { File[] files = imgSYFile.listFiles(); for (File file : files) { videoInfo.getImgSYList().add(file.getName()); } } } else if ("bubing".equals(type)) { videoInfo = null; } else if ("liuchu".equals(type)) { videoInfo = null; } else { videoInfo = null; } return videoInfo; } }