IndexServiceImpl.java 3.41 KB
package com.server.web.common.service.Impl;

import com.server.web.common.mapper.TBaseBannerMapper;
import com.server.web.common.mapper.TBaseFirstClassMapper;
import com.server.web.common.mapping.CourseMapper;
import com.server.web.common.mapping.InformationMapper;
import com.server.web.common.model.TBaseBanner;
import com.server.web.common.model.TBaseBannerExample;
import com.server.web.common.model.TBaseFirstClass;
import com.server.web.common.model.TBaseFirstClassExample;
import com.server.web.common.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;

import static com.server.utils.ResultMapUtil.returnMap;

/**
 * Created by weiwenfu@163.com on 2018/12/12 下午 3:05.
 */
@Service
public class IndexServiceImpl implements IndexService {

    @Autowired
    private TBaseBannerMapper tBaseBannerMapper;
    @Autowired
    private TBaseFirstClassMapper tBaseFirstClassMapper;
    @Autowired
    private InformationMapper informationMapper;
    @Autowired
    private CourseMapper courseMapper;

    @Override
    public Map<String, Object> banner() {
        TBaseBannerExample tBaseBannerExample = new TBaseBannerExample();
        tBaseBannerExample.createCriteria().andIsUpEqualTo(1).andIsDeleteEqualTo(0);
        tBaseBannerExample.setOrderByClause(" weight desc ");
        List<TBaseBanner> list = tBaseBannerMapper.selectByExample(tBaseBannerExample);
        return returnMap("1", "", list);
    }

    /**
     * 首页分类
     *
     * @return
     */
    @Override
    public Map<String, Object> categoryList() {
        TBaseFirstClassExample tBaseFirstClassExample = new TBaseFirstClassExample();
        tBaseFirstClassExample.setOrderByClause(" weight desc");
        tBaseFirstClassExample.createCriteria().andStatusEqualTo(1);
        List<TBaseFirstClass> list = tBaseFirstClassMapper.selectByExample(tBaseFirstClassExample);
        return returnMap("1", "", list);
    }

    /**
     * 首页分类+两条资讯
     *
     * @return
     */
    @Override
    public Map<String, Object> categoryDetail() {
        TBaseFirstClassExample tBaseFirstClassExample = new TBaseFirstClassExample();
        tBaseFirstClassExample.setOrderByClause(" weight desc");
        tBaseFirstClassExample.createCriteria().andStatusEqualTo(1);
        List<TBaseFirstClass> list = tBaseFirstClassMapper.selectByExample(tBaseFirstClassExample);

        List<Map<String, Object>> resultList = new ArrayList<>();
        Map<String, Object> flagMap = null;
        for (TBaseFirstClass tBaseFirstClass : list) {
            flagMap = new HashMap<String, Object>();
            flagMap.put("className", tBaseFirstClass.getClassName());
            flagMap.put("id", tBaseFirstClass.getId());

            List<Map<String, Object>> list2 = informationMapper.categoryDetail(tBaseFirstClass.getId());
            flagMap.put("informationList", list2);
            resultList.add(flagMap);
        }
        return returnMap("1", "", resultList);
    }

    @Override
    public Map<String, Object> livingCourseToday() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Map<String, Object> param = new HashMap<>();
        param.put("today", simpleDateFormat.format(new Date()));
        List<Map<String, Object>> list = courseMapper.livingCourseToday(param);
        return returnMap("1", "", list);
    }
}