CommentsServiceImpl.java 3.15 KB
package com.cnlive.shenhe.serviceImpl;

import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.entity.AcpComments;
import com.cnlive.shenhe.entity.ShySites;
import com.cnlive.shenhe.mapper.AcpCommentsMapper;
import com.cnlive.shenhe.mapper.ShySitesMapper;
import com.cnlive.shenhe.utils.CommonUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @Auther: chenhao
 * @Date: 2018/12/4 17:30
 * @Description:
 */
@Service
public class CommentsServiceImpl {
    @Autowired
    AcpCommentsMapper acpCommentsMapper;
    @Autowired
    ShySitesMapper shySitesMapper;


    public List<ShySites> getBusiness (ShySites shySites ) {
        List<ShySites> sitesList = shySitesMapper.select(shySites);
        return sitesList;
    }
    public int impotComments(AcpComments acpComments){
        int result = acpCommentsMapper.insert(acpComments);
        return result;
    }
    public int updateComment(JSONObject json){
        AcpComments acpComments = new AcpComments();
        acpComments.setActivity_id(json.getString("activity_id"));
        Integer id = acpCommentsMapper.select(acpComments).get(0).getId();
        acpComments.setId(id);
        acpComments.setState(json.getInteger("state"));
        acpComments.setMsg(json.getString("msg"));
        int result = acpCommentsMapper.updateByPrimaryKeySelective(acpComments);
        return result;
    }
    public PageInfo<AcpComments> getListComments(String activity_id,String content,Integer is_hot,String start_date,String end_date,Integer state,String auditor,Integer page,Integer pageSize,String orderByClause){
        Example example = new Example(AcpComments.class);
        Example.Criteria criteria = example.createCriteria();
        if (CommonUtils.isNotEmpty(orderByClause)) {
            example.setOrderByClause(orderByClause);
        }
        if (CommonUtils.isNotEmpty(start_date)&&CommonUtils.isNotEmpty(end_date)) {
            criteria.andGreaterThanOrEqualTo("comment_time",start_date);
            criteria.andLessThanOrEqualTo("comment_time",end_date);
        }
        if (CommonUtils.isNotEmpty(content)){
            criteria.andLike("comment_content", "%" + content + "%");
        }
        if (CommonUtils.isNotEmpty(auditor)){
            criteria.andEqualTo("auditor",  auditor );
        }
        if (CommonUtils.isNotNull(is_hot)){
            criteria.andEqualTo("is_hot", is_hot );
        }
        if (CommonUtils.isNotEmpty(activity_id)){
            criteria.andEqualTo("activity_id", activity_id);
        }
        //默认按上传时间倒序排序
        example.setOrderByClause("comment_time desc");
        PageHelper.startPage(page, pageSize, true);
        List<AcpComments> commentsList = acpCommentsMapper.selectByExample(example);
        PageInfo<AcpComments> pageInfo = new PageInfo<>(commentsList);
        return pageInfo;
    }

    public Object getDetailsComment(Integer id){
        AcpComments comment = acpCommentsMapper.selectByPrimaryKey(id);
        return comment;
    }
}