package com.fdage.service.impl;

import com.fdage.dao.base.TbInformationMapper;
import com.fdage.dao.cust.TbInformationMapperCust;
import com.fdage.pojo.TbInformation;
import com.fdage.request.RequestInformation;
import com.fdage.respon.ResponInformation;
import com.fdage.service.IInformationService;
import com.fdage.util.HTMLSpirit;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Hb_zzZ on 2019/9/11.
 */
@Service
public class InformationServiceImpl implements IInformationService {

    @Autowired
    private TbInformationMapper mapper;

    @Autowired
    private TbInformationMapperCust mapperCust;

    @Override
    public int insert(TbInformation bo) {
        return mapper.insertSelective(bo);
    }

    @Override
    public int update(TbInformation bo) {
        return mapper.updateByPrimaryKeySelective(bo);
    }

    @Override
    public int delete(Long id) {
        return mapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<ResponInformation> findList(RequestInformation bo) {
        if(bo == null){
            bo = new RequestInformation();
            bo.setState(0);
            return mapperCust.findList(bo);
        }
        int pageNum = bo.getPageNum() == 0? 1: bo.getPageNum();
        int pageSize = bo.getPageSize() == 0? 10: bo.getPageSize();
        PageHelper.startPage(pageNum, pageSize);

        return mapperCust.findList(bo);
    }

    @Override
    public List<ResponInformation> listAll() {
        List<ResponInformation> list = mapperCust.findList(null);
        for(ResponInformation responInformation : list){
            //返回给文通的数据过滤掉html标签
            if(responInformation.getDescription() != null){
                responInformation.setDescription(HTMLSpirit.delHTMLTag(StringEscapeUtils.unescapeHtml4(responInformation.getDescription())));
            }
        }
        return list;
    }

}
