TopicController.java 17.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
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.*;
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.cnlive.shenhe.utils.InfoUtil;
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.beans.factory.annotation.Value;
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.HashMap;
import java.util.List;
import java.util.Map;


@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;

    @Value("${spring.localhost.url}")
    private String localhost_url;

    /**
     * 图文列表
     * 
     * @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,Integer receive, 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,receive);
        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简称
                if(CommonUtils.isNotNull(topic.getSp_id())){
                	ShySites shySites = sitesService.findspidDescByspid(topic.getSp_id());
                	if (CommonUtils.isNotNull(shySites)) {
                		topic.setSp_desc(shySites.getName());
                	}
                }else{
                	topic.setSp_desc("sp无法显示");
                }
            }
        }
        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);

    }


    /**
     * 话题审核前台通知接口
     *
     * @return
     */
    @GetMapping("/topicNotice")
    @ResponseBody
    public Map<String, Object> channelNotice() {
        Map<String, Object> map = new HashMap<>();

        ShyTopic shyTopic = new ShyTopic();
        shyTopic.setShenhe_status(CommonConst.AUDIT_INTT);
        shyTopic.setShenhe_type(CommonConst.AUDIT_TYPE_USER);
        List<ShyTopic> shyTopicList = topicService.findshyTopic(shyTopic);
        if(shyTopicList!=null&&shyTopicList.size()>0){
            logger.info("您有"+shyTopicList.size()+"条新的话题审核,请注意查看!");
            // 第三个提示框,避免冲突
            map.put("id", "3");
            map.put("title", "新话题审核通知");
            map.put("content", "您有" + shyTopicList.size() + "条新的话题审核,请注意查看!");
            map.put("url", localhost_url+"/topic/page?shenhe_status=0&receive=0");
            return map;
        }
        return null;
    }


    /**
     * 根据条件导出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();
//            }
//        }
//    }
}