VideosController.java 34.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 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
package com.cnlive.shenhe.controller;

import com.alibaba.fastjson.JSON;
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.ShySites;
import com.cnlive.shenhe.entity.ShyUsers;
import com.cnlive.shenhe.entity.ShyVideos;
import com.cnlive.shenhe.serviceImpl.SitesServiceImpl;
import com.cnlive.shenhe.serviceImpl.UsersServiceImpl;
import com.cnlive.shenhe.serviceImpl.VideosServiceImpl;
import com.cnlive.shenhe.utils.*;
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.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/videos")
public class VideosController extends BaseController {
    private static Logger logger = LoggerFactory.getLogger(VideosController.class);
    @Autowired
    AuditPass Pass;
    @Autowired
    InfoUtil infoUtil;
    @Autowired
    VideosServiceImpl videosService;
    @Autowired
    UsersServiceImpl usersService;
    @Autowired
    SitesServiceImpl sitesService;

    @Value("${qn_domain}")
    String qn_domain;

    @Value("${ks_domain}")
    String ks_domain;

    @Value("${cms_getVideoAndLiveId}")
    String cms_getVideoAndLiveId;

    /**
     * 审核信息返回接口
     *
     * @param activity_id 视频id
     * @param state       状态码
     * @param attr_tags   标签
     * @param msg         备注信息
     * @return
     */
    @PostMapping("/shenheVideo")
    @ResponseBody
    public ResponseBean shenheInfo(Integer id, String activity_id, Integer state, String attr_tags, String msg, String callback, HttpSession session) {
        logger.info("id:{},activity_id:{},state:{},attr_tags:{},msg:{},callback:{}", id, activity_id, state, attr_tags, msg, callback);
        SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
        String userId = sessionUser.getUserId();
//        ShyVideos shyVideos = videosService.selectByPrimaryKey(id);
//        if (shyVideos.getReceive() && CommonUtils.isNotEmpty(shyVideos.getReceive_user_id()) && userId.equals(shyVideos.getReceive_user_id())) {
        JSONObject result = null;
        try {
            result = Pass.auditPass(activity_id, state, attr_tags, msg, callback);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("视频审核失败");
            return new ResponseBean(ErrorEnum.ERROR);
        }
        if (result == null) {
            System.out.println("视频审核失败且接口错误没有返回信息");
            return new ResponseBean(ErrorEnum.ERROR);
        }
        Integer code = result.getInteger("code");
        String errorCode = result.getString("errorCode");
        if (code != null && code != 0) {
            System.out.println("审核失败,code==" + code);
            return new ResponseBean(code, result.getString("msg"));
        }
        if (errorCode != null && !"0".equals(errorCode)) {
            System.out.println("审核失败,code==" + code);
            return new ResponseBean(Integer.valueOf(errorCode), "服务器异常");
        }
        state = state == 4 ? 2 : 1;
        int i = videosService.updateVideo(id, userId, null, attr_tags, state, msg);
        if (i == 0) {
            return new ResponseBean(ErrorEnum.ERROR);
        }
        return new ResponseBean(ErrorEnum.SUCCESS);
//        }
//        logger.error("领取逻辑不符,不能审核,Video_id:{}", shyVideos.getVideo_id());
//        return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "领取逻辑不符,不能审核");
    }

    /**
     * 内容分页列表接口
     *
     * @param video_title
     * @param start_date
     * @param end_date
     * @param state
     * @param page
     * @param pageSize
     * @param orderByClause
     * @return
     */
    @GetMapping("/page")
    public Object getListVideos(Model model, String video_title, String start_date, String end_date, Integer state, Integer receive, Integer page, Integer pageSize, String video_priority, String orderByClause, String sp_desc, String sp_Id, String source, String video_user_id, String shen_auditor_id, Integer contentId, String video_id, HttpSession session) {
        if (!StringUtils.isEmpty(shen_auditor_id)) {
            if ((!"自动审核".equals(shen_auditor_id)) && (!"白名单".equals(shen_auditor_id))) {
                shen_auditor_id = usersService.findspidByName(shen_auditor_id);
            }
        }

        SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
        if (CommonUtils.isNull(sessionUser)) {
            return "redirect:/users/login";
        }
        Integer spid = sessionUser.getSpid();
        logger.info("sp_Id:{},spid:{}", sp_Id, spid);
        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;
        }

        if (CommonUtils.isNotNull(contentId)) {
            Map<String, String> map = new HashMap<>(1);
            map.put("id", contentId.toString());
            String post = HttpClientUtils.get(cms_getVideoAndLiveId, map);
            JSONObject jsonObject = JSONObject.parseObject(post);
            JSONObject data = jsonObject.getJSONObject("data");
            if (data != null) {
                String pid = data.getString("pid");
                video_id = pid;
            } else {
                video_id = contentId.toString();
            }
        }

        PageInfo<ShyVideos> videoPage = videosService.getListContent(video_title, start_date, end_date, state, receive, page, pageSize, video_priority, orderByClause, spid, userId, sp_Id, source, video_user_id, shen_auditor_id, video_id);
        List<ShyVideos> list = videoPage.getList();
        if (!list.isEmpty()) {
            for (ShyVideos videos : list) {
                if (videos.getState() != CommonConst.AUDIT_INTT) {
                    String updater = CommonUtils.isEmpty(videos.getUpdater()) || "null".equals(videos.getUpdater()) ? "白名单" : videos.getUpdater();
                    String auditor_id = videos.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;
                        }
                    }
                    videos.setUpdater(updater);
                }
                //显示spid简称
                ShySites shySites = sitesService.findspidDescByspid(videos.getSpid());
                if (CommonUtils.isNotNull(shySites)) {
                    if (CommonUtils.isNotEmpty(videos.getCategory()) && videos.getCategory().equals(CommonConst.CATEGORY_WITNESS)) {
                        //0-目击者 1-童声共济 2-全民健身 3-目击者政府监督 4-美食中国 5-老年大学 6-旅游摄影大赛 7-老年大学公开课 8-甲申同文 9-万人同唱一首歌 10-上太空 11-芳华归来个人 12-芳华归来团体 13-小小表演家 100-追问发布会  33-万人同唱献给党-独唱 34-万人同唱献给党-合唱
                        String source1 = videos.getSource();
                        if ("1".equals(source1)) {
                            videos.setSpid_desc("童声共济" + "(目击者)");
                        } else if ("2".equals(source1)) {
                            videos.setSpid_desc("全民健身" + "(目击者)");
                        } else if ("3".equals(source1)) {
                            videos.setSpid_desc("政府监督" + "(目击者)");
                        } else if ("4".equals(source1)) {
                            videos.setSpid_desc("美食中国" + "(目击者)");
                        } else if ("5".equals(source1)) {
                            videos.setSpid_desc("老年大学" + "(目击者)");
                        } else if ("6".equals(source1)) {
                            videos.setSpid_desc("旅游摄影大赛" + "(目击者)");
                        } else if ("7".equals(source1)) {
                            videos.setSpid_desc("老年大学公开课" + "(目击者)");
                        } else if ("8".equals(source1)) {
                            videos.setSpid_desc("甲申同文" + "(目击者)");
                        } else if ("9".equals(source1)) {
                            videos.setSpid_desc("万人同唱一首歌" + "(目击者)");
                        } else if ("10".equals(source1)) {
                            videos.setSpid_desc("上太空" + "(目击者)");
                        } else if ("11".equals(source1)) {
                            videos.setSpid_desc("芳华归来个人" + "(目击者)");
                        } else if ("12".equals(source1)) {
                            videos.setSpid_desc("芳华归来团体" + "(目击者)");
                        } else if ("13".equals(source1)) {
                            videos.setSpid_desc("小小表演家" + "(目击者)");
                        } else if ("100".equals(source1)) {
                            videos.setSpid_desc("追问发布会" + "(目击者)");
                        } else if ("14".equals(source1)) {
                            videos.setSpid_desc("中国微电影" + "(目击者)");
                        } else if ("15".equals(source1)) {
                            videos.setSpid_desc("幼儿闯关" + "(目击者)");
                        } else if ("16".equals(source1)) {
                            videos.setSpid_desc("少儿闯关" + "(目击者)");
                        } else if ("101".equals(source1)) {
                            videos.setSpid_desc("电商-cms" + "(目击者)");
                        } else if ("17".equals(source1)) {
                            videos.setSpid_desc("青岛读书" + "(目击者)");
                        } else if ("18".equals(source1)) {
                            videos.setSpid_desc("红色故事演讲" + "(目击者)");
                        } else if ("19".equals(source1)) {
                            videos.setSpid_desc("红色诗词朗诵" + "(目击者)");
                        } else if ("20".equals(source1)) {
                            videos.setSpid_desc("红色短剧展演" + "(目击者)");
                        } else if ("21".equals(source1)) {
                            videos.setSpid_desc("视频号" + "(目击者)");
                        } else if ("29".equals(source1)) {
                            videos.setSpid_desc("中国故事上太空" + "(目击者)");
                        } else if ("30".equals(source1)) {
                            videos.setSpid_desc("绽放夕阳二期" + "(目击者)");
                        } else if ("31".equals(source1)) {
                            videos.setSpid_desc("绽放夕阳三期" + "(目击者)");
                        } else if ("33".equals(source1)) {
                            videos.setSpid_desc("万人同唱献给党-独唱" + "(目击者)");
                        } else if ("34".equals(source1)) {
                            videos.setSpid_desc("万人同唱献给党-合唱" + "(目击者)");
                        } else if ("29".equals(source1)) {
                            videos.setSpid_desc("我们的声音上太空" + "(目击者)");
                        } else if ("35".equals(source1)) {
                            videos.setSpid_desc("精英少年作品展示" + "(目击者)");
                        } else if ("36".equals(source1)) {
                            videos.setSpid_desc("上太空成年" + "(目击者)");
                        } else if ("37".equals(source1)) {
                            videos.setSpid_desc("中国推介" + "(目击者)");
                        } else if ("38".equals(source1)) {
                            videos.setSpid_desc("教学成果展" + "(目击者)");
                        } else if ("39".equals(source1)) {
                            videos.setSpid_desc("绽放夕阳" + "(目击者)");
                        } else if ("40".equals(source1)) {
                            videos.setSpid_desc("家乡推介" + "(目击者)");
                        } else if ("41".equals(source1)) {
                            videos.setSpid_desc("老体协-柔力球" + "(目击者)");
                        } else if ("42".equals(source1)) {
                            videos.setSpid_desc("老体协-健身球操" + "(目击者)");
                        } else if ("43".equals(source1)) {
                            videos.setSpid_desc("老体协-太极拳" + "(目击者)");
                        } else if ("44".equals(source1)) {
                            videos.setSpid_desc("老体协-持杖健走" + "(目击者)");
                        } else if ("45".equals(source1)) {
                            videos.setSpid_desc("老体协-广场舞" + "(目击者)");
                        } else if ("46".equals(source1)) {
                            videos.setSpid_desc("老体协-健身秧歌(鼓)" + "(目击者)");
                        } else if ("47".equals(source1)) {
                            videos.setSpid_desc("老体协-综合类" + "(目击者)");
                        } else if ("48".equals(source1)) {
                            videos.setSpid_desc("少儿吟诵" + "(目击者)");
                        } else if ("49".equals(source1)) {
                            videos.setSpid_desc("少年先锋" + "(目击者)");
                        } else if ("50".equals(source1)) {
                            videos.setSpid_desc("巾帼故事汇" + "(目击者)");
                        } else if ("51".equals(source1)) {
                            videos.setSpid_desc("浣花吟唱节" + "(目击者)");
                        } else {
                            videos.setSpid_desc(shySites.getName() + "(目击者)");
                        }
                    } else if (CommonUtils.isNotEmpty(videos.getCategory()) && videos.getCategory().equals(CommonConst.CATEGORY_MOMENT)) {
                        videos.setSpid_desc(shySites.getName() + "(朋友圈)");
                    } else {
                        videos.setSpid_desc(shySites.getName());
                    }
                }
            }
        }
        /* 获取参数值给前台 用来判断是否需要把查看显示出来 state recive*/
        String state1 = state == null ? "" : state.toString();
        String receive1 = "";
        if (CommonUtils.isNotNull(receive)) {
            receive1 = receive == CommonConst.RECEIVE_AFTER ? "true" : "false";
        } else {
            receive1 = "";
        }
        model.addAttribute("state1", state1);
        model.addAttribute("receive1", receive1);
        model.addAttribute("pageSize", pageSize);
        model.addAttribute("videoPage", videoPage);
        model.addAttribute("sp_Id", sp_Id);
        return "page/video.html";
    }

    /**
     * 内容详情页接口(查看)
     *
     * @param id
     * @return
     */
    @GetMapping("/details")
    public Object getDetailsVideo(Model model, Integer id) {
        ShyVideos detailsContent = videosService.getDetailsContent(id);
        Object images = JSON.parse(detailsContent.getVideo_imgs());
        Object avsampleImgs = JSON.parse(detailsContent.getAvsample_imgs());
        String yuming = "";
        Integer plat = detailsContent.getPlat();
        if (plat == CommonConst.QINIU_PLAT) {
            yuming = qn_domain + "/";
        } else if (plat == CommonConst.KS_PLAT) {
            yuming = ks_domain + "/";
        }
        detailsContent.setAttr_tags(CommonUtils.isEmpty(detailsContent.getAttr_tags()) ? "" : detailsContent.getAttr_tags());

        ShySites shySites = sitesService.findspidDescByspid(detailsContent.getSpid());
        if (CommonUtils.isNotNull(shySites)) {
            if (CommonUtils.isNotEmpty(detailsContent.getCategory()) && detailsContent.getCategory().equals(CommonConst.CATEGORY_WITNESS)) {
                //0-目击者 1-童声共济 2-全民健身 3-目击者政府监督 4-美食中国 5-老年大学 6-旅游摄影大赛 7-老年大学公开课 8-甲申同文 9-万人同唱一首歌 10-上太空 11-芳华归来个人 12-芳华归来团体 13-小小表演家 100-追问发布会  33-万人同唱献给党-独唱 34-万人同唱献给党-合唱
                String source1 = detailsContent.getSource();
                if ("1".equals(source1)) {
                    detailsContent.setSpid_desc("童声共济" + "(目击者)");
                } else if ("2".equals(source1)) {
                    detailsContent.setSpid_desc("全民健身" + "(目击者)");
                } else if ("3".equals(source1)) {
                    detailsContent.setSpid_desc("政府监督" + "(目击者)");
                } else if ("4".equals(source1)) {
                    detailsContent.setSpid_desc("美食中国" + "(目击者)");
                } else if ("5".equals(source1)) {
                    detailsContent.setSpid_desc("老年大学" + "(目击者)");
                } else if ("6".equals(source1)) {
                    detailsContent.setSpid_desc("旅游摄影大赛" + "(目击者)");
                } else if ("7".equals(source1)) {
                    detailsContent.setSpid_desc("老年大学公开课" + "(目击者)");
                } else if ("8".equals(source1)) {
                    detailsContent.setSpid_desc("甲申同文" + "(目击者)");
                } else if ("9".equals(source1)) {
                    detailsContent.setSpid_desc("万人同唱一首歌" + "(目击者)");
                } else if ("10".equals(source1)) {
                    detailsContent.setSpid_desc("上太空" + "(目击者)");
                } else if ("11".equals(source1)) {
                    detailsContent.setSpid_desc("芳华归来个人" + "(目击者)");
                } else if ("12".equals(source1)) {
                    detailsContent.setSpid_desc("芳华归来团体" + "(目击者)");
                } else if ("13".equals(source1)) {
                    detailsContent.setSpid_desc("小小表演家" + "(目击者)");
                } else if ("100".equals(source1)) {
                    detailsContent.setSpid_desc("追问发布会" + "(目击者)");
                } else if ("14".equals(source1)) {
                    detailsContent.setSpid_desc("中国微电影" + "(目击者)");
                } else if ("15".equals(source1)) {
                    detailsContent.setSpid_desc("幼儿闯关" + "(目击者)");
                } else if ("16".equals(source1)) {
                    detailsContent.setSpid_desc("少儿闯关" + "(目击者)");
                } else if ("101".equals(source1)) {
                    detailsContent.setSpid_desc("电商-cms" + "(目击者)");
                } else if ("17".equals(source1)) {
                    detailsContent.setSpid_desc("青岛读书" + "(目击者)");
                } else if ("18".equals(source1)) {
                    detailsContent.setSpid_desc("红色故事演讲" + "(目击者)");
                } else if ("19".equals(source1)) {
                    detailsContent.setSpid_desc("红色诗词朗诵" + "(目击者)");
                } else if ("20".equals(source1)) {
                    detailsContent.setSpid_desc("红色短剧展演" + "(目击者)");
                } else if ("21".equals(source1)) {
                    detailsContent.setSpid_desc("视频号" + "(目击者)");
                } else if ("33".equals(source1)) {
                    detailsContent.setSpid_desc("万人同唱献给党-独唱" + "(目击者)");
                } else if ("34".equals(source1)) {
                    detailsContent.setSpid_desc("万人同唱献给党-合唱" + "(目击者)");
                } else if ("29".equals(source1)) {
                    detailsContent.setSpid_desc("我们的声音上太空" + "(目击者)");
                } else {
                    detailsContent.setSpid_desc(shySites.getName() + "(目击者)");
                }
            } else if (CommonUtils.isNotEmpty(detailsContent.getCategory()) && detailsContent.getCategory().equals(CommonConst.CATEGORY_MOMENT)) {
                detailsContent.setSpid_desc(shySites.getName() + "(朋友圈)");
            } else {
                detailsContent.setSpid_desc(shySites.getName());
            }
        }
        model.addAttribute("images", images);
        model.addAttribute("avsampleImgs", avsampleImgs);
        model.addAttribute("video", detailsContent);
        model.addAttribute("yuming", yuming);
        return "page/videoDetail.html";
    }

    /**
     * 认领
     *
     * @param ids     根据id认领
     * @param num     认领条数
     * @param session
     * @return
     */
    @PostMapping("/receive")
    @ResponseBody
    public ResponseBean receive(String ids, Integer num, HttpSession session) {
        SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
        String userId = sessionUser.getUserId();
        Integer spid = sessionUser.getSpid();
        //领取时要检查领取的数据是否可以领
        if (CommonUtils.isNotEmpty(ids)) {
            String[] cids = ids.split(",");
            for (String cid : cids) {
                ShyVideos shyVideos = videosService.selectByPrimaryKey(Integer.parseInt(cid));
                if (CommonUtils.isNotNull(shyVideos)) {
                    if (shyVideos.getState() != CommonConst.AUDIT_INTT || shyVideos.getReceive() == CommonConst.RECEIVE_AFTER) {
                        return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "您领取的内容中有已被领取或者已经被审核,请检查并重试");
                    }
                } else {
                    return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "您领取的内容不存在,请检查并重试");

                }
            }
        }
        Integer n = videosService.receive(ids, num, userId, spid);
        return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(), "认领到" + n + "条内容");
    }


    /**
     * 退领
     *
     * @param ids
     * @param session
     * @return
     */
    @PostMapping("/retReceive")
    @ResponseBody
    public ResponseBean retReceive(String ids, HttpSession session) {
        SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
        String userId = sessionUser.getUserId();
        //在退领操作前先判断是否包含已退领或者已经审核的数据,有则退回检查并重新退领
        String[] cids = ids.split(",");
        for (String cid : cids) {
            ShyVideos shyVideos = videosService.selectByPrimaryKey(Integer.parseInt(cid));
            if (shyVideos.getState() != CommonConst.AUDIT_INTT || shyVideos.getReceive() == CommonConst.RECEIVE_BEFORE || !shyVideos.getReceive_user_id().equals(userId)) {
                return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "退领失败,您选中的内容包含已退领的或已经审核的");
            }
        }
        return videosService.retReceive(ids, userId);
    }

    /**
     * 根据条件导出excel
     *
     * @param video_title
     * @param start_date
     * @param end_date
     * @param state
     * @param receive
     * @param video_priority
     * @param orderByClause
     * @param session
     * @param response
     */
    @GetMapping("excel")
    public void getExcel(String video_title, String start_date, String end_date, Integer state, Integer receive, String video_priority, Integer source, String video_user_id, String orderByClause, Integer sp_Id, String sp_desc, HttpSession session, HttpServletResponse response) {
        if (CommonUtils.isNotEmpty(sp_desc)) {
            ShySites shySite = sitesService.findspidBySpdesc(sp_desc);
            if (CommonUtils.isNotNull(shySite)) {
                sp_Id = shySite.getSpid();
            }
        }
        SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
        Integer spid = sessionUser.getSpid();
        String userId = sessionUser.getUserId();
        if (spid == 0) spid = null;
        if (sp_Id != null) {
            spid = sp_Id;
        }
        List<ShyVideos> shyVideosList = videosService.findByCondition(video_title, start_date, end_date, state, receive, video_priority, orderByClause, spid, userId, source, video_user_id);
        String fileName = "点播数据";
        String updater = "";//审核员名字
        String state1 = "";//审核状态 1已审核 2审核拒绝 0未审核
        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("标题");
            cell = row.createCell(2);//列
            cell.setCellValue("视频地址");
            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("视频id");
            cell = row.createCell(12);//列
            cell.setCellValue("创建时间");
            cell = row.createCell(13);//列
            cell.setCellValue("视频上传时间");
            cell = row.createCell(14);//列
            cell.setCellValue("视频时长(秒)");
            cell = row.createCell(15);//列
            cell.setCellValue("spid");
            cell = row.createCell(16);//列
            cell.setCellValue("sp简称");

            for (int i = 0; i < shyVideosList.size(); i++) {
                row = sheetlist.createRow((short) (i + 1));//行
                cell = row.createCell(0);//列
                cell.setCellValue(shyVideosList.get(i).getId());
                cell = row.createCell(1);//列
                cell.setCellValue(shyVideosList.get(i).getVideo_title());
                cell = row.createCell(2);//列
                cell.setCellValue(shyVideosList.get(i).getVideo_url());
                cell = row.createCell(3);//列
                cell.setCellValue(shyVideosList.get(i).getVideo_poster());
                cell = row.createCell(4);//列
                cell.setCellValue(shyVideosList.get(i).getVideo_tags());
                cell = row.createCell(5);//列
                /* 审核员需要做处理*/
                if (shyVideosList.get(i).getState() != CommonConst.AUDIT_INTT) {
                    updater = CommonUtils.isEmpty(shyVideosList.get(i).getUpdater()) || "null".equals(shyVideosList.get(i).getUpdater()) ? "白名单" : shyVideosList.get(i).getUpdater();
                    String auditor_id = shyVideosList.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.setCellValue(updater);
                cell = row.createCell(6);//列、增加一列
                cell.setCellValue(shyVideosList.get(i).getAttr_tags());
                cell = row.createCell(7);//列
                cell.setCellValue(shyVideosList.get(i).getMsg());
                cell = row.createCell(8);//列
                /*状态需要处理成用户可读*/
                if (shyVideosList.get(i).getState() == 0) {
                    state1 = "未审核";
                } else if (shyVideosList.get(i).getState() == 1) {
                    state1 = "已审核";
                } else {
                    state1 = "审核拒绝";
                }
                cell.setCellValue(state1);
                cell = row.createCell(9);//列
                cell.setCellValue(shyVideosList.get(i).getVideo_keyword());
                cell = row.createCell(10);//列
                cell.setCellValue(shyVideosList.get(i).getVideo_desc());
                cell = row.createCell(11);//列
                cell.setCellValue(shyVideosList.get(i).getVideo_id());
                cell = row.createCell(12);//列
                cell.setCellValue(CommonUtils.formatDate(shyVideosList.get(i).getCreated_at(), "yyyy-MM-dd HH:mm:ss"));
                cell = row.createCell(13);//列
                cell.setCellValue(CommonUtils.formatDate(shyVideosList.get(i).getVideo_upload_time(), "yyyy-MM-dd HH:mm:ss"));
                cell = row.createCell(14);//列
                cell.setCellValue(shyVideosList.get(i).getDuration());
                cell = row.createCell(15);//列
                cell.setCellValue(shyVideosList.get(i).getSpid());
                cell = row.createCell(16);//列

                //显示spid简称
                ShySites shySites = sitesService.findspidDescByspid(shyVideosList.get(i).getSpid());
                if (CommonUtils.isNotNull(shySites)) {
                    if (CommonUtils.isNotEmpty(shyVideosList.get(i).getCategory()) && shyVideosList.get(i).getCategory().equals(CommonConst.CATEGORY_WITNESS)) {
                        cell.setCellValue(shySites.getName() + "(目击者)");
                    } else if (CommonUtils.isNotEmpty(shyVideosList.get(i).getCategory()) && shyVideosList.get(i).getCategory().equals(CommonConst.CATEGORY_MOMENT)) {
                        cell.setCellValue(shySites.getName() + "(朋友圈)");
                    } else {
                        cell.setCellValue(shySites.getName());
                    }
                }
            }

            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();
            }
        }
    }

    /**
     * 打回(审核拒绝,应要求不加权限、状态等限制)
     *
     * @param ids
     * @param msg
     * @param session
     * @return
     */
    @PostMapping("/repulse")
    @ResponseBody
    public ResponseBean repulse(String ids, String msg, HttpSession session) {
        logger.info("ids:{},msg:{}", ids, msg);
        SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
        String userId = sessionUser.getUserId();
        ResponseBean responseBean = new ResponseBean();
        String[] shyVideoIds = ids.split(",");
        String showMsg = "";
        for (String shyVideoId : shyVideoIds) {
            showMsg = videosService.repulse(shyVideoId, msg, userId);
        }
        if (CommonUtils.isNotEmpty(showMsg)) {
            responseBean.setErrorCode(ErrorEnum.ERROR.getErrorCode());
            responseBean.setErrorMessage(showMsg);
        }
        return responseBean;
    }

    @GetMapping("/ceshi")
    @ResponseBody
    public void ceshi() {
        System.out.println("进入测试");
//    	InfoUtil test = new InfoUtil();
//    	infoUtil.show("测试通知", "这是一个弹窗测试!",localhost_url+"/channel/page?shenhe_status=0&receive=0");

    }

}