Commit b1f35a168b931af065bbae9dca9e1f9cb44d02f5

Authored by 徐近程
1 parent 866f9c61

音频数据导出excel表

src/main/java/com/cnlive/shenhe/controller/AudioController.java
@@ -14,6 +14,10 @@ import com.cnlive.shenhe.serviceImpl.UsersServiceImpl; @@ -14,6 +14,10 @@ import com.cnlive.shenhe.serviceImpl.UsersServiceImpl;
14 import com.cnlive.shenhe.utils.CommonConst; 14 import com.cnlive.shenhe.utils.CommonConst;
15 import com.cnlive.shenhe.utils.CommonUtils; 15 import com.cnlive.shenhe.utils.CommonUtils;
16 import com.github.pagehelper.PageInfo; 16 import com.github.pagehelper.PageInfo;
  17 +import org.apache.poi.xssf.usermodel.XSSFCell;
  18 +import org.apache.poi.xssf.usermodel.XSSFRow;
  19 +import org.apache.poi.xssf.usermodel.XSSFSheet;
  20 +import org.apache.poi.xssf.usermodel.XSSFWorkbook;
17 import org.slf4j.Logger; 21 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory; 22 import org.slf4j.LoggerFactory;
19 import org.springframework.beans.factory.annotation.Autowired; 23 import org.springframework.beans.factory.annotation.Autowired;
@@ -25,7 +29,10 @@ import org.springframework.web.bind.annotation.PostMapping; @@ -25,7 +29,10 @@ import org.springframework.web.bind.annotation.PostMapping;
25 import org.springframework.web.bind.annotation.RequestMapping; 29 import org.springframework.web.bind.annotation.RequestMapping;
26 import org.springframework.web.bind.annotation.ResponseBody; 30 import org.springframework.web.bind.annotation.ResponseBody;
27 31
  32 +import javax.servlet.ServletOutputStream;
  33 +import javax.servlet.http.HttpServletResponse;
28 import javax.servlet.http.HttpSession; 34 import javax.servlet.http.HttpSession;
  35 +import java.io.*;
29 import java.util.List; 36 import java.util.List;
30 37
31 /** 38 /**
@@ -234,20 +241,182 @@ public class AudioController extends BaseController { @@ -234,20 +241,182 @@ public class AudioController extends BaseController {
234 */ 241 */
235 @GetMapping("/details") 242 @GetMapping("/details")
236 public Object getDetailsVideo(Model model, Integer id) { 243 public Object getDetailsVideo(Model model, Integer id) {
237 - ShyAudio detailsContent = audioService.getDetailsContent(id);  
238 - Object images = JSON.parse(detailsContent.getAudioCoverUrl()); 244 + ShyAudio shyAudio = audioService.getDetailsContent(id);
239 String yuming = ""; 245 String yuming = "";
240 - Integer plat = detailsContent.getBucketType(); 246 + Integer plat = shyAudio.getBucketType();
241 if (plat == CommonConst.QINIU_PLAT) { 247 if (plat == CommonConst.QINIU_PLAT) {
242 yuming = qn_domain + "/"; 248 yuming = qn_domain + "/";
243 } else if (plat == CommonConst.KS_PLAT) { 249 } else if (plat == CommonConst.KS_PLAT) {
244 yuming = ks_domain + "/"; 250 yuming = ks_domain + "/";
245 } 251 }
246 - detailsContent.setAttr_tags(CommonUtils.isEmpty(detailsContent.getAttr_tags())?"":detailsContent.getAttr_tags());  
247 - model.addAttribute("images", images);  
248 - model.addAttribute("audio", detailsContent); 252 + shyAudio.setAttr_tags(CommonUtils.isEmpty(shyAudio.getAttr_tags()) ? "" : shyAudio.getAttr_tags());
  253 + model.addAttribute("audio", shyAudio);
249 model.addAttribute("yuming", yuming); 254 model.addAttribute("yuming", yuming);
250 -  
251 return "page/audioDetail.html"; 255 return "page/audioDetail.html";
252 } 256 }
  257 +
  258 + /**
  259 + * 根据条件导出excel
  260 + *
  261 + * @param video_title
  262 + * @param start_date
  263 + * @param end_date
  264 + * @param state
  265 + * @param receive
  266 + * @param video_priority
  267 + * @param orderByClause
  268 + * @param session
  269 + * @param response
  270 + */
  271 + @GetMapping("excel")
  272 + public void getExcel(String video_title, String start_date, String end_date, Integer state, Integer receive, String video_priority, String orderByClause, HttpSession session, HttpServletResponse response) {
  273 + SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
  274 + Integer spid = sessionUser.getSpid();
  275 + String userId = sessionUser.getUserId();
  276 + if (spid == 0) spid = null;
  277 + List<ShyAudio> shyAudioList = audioService.findByCondition(video_title, start_date, end_date, state, receive, video_priority, orderByClause, spid, userId);
  278 + String fileName = "音频数据";
  279 + String updater = "";//审核员名字
  280 + String state1 = "";//审核状态 1已审核 2审核拒绝 0未审核
  281 + XSSFWorkbook wb = new XSSFWorkbook();
  282 + ServletOutputStream out = null;
  283 + BufferedInputStream bis = null;
  284 + BufferedOutputStream bos = null;
  285 + try {
  286 + XSSFSheet sheetlist = wb.createSheet(fileName);
  287 + XSSFRow row = sheetlist.createRow(0);//行
  288 + XSSFCell cell = row.createCell(0);//列
  289 + cell.setCellValue("id");
  290 + cell = row.createCell(1);//列
  291 + cell.setCellValue("标题");
  292 + cell = row.createCell(2);//列
  293 + cell.setCellValue("音频地址");
  294 + cell = row.createCell(3);//列
  295 + cell.setCellValue("标题图");
  296 + cell = row.createCell(4);//列
  297 + cell.setCellValue("音频标签");
  298 + cell = row.createCell(5);//列
  299 + cell.setCellValue("审核员");
  300 + cell = row.createCell(6);//增加一列
  301 + cell.setCellValue("常用审核意见");
  302 + cell = row.createCell(7);//列
  303 + cell.setCellValue("审核意见");
  304 + cell = row.createCell(8);//列
  305 + cell.setCellValue("状态");
  306 + cell = row.createCell(9);//列
  307 + cell.setCellValue("音频关键字");
  308 + cell = row.createCell(10);//列
  309 + cell.setCellValue("音频简介");
  310 + cell = row.createCell(11);//列
  311 + cell.setCellValue("音频id");
  312 + cell = row.createCell(12);//列
  313 + cell.setCellValue("创建时间");
  314 + cell = row.createCell(13);//列
  315 + cell.setCellValue("音频上传时间");
  316 + cell = row.createCell(14);//列
  317 + cell.setCellValue("音频时长(秒)");
  318 + cell = row.createCell(15);//列
  319 + cell.setCellValue("spid");
  320 + cell = row.createCell(16);//列
  321 + cell.setCellValue("sp简称");
  322 +
  323 + for (int i = 0; i < shyAudioList.size(); i++) {
  324 + row = sheetlist.createRow((short) (i + 1));//行
  325 + cell = row.createCell(0);//列
  326 + cell.setCellValue(shyAudioList.get(i).getId());
  327 + cell = row.createCell(1);//列
  328 + cell.setCellValue(shyAudioList.get(i).getAudioTitle());
  329 + cell = row.createCell(2);//列
  330 + cell.setCellValue(shyAudioList.get(i).getAudioUrl());
  331 + cell = row.createCell(3);//列
  332 + cell.setCellValue(shyAudioList.get(i).getAudioCoverUrl());
  333 + cell = row.createCell(4);//列
  334 + cell.setCellValue(shyAudioList.get(i).getAudioTag());
  335 + cell = row.createCell(5);//列
  336 + //审核员需要做处理
  337 + if (shyAudioList.get(i).getState() != CommonConst.AUDIT_INTT) {
  338 + updater = CommonUtils.isEmpty(shyAudioList.get(i).getUploader()) || "null".equals(shyAudioList.get(i).getUploader())? "白名单":shyAudioList.get(i).getUploader();
  339 + String auditor_id = shyAudioList.get(i).getAuditor_id();
  340 + if (CommonUtils.isNotEmpty(auditor_id)) {
  341 + ShyUsers user = new ShyUsers();
  342 + user.setUser_id(auditor_id);
  343 + user = usersService.select(user);
  344 + if (CommonUtils.isNotNull(user)) {
  345 + String email = CommonUtils.isEmpty(user.getEmail()) || "null".equals(user.getEmail()) ? "" : user.getEmail();
  346 + String userName = CommonUtils.isEmpty(user.getUsername()) ? email : user.getUsername();
  347 + updater = userName ;
  348 + }
  349 + }
  350 + }
  351 + cell.setCellValue(updater);
  352 + cell = row.createCell(6);//列、增加一列
  353 + cell.setCellValue(shyAudioList.get(i).getAttr_tags());
  354 + cell = row.createCell(7);//列
  355 + cell.setCellValue(shyAudioList.get(i).getMsg());
  356 + cell = row.createCell(8);//列
  357 + //状态需要处理成用户可读
  358 + if (shyAudioList.get(i).getState() == 0) {
  359 + state1 = "未审核";
  360 + } else if (shyAudioList.get(i).getState() == 1) {
  361 + state1 = "已审核";
  362 + } else {
  363 + state1 = "审核拒绝";
  364 + }
  365 + cell.setCellValue(state1);
  366 + cell = row.createCell(9);//列
  367 + cell.setCellValue(shyAudioList.get(i).getAudioKeyword());
  368 + cell = row.createCell(10);//列
  369 + cell.setCellValue(shyAudioList.get(i).getAudioIntro());
  370 + cell = row.createCell(11);//列
  371 + cell.setCellValue(shyAudioList.get(i).getAudioId());
  372 + cell = row.createCell(12);//列
  373 + cell.setCellValue(CommonUtils.formatDate(shyAudioList.get(i).getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
  374 + cell = row.createCell(13);//列
  375 + cell.setCellValue(CommonUtils.formatDate(shyAudioList.get(i).getUploadTime(), "yyyy-MM-dd HH:mm:ss"));
  376 + cell = row.createCell(14);//列
  377 + cell.setCellValue(shyAudioList.get(i).getDuration());
  378 + cell = row.createCell(15);//列
  379 + cell.setCellValue(shyAudioList.get(i).getSpId());
  380 + cell = row.createCell(16);//列
  381 +
  382 + //显示spid简称
  383 + ShySites shySites = sitesService.findspidDescByspid(shyAudioList.get(i).getSpId());
  384 + cell.setCellValue(shySites.getName());
  385 + }
  386 +
  387 + ByteArrayOutputStream os = new ByteArrayOutputStream();
  388 + wb.write(os);
  389 + byte[] content = os.toByteArray();
  390 + InputStream is = new ByteArrayInputStream(content);
  391 + response.setContentType("application/vnd.ms-excel;charset=utf-8");
  392 + response.setHeader("Content-Disposition", "attachment;filename=" + new String((fileName + ".xlsx").getBytes(), "iso-8859-1"));
  393 + out = response.getOutputStream();
  394 + bis = new BufferedInputStream(is);
  395 + bos = new BufferedOutputStream(out);
  396 + byte[] buff = new byte[2048];
  397 + int bytesRead;
  398 + while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
  399 + bos.write(buff, 0, bytesRead);
  400 + }
  401 + } catch (final Exception e) {
  402 + e.printStackTrace();
  403 + try {
  404 + if (bis != null)
  405 + bis.close();
  406 + if (bos != null)
  407 + bos.close();
  408 + } catch (Exception e1) {
  409 + e1.printStackTrace();
  410 + }
  411 + } finally {
  412 + try {
  413 + if (bis != null)
  414 + bis.close();
  415 + if (bos != null)
  416 + bos.close();
  417 + } catch (Exception e2) {
  418 + e2.printStackTrace();
  419 + }
  420 + }
  421 + }
253 } 422 }
src/main/java/com/cnlive/shenhe/serviceImpl/AudioServiceImpl.java
@@ -19,6 +19,9 @@ import org.slf4j.LoggerFactory; @@ -19,6 +19,9 @@ import org.slf4j.LoggerFactory;
19 import org.springframework.beans.factory.annotation.Autowired; 19 import org.springframework.beans.factory.annotation.Autowired;
20 import org.springframework.stereotype.Service; 20 import org.springframework.stereotype.Service;
21 import tk.mybatis.mapper.entity.Example; 21 import tk.mybatis.mapper.entity.Example;
  22 +
  23 +import java.sql.Timestamp;
  24 +import java.text.ParseException;
22 import java.util.List; 25 import java.util.List;
23 26
24 /** 27 /**
@@ -239,4 +242,57 @@ public class AudioServiceImpl { @@ -239,4 +242,57 @@ public class AudioServiceImpl {
239 } 242 }
240 return shyAudio; 243 return shyAudio;
241 } 244 }
  245 +
  246 + /**
  247 + * 根据条件导出数据excel
  248 + *
  249 + * @param video_title
  250 + * @param start_date
  251 + * @param end_date
  252 + * @param state
  253 + * @param receive
  254 + * @param video_priority
  255 + * @param orderByClause
  256 + * @param spid
  257 + * @param userId
  258 + * @return
  259 + */
  260 + public List<ShyAudio> findByCondition(String video_title, String start_date, String end_date, Integer state, Integer receive, String video_priority, String orderByClause, Integer spid, String userId) {
  261 + Example example = new Example(ShyAudio.class);
  262 + Example.Criteria criteria = example.createCriteria();
  263 + Example.Criteria criteria2 = example.createCriteria();
  264 + if (CommonUtils.isNotEmpty(orderByClause)) {
  265 + example.setOrderByClause(orderByClause);
  266 + }
  267 + if (CommonUtils.isNotEmpty(start_date) && CommonUtils.isNotEmpty(end_date)) {
  268 + criteria.andGreaterThanOrEqualTo("createTime", start_date);
  269 + criteria.andLessThanOrEqualTo("createTime", end_date);
  270 + }
  271 + if (CommonUtils.isNotEmpty(video_title)) {
  272 + criteria.andLike("audioTitle", "%" + video_title + "%");
  273 + }
  274 + if (CommonUtils.isNotNull(state) && state == 0) {
  275 + criteria.andEqualTo("state", state);
  276 + } else if (CommonUtils.isNotNull(state) && state == 1) {
  277 + criteria.andEqualTo("state", state);
  278 + criteria2.andEqualTo("state", 2);
  279 + example.or(criteria2);
  280 + }
  281 + if (CommonUtils.isNotEmpty(video_priority)) {
  282 + criteria.andEqualTo("priority", video_priority);
  283 + }
  284 + if (CommonUtils.isNotNull(spid)) {
  285 + criteria.andEqualTo("spId", spid);
  286 + }
  287 + if (CommonUtils.isNotNull(receive)) {
  288 + criteria.andEqualTo("receive", receive);
  289 + if (receive == CommonConst.RECEIVE_AFTER) {
  290 + criteria.andEqualTo("receive_user_id", userId);
  291 + }
  292 + }
  293 + //默认按上传时间倒序排序
  294 + //example.setOrderByClause("video_upload_time desc");
  295 + List<ShyAudio> shyAudioList = shyAudioMapper.selectByExample(example);
  296 + return shyAudioList;
  297 + }
242 } 298 }
src/main/resources/templates/page/audioDetail.html
@@ -51,43 +51,12 @@ @@ -51,43 +51,12 @@
51 <div id="tabContents" class="tab-content"> 51 <div id="tabContents" class="tab-content">
52 <div id="tabHome" class="tab-pane fade in active padding-t-15"> 52 <div id="tabHome" class="tab-pane fade in active padding-t-15">
53 <div class="col-sm-5"> 53 <div class="col-sm-5">
54 - <div class="form-group">  
55 - <div>  
56 - <label for="video_cover_img" class="control-label col-sm-4"  
57 - style="margin-left: -3%">封面图:</label>  
58 - </div>  
59 - <div style="height:110px; margin-left: 17%;">  
60 - <div class="col-sm-4 popover-options " th:style="${imgsStat.index==0}? 'float:left;margin-right: 43px;margin-left: -18px;':''" th:if="${imgsStat.index<2}"  
61 - th:each="imgs :${images}">  
62 - <a href="#">  
63 - <img th:src="@{${imgs.value}}" height="100px" alt="封面图">  
64 - </a>  
65 - <b th:text="${imgs.key}"></b>  
66 - </div>  
67 - </div>  
68 - <div style="height: 110px;margin-top: 15px;">  
69 - <label for="" class="control-label col-sm-4"  
70 - style="width: 26.3%;"></label>  
71 - <div class="col-sm-4 popover-options " th:style="${imgsStat.index==2}?'float:left;margin-right: 15px;':'float:left;'"  
72 - th:if="${imgsStat.index>=2&&imgsStat.index<4}"  
73 - th:each="imgs :${images}">  
74 - <a href="#">  
75 - <img th:src="@{${imgs.value}}" height="100px" alt="封面图">  
76 - </a>  
77 - <b th:text="${imgs.key}"></b>  
78 - </div>  
79 - </div>  
80 - <div style="height: 110px;margin-top: 15px;">  
81 - <label for="" class="control-label col-sm-4"  
82 - style="width: 26.3%;"></label>  
83 - <div class="col-sm-4 popover-options" th:style="${imgsStat.index==4}?'float:left;margin-right: 15px;':'float:left;'"  
84 - th:if="${imgsStat.index>=4}"  
85 - th:each="imgs :${images}">  
86 - <a href="#">  
87 - <img th:src="@{${imgs.value}}" height="100px" alt="封面图">  
88 - </a>  
89 - <b th:text="${imgs.key}"></b>  
90 - </div> 54 + <div class="form-group" style="margin-bottom: 6px;">
  55 + <label for="audioCoverUrl" class="control-label col-sm-4">封面图:</label>
  56 + <div class="col-sm-8">
  57 + <a href="#">
  58 + <img th:src="@{${audio.audioCoverUrl}}" height="50%" width="50%" alt="封面图">
  59 + </a>
91 </div> 60 </div>
92 </div> 61 </div>
93 <div class="form-group" style="margin-bottom: 6px;"> 62 <div class="form-group" style="margin-bottom: 6px;">
@@ -134,7 +103,7 @@ @@ -134,7 +103,7 @@
134 "model": 3, 103 "model": 3,
135 "autoplay": 1, 104 "autoplay": 1,
136 "currRate": 3, 105 "currRate": 3,
137 - "cover": "http://wjjtest.ys2.cnliveimg.com/802/img/2020/0608/ff80808171053574017292e3053d77a3/000001.jpg", 106 + "cover": "http://sxzg.ys1.cnliveimg.com/82/img/2018/0426/82_20180426164129.png",
138 "videoUrl_3": audioUrl 107 "videoUrl_3": audioUrl
139 }); 108 });
140 </script> 109 </script>