package com.yeshi.buwan.service.imp.live;
|
|
import com.yeshi.buwan.dao.live.SuperTVLiveCategoryDao;
|
import com.yeshi.buwan.dao.live.TVLiveCategoryDao;
|
import com.yeshi.buwan.domain.live.SuperTVLiveCategory;
|
import com.yeshi.buwan.domain.live.TVLiveCategory;
|
import com.yeshi.buwan.exception.live.TVLiveCategoryException;
|
import com.yeshi.buwan.service.inter.live.TVLiveCategoryService;
|
import com.yeshi.buwan.util.StringUtil;
|
import org.springframework.data.domain.Sort;
|
import org.springframework.data.mongodb.core.query.Criteria;
|
import org.springframework.data.mongodb.core.query.Query;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
|
@Service
|
public class TVLiveCategoryServiceImpl implements TVLiveCategoryService {
|
@Resource
|
private SuperTVLiveCategoryDao superTVLiveCategoryDao;
|
|
@Resource
|
private TVLiveCategoryDao tvLiveCategoryDao;
|
|
|
@Override
|
public void addCategory(TVLiveCategory category, List<String> detailSystemList) throws TVLiveCategoryException {
|
//查询分类名称是否存在
|
category.setId(StringUtil.Md5(category.getName()));
|
TVLiveCategory old = tvLiveCategoryDao.get(category.getId());
|
if (old != null)
|
throw new TVLiveCategoryException(1, "分类已经存在");
|
|
if (category.getCreateTime() == null)
|
category.setCreateTime(new Date());
|
|
tvLiveCategoryDao.save(category);
|
|
for (String detailSystemId : detailSystemList) {
|
SuperTVLiveCategory superTVLiveCategory = new SuperTVLiveCategory();
|
superTVLiveCategory.setCid(category.getId());
|
superTVLiveCategory.setDetailSystemId(detailSystemId);
|
superTVLiveCategory.setCreateTime(new Date());
|
superTVLiveCategory.setWeight(1);
|
addSuperCategory(superTVLiveCategory);
|
}
|
}
|
|
@Override
|
public void deleteCateogry(List<String> ids) {
|
for (String cid : ids) {
|
List<SuperTVLiveCategory> scList = superTVLiveCategoryDao.listByCid(cid);
|
for (SuperTVLiveCategory sc : scList) {
|
superTVLiveCategoryDao.delete(sc.getId());
|
}
|
tvLiveCategoryDao.delete(cid);
|
}
|
}
|
|
@Override
|
public void updateCategory(TVLiveCategory category) {
|
tvLiveCategoryDao.updateSelective(category);
|
}
|
|
@Override
|
public List<TVLiveCategory> list(String detailSystemId, String systemId, String nameKey, int page, int pageSize) {
|
if (detailSystemId != null) {
|
List<SuperTVLiveCategory> superTVLiveCategoryList = superTVLiveCategoryDao.listByDetailSystemId(detailSystemId, (page - 1) * pageSize, pageSize);
|
if (superTVLiveCategoryList == null || superTVLiveCategoryList.size() == 0)
|
return null;
|
List<String> cids = new ArrayList<>();
|
|
for (SuperTVLiveCategory sc : superTVLiveCategoryList) {
|
cids.add(sc.getCid());
|
}
|
List<TVLiveCategory> categoryList = tvLiveCategoryDao.listByIds(cids);
|
Map<String, TVLiveCategory> map = new HashMap<>();
|
for (TVLiveCategory tc : categoryList) {
|
map.put(tc.getId(), tc);
|
}
|
|
|
List<TVLiveCategory> resultList = new ArrayList<>();
|
for (SuperTVLiveCategory sc : superTVLiveCategoryList) {
|
resultList.add(map.get(sc.getCid()));
|
}
|
return resultList;
|
} else {
|
TVLiveCategoryDao.DaoQuery daoQuery = new TVLiveCategoryDao.DaoQuery();
|
daoQuery.systemId = systemId;
|
daoQuery.start = (page - 1) * pageSize;
|
daoQuery.count = pageSize;
|
daoQuery.name = nameKey;
|
daoQuery.sortList = Arrays.asList(new Sort.Order(Sort.Direction.DESC, "createTime"));
|
return tvLiveCategoryDao.list(daoQuery);
|
}
|
}
|
|
@Override
|
public long count(String detailSystemId, String systemId, String nameKey) {
|
if (detailSystemId != null) {
|
return superTVLiveCategoryDao.countByDetailSystemId(detailSystemId);
|
} else {
|
TVLiveCategoryDao.DaoQuery daoQuery = new TVLiveCategoryDao.DaoQuery();
|
daoQuery.name = nameKey;
|
daoQuery.systemId = systemId;
|
return tvLiveCategoryDao.count(daoQuery);
|
}
|
}
|
|
@Override
|
public List<TVLiveCategory> listByIds(List<String> idList) {
|
Criteria[] ors = new Criteria[idList.size()];
|
for (int i = 0; i < idList.size(); i++) {
|
ors[i] = Criteria.where("_id").is(idList.get(i));
|
}
|
Query query = new Query();
|
query.addCriteria(new Criteria().orOperator(ors));
|
return tvLiveCategoryDao.findList(query);
|
}
|
|
@Override
|
public List<SuperTVLiveCategory> listSuper(String detailSystemId, int page, int pageSize) {
|
|
return superTVLiveCategoryDao.listByDetailSystemId(detailSystemId, (page - 1) * pageSize, pageSize);
|
|
}
|
|
@Override
|
public void addSuperCategory(SuperTVLiveCategory superCategory) {
|
if (superCategory == null)
|
return;
|
superCategory.setId(SuperTVLiveCategory.createId(superCategory.getCid(), superCategory.getDetailSystemId()));
|
|
if (superTVLiveCategoryDao.get(superCategory.getId()) != null)
|
return;
|
|
if (superCategory.getCreateTime() == null)
|
superCategory.setCreateTime(new Date());
|
superTVLiveCategoryDao.save(superCategory);
|
}
|
|
@Override
|
public void updateSuperCategory(SuperTVLiveCategory superCategory) {
|
superTVLiveCategoryDao.updateSelective(superCategory);
|
}
|
|
@Override
|
public void deleteSuperCategory(String id) {
|
superTVLiveCategoryDao.deleteByPrimaryKey(id);
|
}
|
|
@Override
|
public void deleteSuperCategory(String categoryId, String detailSystemId) {
|
SuperTVLiveCategory sc = superTVLiveCategoryDao.selectByCidAndDetailsystemId(categoryId, detailSystemId);
|
if (sc != null)
|
deleteSuperCategory(sc.getId());
|
}
|
|
@Override
|
public List<SuperTVLiveCategory> listSuper(String cid) {
|
return superTVLiveCategoryDao.listByCid(cid);
|
}
|
|
@Override
|
public TVLiveCategory selectCategoryBuPrimaryKey(String id) {
|
return tvLiveCategoryDao.get(id);
|
}
|
|
|
}
|