TopicController.java 16.4 KB
package com.cnlive.shenhe.controller;

import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.bean.ErrorEnum;
import com.cnlive.shenhe.bean.ResponseBean;
import com.cnlive.shenhe.bean.SessionUser;
import com.cnlive.shenhe.entity.ShyComments;
import com.cnlive.shenhe.entity.ShyContent;
import com.cnlive.shenhe.entity.ShyLive;
import com.cnlive.shenhe.entity.ShySites;
import com.cnlive.shenhe.entity.ShyTopic;
import com.cnlive.shenhe.entity.ShyUsers;
import com.cnlive.shenhe.entity.ShyVideos;
import com.cnlive.shenhe.serviceImpl.CommentsServiceImpl;
import com.cnlive.shenhe.serviceImpl.ContentServiceImpl;
import com.cnlive.shenhe.serviceImpl.SitesServiceImpl;
import com.cnlive.shenhe.serviceImpl.TopicServiceImpl;
import com.cnlive.shenhe.serviceImpl.UsersServiceImpl;
import com.cnlive.shenhe.utils.AuditPass;
import com.cnlive.shenhe.utils.CommonConst;
import com.cnlive.shenhe.utils.CommonUtils;
import com.github.pagehelper.PageInfo;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.Date;
import java.util.List;


@Controller
@RequestMapping("/topic")
public class TopicController extends BaseController {
    private static Logger logger = LoggerFactory.getLogger(TopicController.class);
    @Autowired
    AuditPass Pass;
    @Autowired
    CommentsServiceImpl commentsService;
    @Autowired
    TopicServiceImpl topicService;
    @Autowired
    SitesServiceImpl sitesService;

    @Autowired
    UsersServiceImpl usersService;

    /**
     * 图文列表
     * 
     * @param model
     * @param title
     * @param start_date
     * @param end_date
     * @param receive_status
     * @param sp_desc
     * @param page
     * @param pageSize
     * @param orderByClause
     * @param session
     * @return
     */
    @GetMapping("/page")
    public String getPage(Model model,  String topic_name,String topic_id, String topic_tag,
                          String start_date, String end_date, Integer shenhe_status, String sp_desc,
                          Integer page, Integer pageSize, String orderByClause, HttpSession session) {
        SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
        if(CommonUtils.isNull(sessionUser)){
        	return "redirect:/users/login";
        }
        Integer spid = sessionUser.getSpid();
        String userId = sessionUser.getUserId();
        if (CommonUtils.isNull(page)) page = 1;
        if (CommonUtils.isNull(pageSize)) pageSize = 10;
        if (CommonUtils.isNotEmpty(sp_desc) && spid == 0) {
        	ShySites shySite=sitesService.findspidBySpdesc(sp_desc);
        	if(CommonUtils.isNotNull(shySite)){
        		spid = shySite.getSpid();
        	}else{
        		setmodel_site(model);
        		return "error.html";
        	}
        } else if (CommonUtils.isEmpty(sp_desc) && spid == 0) {
            spid = null;
        }
        Date sDate = null;
        Date eDate = null;

        if (CommonUtils.isNotEmpty(start_date)) {
            try {
                sDate = CommonUtils.parseDate(start_date, "yyyy-MM-dd");
            } catch (Exception e) {
            }
        }
        if (CommonUtils.isNotEmpty(end_date)) {
            try {
                eDate = CommonUtils.parseDate(end_date, "yyyy-MM-dd");
            } catch (Exception e) {
            }
        }
        PageInfo<ShyTopic> topicPage = topicService.getPage( topic_name,topic_tag,topic_id,  sDate, eDate, shenhe_status, null, page, pageSize, orderByClause, spid, userId);
        List<ShyTopic> list = topicPage.getList();
        if (!list.isEmpty()) {
            for (ShyTopic topic : list) {
                if (topic.getShenhe_status() != CommonConst.AUDIT_INTT) {
                	String auditor_id = topic.getAuditor_id();
                	String updater = CommonUtils.isEmpty(topic.getUpdater()) || "null".equals(topic.getUpdater())? "白名单":topic.getUpdater();
                    updater =sitesService.getUpdater(updater,auditor_id);
                    topic.setUpdater(updater);
                }
                //显示spid简称
                ShySites shySites = sitesService.findspidDescByspid(topic.getSp_id());
                if (CommonUtils.isNotNull(shySites)) {
                	topic.setSp_desc(shySites.getName());
                }
            }
        }
        model.addAttribute("topicPage", topicPage);
        model.addAttribute("pageSize", pageSize);
        return "page/topic.html";
    }


    /**
     * 审核通过
     *
     * @param ids
     * @return
     */
    @PostMapping("/pass")
    @ResponseBody
    public ResponseBean pass(String ids, HttpSession session) {
        SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
        String userId = sessionUser.getUserId();
        boolean success =false;
        String[] topicIds = ids.split(",");
		for (String id : topicIds) {
            success = topicService.callback(id,"审核通过", CommonConst.AUDIT_SUCCESS, userId,"");
            if(!success){
            	return new ResponseBean(ErrorEnum.ERROR);
            }
		}
        return new ResponseBean(ErrorEnum.SUCCESS);
    }

    /**
     * 审核拒绝
     *
     * @param ids
     * @return
     */
    @PostMapping("/refuse")
    @ResponseBody
    public ResponseBean refuse(String ids,String msg, HttpSession session) {
        SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
        String userId = sessionUser.getUserId();
        boolean success =false;
        String[] contentIds = ids.split(",");
		for (String id : contentIds) {
			 success = topicService.callback(id,msg, CommonConst.AUDIT_REFUSE, userId,"");
			 if(!success){
	            	return new ResponseBean(ErrorEnum.ERROR);
	            }
			}
	    return new ResponseBean(ErrorEnum.SUCCESS);

    }


    /**
     * 根据条件导出excel
     */
//    @GetMapping("excel")
//    public void getExcel( String title,String contentId, String content_tag,
//            String start_date, String end_date, Integer receive_status, String sp_desc,
//            Integer page, Integer pageSize, String orderByClause, HttpSession session,HttpServletResponse response) {
//        SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
//        Integer spid = sessionUser.getSpid();
//        String userId = sessionUser.getUserId();
//        if (CommonUtils.isNotEmpty(sp_desc) && spid == 0) {
//        	ShySites shySite=sitesService.findspidBySpdesc(sp_desc);
//        	if(CommonUtils.isNotNull(shySite)){
//        		spid = shySite.getSpid();
//        		}
//        	}else if (CommonUtils.isEmpty(sp_desc) && spid == 0) {
//            spid = null;
//        	}
//        Date sDate = null;
//        Date eDate = null;
//
//        if (CommonUtils.isNotEmpty(start_date)) {
//            try {
//                sDate = CommonUtils.parseDate(start_date, "yyyy-MM-dd");
//            } catch (Exception e) {
//            }
//        }
//        if (CommonUtils.isNotEmpty(end_date)) {
//            try {
//                eDate = CommonUtils.parseDate(end_date, "yyyy-MM-dd");
//            } catch (Exception e) {
//            }
//        }
//        List<ShyContent> contentList = contentService.findByCondition(title,content_tag,contentId,  sDate, eDate, receive_status,  page, pageSize, orderByClause, spid);
//        
//        String fileName = "图文数据";
//        
//        XSSFWorkbook wb = new XSSFWorkbook();
//        ServletOutputStream out = null;
//        BufferedInputStream bis = null;
//        BufferedOutputStream bos = null;
//        try {
//            XSSFSheet sheetlist = wb.createSheet(fileName);
//            XSSFRow row = sheetlist.createRow(0);//行
//            XSSFCell cell = row.createCell(0);//列
//            cell.setCellValue("id");
//            cell = row.createCell(1);//列
//            cell.setCellValue("sp昵称");
//            cell = row.createCell(2);//列
//            cell.setCellValue("图文id");
//            cell = row.createCell(3);//列
//            cell.setCellValue("内容标题");
//            cell = row.createCell(4);//列
//            cell.setCellValue("图文标签");
//            cell = row.createCell(5);//列
//            cell.setCellValue("审核类型");
//            cell = row.createCell(6);//列
//            cell.setCellValue("内容状态");
//            cell = row.createCell(7);//列
//            cell.setCellValue("图文创建时间");
//            cell = row.createCell(8);//列
//            cell.setCellValue("图文送审时间");
//            cell = row.createCell(9);//列
//            cell.setCellValue("领取状态");
//            cell = row.createCell(10);//列
//            cell.setCellValue("审核人");
//            cell = row.createCell(11);//列
//            cell.setCellValue("审核意见");
//            cell = row.createCell(12);//列
//            cell.setCellValue("来源(昵称)");
//            cell = row.createCell(13);//列
//            cell.setCellValue("作者(sid)");
//            cell = row.createCell(14);//列
//            cell.setCellValue("图文url");
//            
//            for (int i = 0; i < contentList.size(); i++) {
//                row = sheetlist.createRow((short) (i + 1));//行
//                cell = row.createCell(0);//列
//                cell.setCellValue(contentList.get(i).getId());
//                cell = row.createCell(1);//列
//                cell.setCellValue(sitesService.findspidDescByspid(contentList.get(i).getSp_id()).getName());
//                cell = row.createCell(2);//列
//                cell.setCellValue(contentList.get(i).getContent_id());
//                cell = row.createCell(3);//列
//                cell.setCellValue(contentList.get(i).getTitle());
//                /*状态需要处理成用户可读*/
//                String contentTag = "";//图文标签 content:图文发布,moment:朋友圈
//                if (contentList.get(i).getContent_tag().equals("content") ) {
//                	contentTag = "图文发布";
//                } else if (contentList.get(i).getContent_tag().equals("moment")) {
//                	contentTag = "朋友圈";
//                }
//                cell = row.createCell(4);//列
//                cell.setCellValue(contentTag);
//               
//                /*状态需要处理成用户可读*/
//                String shenheType = "";//审核类型,1:免审,2:机审,3:人工审
//                if (contentList.get(i).getShenhe_type() == 1) {
//             	   shenheType = "免审";
//                } else if (contentList.get(i).getShenhe_type() == 2) {
//             	   shenheType = "机审";
//                } else {
//             	   shenheType = "人工审";
//                }
//                cell = row.createCell(5);//列
//                cell.setCellValue(shenheType);
//                
//                /*状态需要处理成用户可读*/
//                String contentStatus = "";//内容状态:0:待发布,1:已发布,2:已下线,3:已删除
//                if (contentList.get(i).getContent_status() == 0) {
//                	contentStatus = "待发布";
//                } else if (contentList.get(i).getContent_status() == 1) {
//                	contentStatus = "已发布";
//                } else if(contentList.get(i).getContent_status() == 2){
//                	contentStatus = "已下线";
//                }else if(contentList.get(i).getContent_status() == 3){
//                	contentStatus = "已删除";
//                }
//                
//                cell = row.createCell(6);//列
//                cell.setCellValue(contentStatus);
//                cell = row.createCell(7);//列
//                cell.setCellValue(contentList.get(i).getContent_time()==null?"":CommonUtils.formatDate(contentList.get(i).getContent_time(), "yyyy-MM-dd HH:mm:ss"));
//                cell = row.createCell(8);//列
//                cell.setCellValue(contentList.get(i).getCreate_date()==null?"":CommonUtils.formatDate(contentList.get(i).getCreate_date(), "yyyy-MM-dd HH:mm:ss"));
//                
//                /*状态需要处理成用户可读*/
//                String receiveStatus = "";//领取状态。0:未领取;1:已领取,2:已审核
//                if (contentList.get(i).getReceive_status() == 1) {
//                	receiveStatus = "已领取";
//                } else if (contentList.get(i).getReceive_status() == 2) {
//                	receiveStatus = "已审核";
//                } else {
//                	receiveStatus = "未领取";
//                }
//                
//                cell = row.createCell(9);//列
//                cell.setCellValue(receiveStatus);
//                
//                /* 审核员需要做处理*/
//                String updater = "";//审核员名字
//                if (contentList.get(i).getReceive_status() != CommonConst.RECEIVE_BEFORE) {
//                	updater = CommonUtils.isEmpty(contentList.get(i).getUpdater()) || "null".equals(contentList.get(i).getUpdater())? "自动通过":contentList.get(i).getUpdater();
//                    String auditor_id = contentList.get(i).getAuditor_id();
//                    if (CommonUtils.isNotEmpty(auditor_id)) {
//                        ShyUsers user = new ShyUsers();
//                        user.setUser_id(auditor_id);
//                        user = usersService.select(user);
//                        if (CommonUtils.isNotNull(user)) {
//                        	String email = CommonUtils.isEmpty(user.getEmail()) || "null".equals(user.getEmail()) ? "" : user.getEmail();
//                            String userName = CommonUtils.isEmpty(user.getUsername()) ? email : user.getUsername();
//                            updater = userName ;
//                        }
//                    }
//                }
//                cell = row.createCell(10);//列
//                cell.setCellValue(updater);
//                
//               
//                
//                cell = row.createCell(11);//列
//                cell.setCellValue(contentList.get(i).getShenhe_msg());
//                cell = row.createCell(12);//列
//                cell.setCellValue(contentList.get(i).getSource());
//                cell = row.createCell(13);//列
//                cell.setCellValue(contentList.get(i).getAuthor());
//                cell = row.createCell(14);//列
//                cell.setCellValue(contentList.get(i).getContent_url());
//            }
//
//            ByteArrayOutputStream os = new ByteArrayOutputStream();
//            wb.write(os);
//            byte[] content = os.toByteArray();
//            InputStream is = new ByteArrayInputStream(content);
//            response.setContentType("application/vnd.ms-excel;charset=utf-8");
//            response.setHeader("Content-Disposition", "attachment;filename=" + new String((fileName + ".xlsx").getBytes(), "iso-8859-1"));
//            out = response.getOutputStream();
//            bis = new BufferedInputStream(is);
//            bos = new BufferedOutputStream(out);
//            byte[] buff = new byte[2048];
//            int bytesRead;
//            while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
//                bos.write(buff, 0, bytesRead);
//            }
//        } catch (final Exception e) {
//            e.printStackTrace();
//            try {
//                if (bis != null)
//                    bis.close();
//                if (bos != null)
//                    bos.close();
//            } catch (Exception e1) {
//                e1.printStackTrace();
//            }
//        } finally {
//            try {
//                if (bis != null)
//                    bis.close();
//                if (bos != null)
//                    bos.close();
//            } catch (Exception e2) {
//                e2.printStackTrace();
//            }
//        }
//    }
}