admin
2021-07-30 19533a17aa55fafc70d0a385928e785cb50e1ebc
src/main/java/com/yeshi/buwan/service/imp/recommend/HomeRecommendSpecialServiceImpl.java
@@ -4,7 +4,11 @@
import com.yeshi.buwan.dao.recommend.SuperHomeRecommendSpecialDao;
import com.yeshi.buwan.domain.recommend.HomeRecommendSpecial;
import com.yeshi.buwan.domain.recommend.SuperHomeRecommendSpecial;
import com.yeshi.buwan.domain.system.DetailSystem;
import com.yeshi.buwan.domain.web.DetailSystemSelect;
import com.yeshi.buwan.dto.recommend.HomeRecommendSpecialDTO;
import com.yeshi.buwan.exception.ParamsException;
import com.yeshi.buwan.service.imp.SystemService;
import com.yeshi.buwan.service.inter.recommend.HomeRecommendSpecialService;
import com.yeshi.buwan.util.StringUtil;
import org.springframework.stereotype.Service;
@@ -23,6 +27,55 @@
    @Resource
    private SuperHomeRecommendSpecialDao superHomeRecommendSpecialDao;
    @Resource
    private SystemService systemService;
    @Override
    public List<HomeRecommendSpecialDTO> list(String systemId, String detailSystemId, String key, int page, int pageSize) {
        List<HomeRecommendSpecialDTO> dtoList = new ArrayList<>();
        List<DetailSystem> detailSystemList = systemService.getDetailSystemList(systemId);
        List<HomeRecommendSpecial> list = null;
        if (!StringUtil.isNullOrEmpty(detailSystemId)) {
            list = listSpecialByDetailSystemId(detailSystemId, key, page, pageSize);
        } else {
            list = listSpecialBySystemId(systemId, key, page, pageSize);
        }
        for (HomeRecommendSpecial special : list) {
            List<DetailSystemSelect> selects = new ArrayList<>();
            HomeRecommendSpecialDTO dto = new HomeRecommendSpecialDTO();
            //查询super
            List<SuperHomeRecommendSpecial> superHomeRecommendSpecialList = listSuperSpecialBySpecialId(special.getId());
            for (DetailSystem detailSystem : detailSystemList) {
                detailSystem.setInfo(null);
                DetailSystemSelect select = new DetailSystemSelect();
                select.setDetailSystem(detailSystem);
                for (SuperHomeRecommendSpecial s : superHomeRecommendSpecialList) {
                    if (s.getDetailSystemId().equalsIgnoreCase(detailSystem.getId())) {
                        select.setSelected(true);
                        break;
                    }
                }
                selects.add(select);
            }
            dto.setDetailSystemSelectList(selects);
            dto.setSpecial(special);
            dtoList.add(dto);
        }
        return dtoList;
    }
    @Override
    public long count(String systemId, String detailSystemId, String key) {
        if (!StringUtil.isNullOrEmpty(detailSystemId)) {
            return countSpecialByDetailSystemId(detailSystemId, key);
        } else {
            return countSpecialBySystemId(systemId, key);
        }
    }
    @Validated
    @Override
@@ -48,18 +101,40 @@
    }
    @Override
    public List<HomeRecommendSpecial> listSpecialBySystemId(String systemId) {
    public HomeRecommendSpecial getSpecial(String id) {
        return homeRecommendSpecialDao.get(id);
    }
    @Override
    public HomeRecommendSpecial getSpecialByDataKey(String dataKey) {
        return homeRecommendSpecialDao.selectByDataKey(dataKey);
    }
    @Override
    public List<HomeRecommendSpecial> listSpecialBySystemId(String systemId, String key, int page, int pageSize) {
        HomeRecommendSpecialDao.DaoQuery query = new HomeRecommendSpecialDao.DaoQuery();
        query.systemId = systemId;
        query.count = Integer.MAX_VALUE;
        query.key = key;
        query.start = (page - 1) * pageSize;
        query.count = pageSize;
        return homeRecommendSpecialDao.list(query);
    }
    @Override
    public List<HomeRecommendSpecial> listSpecialByDetailSystemId(String detailSystemId) {
    public long countSpecialBySystemId(String systemId, String key) {
        HomeRecommendSpecialDao.DaoQuery query = new HomeRecommendSpecialDao.DaoQuery();
        query.systemId = systemId;
        query.key = key;
        return homeRecommendSpecialDao.count(query);
    }
    @Override
    public List<HomeRecommendSpecial> listSpecialByDetailSystemId(String detailSystemId, String key, int page, int pageSize) {
        SuperHomeRecommendSpecialDao.DaoQuery query = new SuperHomeRecommendSpecialDao.DaoQuery();
        query.detailSystemId = detailSystemId;
        query.count = Integer.MAX_VALUE;
        query.showName = key;
        query.start = (page - 1) * pageSize;
        query.count = pageSize;
        List<SuperHomeRecommendSpecial> list = superHomeRecommendSpecialDao.list(query);
        List<String> specialIds = new ArrayList<>();
        for (SuperHomeRecommendSpecial special : list) {
@@ -92,6 +167,14 @@
    }
    @Override
    public long countSpecialByDetailSystemId(String detailSystemId, String key) {
        SuperHomeRecommendSpecialDao.DaoQuery query = new SuperHomeRecommendSpecialDao.DaoQuery();
        query.detailSystemId = detailSystemId;
        query.showName = key;
        return superHomeRecommendSpecialDao.count(query);
    }
    @Override
    public void deleteSpecial(String specialId) {
        List<SuperHomeRecommendSpecial> list = listSuperSpecialBySpecialId(specialId);
@@ -116,6 +199,11 @@
        if (superSpecial.getWeight() == null) {
            superSpecial.setWeight(special.getWeight());
        }
        if (superSpecial.getShowName() == null) {
            superSpecial.setShowName(special.getName());
        }
        if (superSpecial.getCreateTime() == null)
            superSpecial.setCreateTime(new Date());
        superHomeRecommendSpecialDao.save(superSpecial);