Commit d32e6a32b58f2d674b867f87008a605c7dd2e6a4

Authored by 陈浩
1 parent 21ea0459

点播审核添加 ‘导出excel’ 功能。(根据当前查询条件,导出查询出的内容)

... ... @@ -116,6 +116,17 @@
116 116 <artifactId>nekohtml</artifactId>
117 117 <version>1.9.22</version>
118 118 </dependency>
  119 +
  120 + <dependency>
  121 + <groupId>org.apache.poi</groupId>
  122 + <artifactId>poi-scratchpad</artifactId>
  123 + <version>3.16</version>
  124 + </dependency>
  125 + <dependency>
  126 + <groupId>org.apache.poi</groupId>
  127 + <artifactId>poi-ooxml</artifactId>
  128 + <version>3.16</version>
  129 + </dependency>
119 130 </dependencies>
120 131  
121 132 <build>
... ...
src/main/java/com/cnlive/shenhe/controller/VideosController.java
1 1 package com.cnlive.shenhe.controller;
2 2  
  3 +import org.apache.poi.xssf.usermodel.XSSFCell;
  4 +import org.apache.poi.xssf.usermodel.XSSFRow;
  5 +import org.apache.poi.xssf.usermodel.XSSFSheet;
  6 +import org.apache.poi.xssf.usermodel.XSSFWorkbook;
3 7 import com.alibaba.fastjson.JSON;
4 8 import com.alibaba.fastjson.JSONObject;
5 9 import com.cnlive.shenhe.bean.ErrorEnum;
... ... @@ -26,7 +30,10 @@ import org.springframework.web.bind.annotation.PostMapping;
26 30 import org.springframework.web.bind.annotation.RequestMapping;
27 31 import org.springframework.web.bind.annotation.ResponseBody;
28 32  
  33 +import javax.servlet.ServletOutputStream;
  34 +import javax.servlet.http.HttpServletResponse;
29 35 import javax.servlet.http.HttpSession;
  36 +import java.io.*;
30 37 import java.util.List;
31 38  
32 39 @Controller
... ... @@ -227,4 +234,157 @@ public class VideosController {
227 234 }
228 235 return videosService.retReceive(ids, userId);
229 236 }
  237 +
  238 + /**
  239 + * 根据条件导出excel
  240 + *
  241 + * @param video_title
  242 + * @param start_date
  243 + * @param end_date
  244 + * @param state
  245 + * @param receive
  246 + * @param video_priority
  247 + * @param orderByClause
  248 + * @param session
  249 + * @param response
  250 + */
  251 + @GetMapping("excel")
  252 + public void getExcel(String video_title, String start_date, String end_date, Integer state, Boolean receive, String video_priority, String orderByClause, HttpSession session, HttpServletResponse response) {
  253 + SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
  254 + Integer spid = sessionUser.getSpid();
  255 + String userId = sessionUser.getUserId();
  256 + if (spid == 0) spid = null;
  257 + List<ShyVideos> shyVideosList = videosService.findByCondition(video_title, start_date, end_date, state, receive, video_priority, orderByClause, spid, userId);
  258 + String fileName = "点播数据";
  259 + String auditor = "";//审核员名字
  260 + String state1 = "";//审核状态 1已审核 2审核拒绝 0未审核
  261 + XSSFWorkbook wb = new XSSFWorkbook();
  262 + ServletOutputStream out = null;
  263 + BufferedInputStream bis = null;
  264 + BufferedOutputStream bos = null;
  265 + try {
  266 + XSSFSheet sheetlist = wb.createSheet(fileName);
  267 + XSSFRow row = sheetlist.createRow(0);//行
  268 + XSSFCell cell = row.createCell(0);//列
  269 + cell.setCellValue("id");
  270 + cell = row.createCell(1);//列
  271 + cell.setCellValue("标题");
  272 + cell = row.createCell(2);//列
  273 + cell.setCellValue("视频地址");
  274 + cell = row.createCell(3);//列
  275 + cell.setCellValue("标题图");
  276 + cell = row.createCell(4);//列
  277 + cell.setCellValue("视频标签");
  278 + cell = row.createCell(5);//列
  279 + cell.setCellValue("审核员");
  280 + cell = row.createCell(6);//列
  281 + cell.setCellValue("审核意见");
  282 + cell = row.createCell(7);//列
  283 + cell.setCellValue("状态");
  284 + cell = row.createCell(8);//列
  285 + cell.setCellValue("视频关键字");
  286 + cell = row.createCell(9);//列
  287 + cell.setCellValue("视频简介");
  288 + cell = row.createCell(10);//列
  289 + cell.setCellValue("视频id");
  290 + cell = row.createCell(11);//列
  291 + cell.setCellValue("创建时间");
  292 + cell = row.createCell(12);//列
  293 + cell.setCellValue("视频上传时间");
  294 + cell = row.createCell(13);//列
  295 + cell.setCellValue("视频时长(秒)");
  296 + cell = row.createCell(14);//列
  297 + cell.setCellValue("spid");
  298 + for (int i = 0; i < shyVideosList.size(); i++) {
  299 + row = sheetlist.createRow((short) (i + 1));//行
  300 + cell = row.createCell(0);//列
  301 + cell.setCellValue(shyVideosList.get(i).getId());
  302 + cell = row.createCell(1);//列
  303 + cell.setCellValue(shyVideosList.get(i).getVideo_title());
  304 + cell = row.createCell(2);//列
  305 + cell.setCellValue(shyVideosList.get(i).getVideo_url());
  306 + cell = row.createCell(3);//列
  307 + cell.setCellValue(shyVideosList.get(i).getVideo_poster());
  308 + cell = row.createCell(4);//列
  309 + cell.setCellValue(shyVideosList.get(i).getVideo_tags());
  310 + cell = row.createCell(5);//列
  311 + /* 审核员需要做处理*/
  312 + if (shyVideosList.get(i).getState() != CommonConst.AUDIT_INTT) {
  313 + auditor = "白名单";
  314 + String auditor_id = shyVideosList.get(i).getAuditor_id();
  315 + if (CommonUtils.isNotEmpty(auditor_id)) {
  316 + ShyUsers user = new ShyUsers();
  317 + user.setUser_id(auditor_id);
  318 + user = usersService.select(user);
  319 + if (CommonUtils.isNotNull(user)) {
  320 + String userName = CommonUtils.isEmpty(user.getUsername()) ? "" : user.getUsername();
  321 + String email = CommonUtils.isEmpty(user.getEmail()) ? "" : user.getEmail();
  322 + auditor = userName + email;
  323 + }
  324 + }
  325 + }
  326 + cell.setCellValue(auditor);
  327 + cell = row.createCell(6);//列
  328 + cell.setCellValue(shyVideosList.get(i).getMsg());
  329 + cell = row.createCell(7);//列
  330 + /*状态需要处理成用户可读*/
  331 + if (shyVideosList.get(i).getState() == 0) {
  332 + state1 = "未审核";
  333 + } else if (shyVideosList.get(i).getState() == 1) {
  334 + state1 = "已审核";
  335 + } else {
  336 + state1 = "审核拒绝";
  337 + }
  338 + cell.setCellValue(state1);
  339 + cell = row.createCell(8);//列
  340 + cell.setCellValue(shyVideosList.get(i).getVideo_keyword());
  341 + cell = row.createCell(9);//列
  342 + cell.setCellValue(shyVideosList.get(i).getVideo_desc());
  343 + cell = row.createCell(10);//列
  344 + cell.setCellValue(shyVideosList.get(i).getVideo_id());
  345 + cell = row.createCell(11);//列
  346 + cell.setCellValue(CommonUtils.formatDate(shyVideosList.get(i).getCreated_at(), "M/d/yyyy HH:mm:SS"));
  347 + cell = row.createCell(12);//列
  348 + cell.setCellValue(CommonUtils.formatDate(shyVideosList.get(i).getVideo_upload_time(), "M/d/yyyy HH:mm:SS"));
  349 + cell = row.createCell(13);//列
  350 + cell.setCellValue(shyVideosList.get(i).getDuration());
  351 + cell = row.createCell(14);//列
  352 + cell.setCellValue(shyVideosList.get(i).getSpid());
  353 + }
  354 +
  355 + ByteArrayOutputStream os = new ByteArrayOutputStream();
  356 + wb.write(os);
  357 + byte[] content = os.toByteArray();
  358 + InputStream is = new ByteArrayInputStream(content);
  359 + response.setContentType("application/vnd.ms-excel;charset=utf-8");
  360 + response.setHeader("Content-Disposition", "attachment;filename=" + new String((fileName + ".xlsx").getBytes(), "iso-8859-1"));
  361 + out = response.getOutputStream();
  362 + bis = new BufferedInputStream(is);
  363 + bos = new BufferedOutputStream(out);
  364 + byte[] buff = new byte[2048];
  365 + int bytesRead;
  366 + while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
  367 + bos.write(buff, 0, bytesRead);
  368 + }
  369 + } catch (final Exception e) {
  370 + e.printStackTrace();
  371 + try {
  372 + if (bis != null)
  373 + bis.close();
  374 + if (bos != null)
  375 + bos.close();
  376 + } catch (Exception e1) {
  377 + e1.printStackTrace();
  378 + }
  379 + } finally {
  380 + try {
  381 + if (bis != null)
  382 + bis.close();
  383 + if (bos != null)
  384 + bos.close();
  385 + } catch (Exception e2) {
  386 + e2.printStackTrace();
  387 + }
  388 + }
  389 + }
230 390 }
... ...
src/main/java/com/cnlive/shenhe/serviceImpl/VideosServiceImpl.java
... ... @@ -173,18 +173,79 @@ public class VideosServiceImpl {
173 173 String[] cids = ids.split(",");
174 174 for (String cid : cids) {
175 175 ShyVideos shyVideos = shyVideosMapper.selectByPrimaryKey(Integer.parseInt(cid));
176   - if (shyVideos.getState() == CommonConst.AUDIT_INTT && shyVideos.getReceive() && shyVideos.getReceive_user_id().equals(userId) ) {
  176 + if (shyVideos.getState() == CommonConst.AUDIT_INTT && shyVideos.getReceive() && shyVideos.getReceive_user_id().equals(userId)) {
177 177 shyVideos.setReceive(CommonConst.RECEIVE_BEFORE);
178 178 shyVideos.setReceive_user_id(null);
179 179 int i = shyVideosMapper.updateByPrimaryKeySelective(shyVideos);
180 180 if (i != 1) {
181   - return new ResponseBean(ErrorEnum.ERROR.getErrorCode(),"退领失败,请重试");
  181 + return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "退领失败,请重试");
182 182 }
183 183 } else {
184   - return new ResponseBean(ErrorEnum.ERROR.getErrorCode(),"退领失败,您选中的内容包含已退领的或已经审核的");
  184 + return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "退领失败,您选中的内容包含已退领的或已经审核的");
185 185 }
186 186 }
187   - return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(),"已退领");
  187 + return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(), "已退领");
  188 + }
  189 +
  190 + /**
  191 + * 根据条件导出数据excel
  192 + *
  193 + * @param video_title
  194 + * @param start_date
  195 + * @param end_date
  196 + * @param state
  197 + * @param receive
  198 + * @param video_priority
  199 + * @param orderByClause
  200 + * @param spid
  201 + * @param userId
  202 + * @return
  203 + */
  204 + public List<ShyVideos> findByCondition(String video_title, String start_date, String end_date, Integer state, Boolean receive, String video_priority, String orderByClause, Integer spid, String userId) {
  205 + Example example = new Example(ShyVideos.class);
  206 + Example.Criteria criteria = example.createCriteria();
  207 + Example.Criteria criteria2 = example.createCriteria();
  208 + if (CommonUtils.isNotEmpty(orderByClause)) {
  209 + example.setOrderByClause(orderByClause);
  210 + }
  211 + if (CommonUtils.isNotEmpty(start_date) && CommonUtils.isNotEmpty(end_date)) {
  212 + Timestamp startdate = null;
  213 + Timestamp enddate = null;
  214 + try {
  215 + startdate = CommonUtils.parseDate(start_date, "yyyy-MM-dd HH:mm:ss");
  216 + enddate = CommonUtils.parseDate(end_date, "yyyy-MM-dd HH:mm:ss");
  217 + } catch (ParseException e) {
  218 + e.printStackTrace();
  219 + }
  220 + criteria.andGreaterThanOrEqualTo("video_upload_time", startdate);
  221 + criteria.andLessThanOrEqualTo("video_upload_time", enddate);
  222 + }
  223 + if (CommonUtils.isNotEmpty(video_title)) {
  224 + criteria.andLike("video_title", "%" + video_title + "%");
  225 + }
  226 + if (CommonUtils.isNotNull(state) && state == 0) {
  227 + criteria.andEqualTo("state", state);
  228 + } else if (CommonUtils.isNotNull(state) && state == 1) {
  229 + criteria.andEqualTo("state", state);
  230 + criteria2.andEqualTo("state", 2);
  231 + example.or(criteria2);
  232 + }
  233 + if (CommonUtils.isNotEmpty(video_priority)) {
  234 + criteria.andEqualTo("video_priority", video_priority);
  235 + }
  236 + if (CommonUtils.isNotNull(spid)) {
  237 + criteria.andEqualTo("spid", spid);
  238 + }
  239 + if (CommonUtils.isNotNull(receive)) {
  240 + criteria.andEqualTo("receive", receive);
  241 + if (receive == true) {
  242 + criteria.andEqualTo("receive_user_id", userId);
  243 + }
  244 + }
  245 + //默认按上传时间倒序排序
  246 + //example.setOrderByClause("video_upload_time desc");
  247 + List<ShyVideos> shyVideosList = shyVideosMapper.selectByExample(example);
  248 + return shyVideosList;
188 249 }
189 250  
190 251  
... ...
src/main/resources/templates/page/video.html
... ... @@ -49,6 +49,10 @@
49 49  
50 50 <div class="btn-group margin-bottom pull-right">
51 51 <button type="button" class="btn btn-sm margin-r-5 filter "
  52 + th:onclick="'javascript:daochu()'" value="" id="excel">
  53 + 导出excel
  54 + </button>
  55 + <button type="button" class="btn btn-sm margin-r-5 filter "
52 56 th:onclick="'javascript:quanbu()'" value="" id="quanbu">
53 57 全部
54 58 </button>
... ... @@ -177,7 +181,8 @@
177 181 <tr data-index="0" th:each="video : ${videoPage.list}">
178 182 <td class="bs-checkbox "><input data-index="0" name="btSelectItem"
179 183 type="checkbox" th:value="${video.id}"></td>
180   - <td style="text-align: center; width: 6%;" th:text="${video.spid_desc}"></td>
  184 + <td style="text-align: center; width: 6%;"
  185 + th:text="${video.spid_desc}"></td>
181 186 <td style="text-align: center; width: 20%;" th:text="${video.video_title}">
182 187 邓建国正面PK冯小刚
183 188 </td>
... ... @@ -203,7 +208,10 @@
203 208 <td style="text-align: center; width: 17%;">
204 209 <a class="detail" th:href="@{'/videos/details/?id='+${video.id}}">
205 210 <!--th:if="${ (video.receive==true and session.sessionUser.userId==video.receive_user_id) or (video.state==1 or video.state==2) }"-->
206   - <button class="btn btn-info btn-sm" th:style="${state1 eq '0' && receive1 eq 'false'} ? 'display: none ' : ' '">查看</button>
  211 + <button class="btn btn-info btn-sm"
  212 + th:style="${state1 eq '0' && receive1 eq 'false'} ? 'display: none ' : ' '">
  213 + 查看
  214 + </button>
207 215 </a>
208 216 <span th:if="${video.state==0 and !video.receive}"> &nbsp;</span>
209 217 <a th:href="@{'javascript:applyReceive('+${video.id}+')'}"
... ... @@ -310,6 +318,12 @@
310 318 }
311 319 }
312 320  
  321 + //导出excel
  322 + function daochu() {
  323 + var param = location.search;
  324 + window.location.href = "/videos/excel" + param;
  325 + }
  326 +
313 327 //全部
314 328 function quanbu() {
315 329 window.location.href = "/videos/page?video_title=&start_date=&end_date=&state=&receive=&video_priority=";
... ...