Commit 18c2ff27 by Java-金吉宝

重复记录

parent 1d43b2c7
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ejweb.modules.contact.dao.SoundRecordingDao">
<select id="findList" resultType="com.ejweb.modules.contact.entity.SoundRecordingEntity">
SELECT CONCAT(ac.create_name,ap.username,(UNIX_TIMESTAMP(ac.end_time)-ac.duration)) as b,
create_phone AS callNo,ac.create_name AS callName,ap.phone AS acceptNo,ap.username AS acceptName,
ac.start_time AS beginTime, ac.end_time AS endTime, ac.download_url ,ac.duration,end_status AS result
FROM foc_sound_records ac
LEFT JOIN foc_sound_phones ap ON ac.id=ap.record_id
<where>
ac.end_status !='INIT'
<if test="seatList.size() > 0">
and (ac.create_by in
<foreach item="item" collection="seatList" separator="," open="(" close=")" index="">
#{item.id}
</foreach>
or
ap.user_id in
<foreach item="item" collection="seatList" separator="," open="(" close=")" index="">
#{item.id}
</foreach>
)
</if>
<if test="callNo != null and callNo != ''">
AND ac.create_phone LIKE
<if test="dbName == 'oracle'">'%'||#{callNo}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{callNo}+'%'</if>
<if test="dbName == 'mysql'">CONCAT('%', #{callNo}, '%')</if>
</if>
<if test="callName != null and callName != ''">
AND ac.create_name LIKE
<if test="dbName == 'oracle'">'%'||#{callName}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{callName}+'%'</if>
<if test="dbName == 'mysql'">CONCAT('%', #{callName}, '%')</if>
</if>
<if test="acceptNo != null and acceptNo != ''">
AND ap.phone LIKE
<if test="dbName == 'oracle'">'%'||#{acceptNo}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{acceptNo}+'%'</if>
<if test="dbName == 'mysql'">CONCAT('%', #{acceptNo}, '%')</if>
</if>
<if test="acceptName != null and acceptName != ''">
AND ap.username LIKE
<if test="dbName == 'oracle'">'%'||#{acceptName}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{acceptName}+'%'</if>
<if test="dbName == 'mysql'">CONCAT('%', #{acceptName}, '%')</if>
</if>
<if test="beginTime != null and beginTime != ''">
AND (ac.start_time BETWEEN #{beginTime} AND #{endTime})
<!-- AND ac.start_time <![CDATA[>]]> #{beginTime} -->
</if>
<if test="endTime != null and endTime != ''">
AND ( ac.end_time <![CDATA[<]]> #{endTime} OR ac.end_time is NULL)
</if>
</where>
group by b
ORDER BY ac.start_time desc
</select>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ejweb.modules.contact.dao.SoundRecordingDao">
<!-- <select id="findList" resultType="com.ejweb.modules.contact.entity.SoundRecordingEntity">
select *
from (
SELECT CONCAT(ac.create_name,ap.username,(UNIX_TIMESTAMP(ac.end_time)-ac.duration)) as b,
create_phone AS callNo,ac.create_name AS callName,ap.phone AS acceptNo,ap.username AS acceptName,
ac.start_time AS beginTime, ac.end_time AS endTime, ac.download_url ,ac.duration,end_status AS result
FROM foc_sound_records ac
LEFT JOIN foc_sound_phones ap ON ac.id=ap.record_id
where
ac.end_status !='INIT'
<if test="seatList.size() > 0">
and (ac.create_by in
<foreach item="item" collection="seatList" separator="," open="(" close=")" index="">
#{item.id}
</foreach>
or
ap.user_id in
<foreach item="item" collection="seatList" separator="," open="(" close=")" index="">
#{item.id}
</foreach>
)
</if>
<if test="callNo != null and callNo != ''">
AND ac.create_phone LIKE
<if test="dbName == 'oracle'">'%'||#{callNo}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{callNo}+'%'</if>
<if test="dbName == 'mysql'">CONCAT('%', #{callNo}, '%')</if>
</if>
<if test="callName != null and callName != ''">
AND ac.create_name LIKE
<if test="dbName == 'oracle'">'%'||#{callName}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{callName}+'%'</if>
<if test="dbName == 'mysql'">CONCAT('%', #{callName}, '%')</if>
</if>
<if test="acceptNo != null and acceptNo != ''">
AND ap.phone LIKE
<if test="dbName == 'oracle'">'%'||#{acceptNo}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{acceptNo}+'%'</if>
<if test="dbName == 'mysql'">CONCAT('%', #{acceptNo}, '%')</if>
</if>
<if test='acceptName != null and acceptName != ""'>
AND ap.username LIKE
<if test="dbName == 'oracle'">'%'||#{acceptName}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{acceptName}+'%'</if>
<if test="dbName == 'mysql'">CONCAT('%', #{acceptName}, '%')</if>
</if>
<if test='beginTime != null and beginTime != ""'>
AND ac.start_time <![CDATA[<=]]>#{endTime} and ac.start_time <![CDATA[>=]]> #{beginTime}
AND ac.start_time <![CDATA[>]]> #{beginTime}
</if>
<if test='endTime != null and endTime != ""'>
AND ( ac.end_time <![CDATA[<]]> #{endTime} OR ac.end_time is NULL)
</if>
GROUP BY b
) er
ORDER BY beginTime DESC
</select> -->
<select id="findList" resultType="com.ejweb.modules.contact.entity.SoundRecordingEntity">
SELECT
create_phone AS callNo,ac.create_name AS callName,ap.phone AS acceptNo,ap.username AS acceptName,
ac.start_time AS beginTime, ac.end_time AS endTime, ac.download_url ,ac.duration,end_status AS result
FROM foc_sound_records ac
LEFT JOIN foc_sound_phones ap ON ac.id=ap.record_id
where
ac.end_status !='INIT'
<if test="seatList.size() > 0">
and (ac.create_by in
<foreach item="item" collection="seatList" separator="," open="(" close=")" index="">
#{item.id}
</foreach>
or
ap.user_id in
<foreach item="item" collection="seatList" separator="," open="(" close=")" index="">
#{item.id}
</foreach>
)
</if>
<if test="callNo != null and callNo != ''">
AND ac.create_phone LIKE
<if test="dbName == 'oracle'">'%'||#{callNo}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{callNo}+'%'</if>
<if test="dbName == 'mysql'">CONCAT('%', #{callNo}, '%')</if>
</if>
<if test="callName != null and callName != ''">
AND ac.create_name LIKE
<if test="dbName == 'oracle'">'%'||#{callName}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{callName}+'%'</if>
<if test="dbName == 'mysql'">CONCAT('%', #{callName}, '%')</if>
</if>
<if test="acceptNo != null and acceptNo != ''">
AND ap.phone LIKE
<if test="dbName == 'oracle'">'%'||#{acceptNo}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{acceptNo}+'%'</if>
<if test="dbName == 'mysql'">CONCAT('%', #{acceptNo}, '%')</if>
</if>
<if test='acceptName != null and acceptName != ""'>
AND ap.username LIKE
<if test="dbName == 'oracle'">'%'||#{acceptName}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{acceptName}+'%'</if>
<if test="dbName == 'mysql'">CONCAT('%', #{acceptName}, '%')</if>
</if>
<if test='beginTime != null and beginTime != ""'>
AND ac.start_time <![CDATA[<=]]>#{endTime} and ac.start_time <![CDATA[>=]]> #{beginTime}
AND ac.start_time <![CDATA[>]]> #{beginTime}
</if>
<if test='endTime != null and endTime != ""'>
AND ( ac.end_time <![CDATA[<]]> #{endTime} OR ac.end_time is NULL)
</if>
ORDER BY beginTime DESC
</select>
<select id="findRecordingList" resultType="com.ejweb.modules.contact.entity.SoundRecordingEntity">
SELECT
create_phone AS callNo,ac.create_name AS callName,ap.phone AS acceptNo,ap.username AS acceptName,
ac.start_time AS beginTime, ac.end_time AS endTime, ac.download_url ,ac.duration,end_status AS result
FROM foc_sound_records ac
LEFT JOIN foc_sound_phones ap ON ac.id=ap.record_id
where
ac.end_status !='INIT'
and ac.create_name=#{callName}
and ap.username=#{acceptName}
and ac.start_time=#{endTime}
</select>
</mapper>
\ No newline at end of file
package com.ejweb.modules.contact.dao;
import com.ejweb.core.persistence.CrudDao;
import com.ejweb.core.persistence.annotation.MyBatisDao;
import com.ejweb.modules.contact.entity.SoundRecordingEntity;
@MyBatisDao
public interface SoundRecordingDao extends CrudDao<SoundRecordingEntity> {
}
package com.ejweb.modules.contact.dao;
import java.util.List;
import com.ejweb.core.persistence.CrudDao;
import com.ejweb.core.persistence.annotation.MyBatisDao;
import com.ejweb.modules.contact.entity.SoundRecordingEntity;
@MyBatisDao
public interface SoundRecordingDao extends CrudDao<SoundRecordingEntity> {
List<SoundRecordingEntity> findRecordingList(SoundRecordingEntity entityTmp);
}
package com.ejweb.modules.contact.service;
import com.alibaba.fastjson.JSON;
import com.ejweb.core.fetcher.HttpClientUtil;
import com.ejweb.core.persistence.Page;
import com.ejweb.core.service.CrudService;
import com.ejweb.core.utils.StringUtils;
import com.ejweb.modules.contact.dao.SoundRecordingDao;
import com.ejweb.modules.contact.entity.SoundRecordingEntity;
import com.ejweb.modules.contact.entity.SoundRecordingResponseEntity;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 聊天记录Service
* @author lyw
*
*/
@Service
public class SoundRecordingService extends CrudService<SoundRecordingDao, SoundRecordingEntity> {
@Value("${foc.sound.records.url}")
private String soundRecordingUrl;
public Page<SoundRecordingEntity> getPage(Page<SoundRecordingEntity> page,SoundRecordingEntity soundRecordingEntity) {
soundRecordingEntity.setPage(page);
String url = soundRecordingUrl;
Map<String, String> params = new HashMap<>();
params.put("pageNo", String.valueOf(soundRecordingEntity.getPage().getPageNo()));
params.put("pageSize", String.valueOf(soundRecordingEntity.getPage().getPageSize()));
if (StringUtils.isNotBlank(soundRecordingEntity.getBeginTime())) {
params.put("beginTime", soundRecordingEntity.getBeginTime());
}
if (StringUtils.isNotBlank(soundRecordingEntity.getEndTime())) {
params.put("endTime", soundRecordingEntity.getEndTime());
}
if (StringUtils.isNotBlank(soundRecordingEntity.getCallName())) {
params.put("callUserName", soundRecordingEntity.getCallName());
}
if (StringUtils.isNotBlank(soundRecordingEntity.getAcceptName())) {
params.put("acceptUserName", soundRecordingEntity.getAcceptName());
}
if (StringUtils.isNotBlank(soundRecordingEntity.getCallUserNo())) {
params.put("callUserNo", soundRecordingEntity.getCallUserNo());
}
if (StringUtils.isNotBlank(soundRecordingEntity.getAcceptUserNo())) {
params.put("acceptUserNo", soundRecordingEntity.getAcceptUserNo());
}
String res = HttpClientUtil.doPost(url, params, "UTF-8");
HashMap returnResult = JSON.parseObject(res, HashMap.class);
// Page<SoundRecordingEntity> pageReturnResult = new Page<>();
if ("2000".equals(returnResult.get("status"))) {
SoundRecordingResponseEntity responseEntity = JSON.parseObject(returnResult.get("data").toString(), SoundRecordingResponseEntity.class);
if (responseEntity != null) {
page.setCount(responseEntity.getCount());
page.setList(responseEntity.getList());
page.setPageNo(responseEntity.getPageNo());
page.setPageSize(responseEntity.getPageSize());
}
}
System.out.print(res);
return page;
}
}
package com.ejweb.modules.contact.service;
import com.alibaba.fastjson.JSON;
import com.ejweb.core.fetcher.HttpClientUtil;
import com.ejweb.core.persistence.Page;
import com.ejweb.core.service.CrudService;
import com.ejweb.core.utils.StringUtils;
import com.ejweb.modules.contact.dao.SoundRecordingDao;
import com.ejweb.modules.contact.entity.SoundRecordingEntity;
import com.ejweb.modules.contact.entity.SoundRecordingResponseEntity;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 聊天记录Service
* @author lyw
*
*/
@Service
public class SoundRecordingService extends CrudService<SoundRecordingDao, SoundRecordingEntity> {
@Value("${foc.sound.records.url}")
private String soundRecordingUrl;
public Page<SoundRecordingEntity> getPage(Page<SoundRecordingEntity> page,SoundRecordingEntity soundRecordingEntity) {
soundRecordingEntity.setPage(page);
String url = soundRecordingUrl;
Map<String, String> params = new HashMap<>();
params.put("pageNo", String.valueOf(soundRecordingEntity.getPage().getPageNo()));
params.put("pageSize", String.valueOf(soundRecordingEntity.getPage().getPageSize()));
if (StringUtils.isNotBlank(soundRecordingEntity.getBeginTime())) {
params.put("beginTime", soundRecordingEntity.getBeginTime());
}
if (StringUtils.isNotBlank(soundRecordingEntity.getEndTime())) {
params.put("endTime", soundRecordingEntity.getEndTime());
}
if (StringUtils.isNotBlank(soundRecordingEntity.getCallName())) {
params.put("callUserName", soundRecordingEntity.getCallName());
}
if (StringUtils.isNotBlank(soundRecordingEntity.getAcceptName())) {
params.put("acceptUserName", soundRecordingEntity.getAcceptName());
}
if (StringUtils.isNotBlank(soundRecordingEntity.getCallUserNo())) {
params.put("callUserNo", soundRecordingEntity.getCallUserNo());
}
if (StringUtils.isNotBlank(soundRecordingEntity.getAcceptUserNo())) {
params.put("acceptUserNo", soundRecordingEntity.getAcceptUserNo());
}
String res = HttpClientUtil.doPost(url, params, "UTF-8");
HashMap returnResult = JSON.parseObject(res, HashMap.class);
// Page<SoundRecordingEntity> pageReturnResult = new Page<>();
if ("2000".equals(returnResult.get("status"))) {
SoundRecordingResponseEntity responseEntity = JSON.parseObject(returnResult.get("data").toString(), SoundRecordingResponseEntity.class);
if (responseEntity != null) {
page.setCount(responseEntity.getCount());
page.setList(responseEntity.getList());
page.setPageNo(responseEntity.getPageNo());
page.setPageSize(responseEntity.getPageSize());
}
}
System.out.print(res);
return page;
}
public List<SoundRecordingEntity> findRecordingList(SoundRecordingEntity entityTmp) {
// TODO Auto-generated method stub
return dao.findRecordingList(entityTmp);
}
}
package com.ejweb.modules.contact.web;
import com.ejweb.core.base.BaseController;
import com.ejweb.core.conf.GConstants;
import com.ejweb.core.persistence.Page;
import com.ejweb.modules.contact.entity.SeatEntity;
import com.ejweb.modules.contact.entity.SoundRecordingEntity;
import com.ejweb.modules.contact.service.SoundRecordingService;
import com.ejweb.modules.contact.service.UserProfileServce;
import com.ejweb.modules.sys.entity.Role;
import com.ejweb.modules.sys.entity.User;
import com.ejweb.modules.sys.utils.UserUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
import java.util.List;
/**
* 录音管理Controller
* @author lyw
*
*/
@Controller
@RequestMapping(value = "${adminPath}/contact/soundRecording/")
public class SoundRecordingController extends BaseController {
@Autowired
private SoundRecordingService soundRecordingService;
@Autowired
private UserProfileServce userProfileService;
@RequiresPermissions("im:soundRecording:view")
@RequestMapping(value = "list")
public String list(Model model, HttpServletRequest request, HttpServletResponse response, SoundRecordingEntity soundRecordingEntity) {
Page<SoundRecordingEntity> page = soundRecordingService.getPage(new Page<SoundRecordingEntity>(request, response), soundRecordingEntity);
if (page != null && !CollectionUtils.isEmpty(page.getList())) {
String proxy = GConstants.getValue("foc.sound.records.proxy", "https://ifos.jdair.net/sounds/");
for (SoundRecordingEntity entityTmp : page.getList()) {
if (StringUtils.isNotBlank(entityTmp.getDownloadUrl())) {
entityTmp.setDownloadUrl(entityTmp.getDownloadUrl().replaceAll(".{4,5}://.*?(/|\\\\)", proxy).replaceAll("\\\\", "/"));
}
}
}
model.addAttribute("page", page);
return "modules/contact/soundRecordingList";
}
@RequiresPermissions("im:soundRecording:view")
@RequestMapping(value = "newList")
public String newList(Model model, HttpServletRequest request, HttpServletResponse response, SoundRecordingEntity soundRecordingEntity) {
//Page<SoundRecordingEntity> page = soundRecordingService.getPage(new Page<SoundRecordingEntity>(request, response), soundRecordingEntity);
User user = UserUtils.getUser();
List<SeatEntity> list = userProfileService.getSeatList(user.getId());//查询录音权限
if(StringUtils.isEmpty(soundRecordingEntity.getBeginTime())){
Date current = new Date();
Date startTime = new Date(current.getTime()-36*60*60*1000);
soundRecordingEntity.setBeginTime(DateFormatUtils.format(startTime, "yyyy-MM-dd HH:mm:ss"));
soundRecordingEntity.setEndTime(DateFormatUtils.format(current, "yyyy-MM-dd 23:59:59"));
}
soundRecordingEntity.setSeatList(list);
Page<SoundRecordingEntity> page =soundRecordingService.findPage(new Page<SoundRecordingEntity>(request, response),soundRecordingEntity);
if (page != null && !CollectionUtils.isEmpty(page.getList())) {
String proxy = GConstants.getValue("foc.sound.records.proxy", "https://ifos.jdair.net/sounds/");
if(StringUtils.isNoneBlank(proxy)){
proxy="https://ifos.jdair.net/sounds/";
}
for (SoundRecordingEntity entityTmp : page.getList()) {
if (StringUtils.isNotBlank(entityTmp.getDownloadUrl())) {
entityTmp.setDownloadUrl(entityTmp.getDownloadUrl().replaceAll(".{4,5}://.*?(/|\\\\)", proxy).replaceAll("\\\\", "/"));
}
}
}
model.addAttribute("page", page);
return "modules/contact/soundRecordingList";
}
@RequiresPermissions("im:soundRecording:view")
@RequestMapping(value = "download")
public void download(HttpServletRequest request, HttpServletResponse response, SoundRecordingEntity soundRecordingEntity, RedirectAttributes redirectAttributes) {
if (soundRecordingEntity == null || StringUtils.isBlank(soundRecordingEntity.getDownloadUrl())) {
addMessage(redirectAttributes, "下载路径有问题");
return;
}
soundRecordingEntity.setDownloadUrl(soundRecordingEntity.getDownloadUrl().replaceAll("\\\\", "/"));
ServletOutputStream outputStream = null;
InputStream inputStream = null;
HttpURLConnection urlCon = null;
try {
String fileName = soundRecordingEntity.getDownloadUrl().substring(soundRecordingEntity.getDownloadUrl().lastIndexOf("/") + 1, soundRecordingEntity.getDownloadUrl().length());
response.setHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("gbk"), "ISO8859-1"));
outputStream = response.getOutputStream();
URL url = new URL(soundRecordingEntity.getDownloadUrl());
urlCon = (HttpURLConnection)url.openConnection();
urlCon.setConnectTimeout(30000);
urlCon.setReadTimeout(30000); //最多连接30秒
inputStream = urlCon.getInputStream();
byte []bytes = new byte[1024];
int len = 0;
while ((len = inputStream.read(bytes, 0, bytes.length)) != -1) {
outputStream.write(bytes, 0, len);
outputStream.flush();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (urlCon != null) {urlCon.disconnect();}
try {
if (inputStream != null) {inputStream.close();}
if (outputStream != null) {outputStream.close();}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
package com.ejweb.modules.contact.web;
import com.ejweb.core.base.BaseController;
import com.ejweb.core.conf.GConstants;
import com.ejweb.core.persistence.Page;
import com.ejweb.modules.contact.entity.SeatEntity;
import com.ejweb.modules.contact.entity.SoundRecordingEntity;
import com.ejweb.modules.contact.service.SoundRecordingService;
import com.ejweb.modules.contact.service.UserProfileServce;
import com.ejweb.modules.sys.entity.Role;
import com.ejweb.modules.sys.entity.User;
import com.ejweb.modules.sys.utils.UserUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* 录音管理Controller
* @author lyw
*
*/
@Controller
@RequestMapping(value = "${adminPath}/contact/soundRecording/")
public class SoundRecordingController extends BaseController {
@Autowired
private SoundRecordingService soundRecordingService;
@Autowired
private UserProfileServce userProfileService;
@RequiresPermissions("im:soundRecording:view")
@RequestMapping(value = "list")
public String list(Model model, HttpServletRequest request, HttpServletResponse response, SoundRecordingEntity soundRecordingEntity) {
Page<SoundRecordingEntity> page = soundRecordingService.getPage(new Page<SoundRecordingEntity>(request, response), soundRecordingEntity);
if (page != null && !CollectionUtils.isEmpty(page.getList())) {
String proxy = GConstants.getValue("foc.sound.records.proxy", "https://ifos.jdair.net/sounds/");
for (SoundRecordingEntity entityTmp : page.getList()) {
if (StringUtils.isNotBlank(entityTmp.getDownloadUrl())) {
entityTmp.setDownloadUrl(entityTmp.getDownloadUrl().replaceAll(".{4,5}://.*?(/|\\\\)", proxy).replaceAll("\\\\", "/"));
}
}
}
model.addAttribute("page", page);
return "modules/contact/soundRecordingList";
}
@RequiresPermissions("im:soundRecording:view")
@RequestMapping(value = "newList")
public String newList(Model model, HttpServletRequest request, HttpServletResponse response, SoundRecordingEntity soundRecordingEntity) {
//Page<SoundRecordingEntity> page = soundRecordingService.getPage(new Page<SoundRecordingEntity>(request, response), soundRecordingEntity);
User user = UserUtils.getUser();
List<SeatEntity> list = userProfileService.getSeatList(user.getId());//查询录音权限
if(StringUtils.isEmpty(soundRecordingEntity.getBeginTime())){
Date current = new Date();
Date startTime = new Date(current.getTime()-36*60*60*1000);
soundRecordingEntity.setBeginTime(DateFormatUtils.format(startTime, "yyyy-MM-dd HH:mm:ss"));
soundRecordingEntity.setEndTime(DateFormatUtils.format(current, "yyyy-MM-dd 23:59:59"));
}
soundRecordingEntity.setSeatList(list);
Page<SoundRecordingEntity> page =soundRecordingService.findPage(new Page<SoundRecordingEntity>(request, response),soundRecordingEntity);
if (page != null && !CollectionUtils.isEmpty(page.getList())) {
String proxy = GConstants.getValue("foc.sound.records.proxy", "https://ifos.jdair.net/sounds/");
if(StringUtils.isNoneBlank(proxy)){
proxy="https://ifos.jdair.net/sounds/";
}
List<SoundRecordingEntity> templist = new ArrayList<SoundRecordingEntity>();
for (SoundRecordingEntity entityTmp : page.getList()) {
if (StringUtils.isNotBlank(entityTmp.getDownloadUrl())) {
entityTmp.setDownloadUrl(entityTmp.getDownloadUrl().replaceAll(".{4,5}://.*?(/|\\\\)", proxy).replaceAll("\\\\", "/"));
}
List<SoundRecordingEntity> entity = soundRecordingService.findRecordingList(entityTmp);
if(entity.size()>0){
templist.add(entityTmp);
}
}
if(templist.size()>0){
page.getList().removeAll(templist);
}
}
model.addAttribute("page", page);
return "modules/contact/soundRecordingList";
}
@RequiresPermissions("im:soundRecording:view")
@RequestMapping(value = "download")
public void download(HttpServletRequest request, HttpServletResponse response, SoundRecordingEntity soundRecordingEntity, RedirectAttributes redirectAttributes) {
if (soundRecordingEntity == null || StringUtils.isBlank(soundRecordingEntity.getDownloadUrl())) {
addMessage(redirectAttributes, "下载路径有问题");
return;
}
soundRecordingEntity.setDownloadUrl(soundRecordingEntity.getDownloadUrl().replaceAll("\\\\", "/"));
ServletOutputStream outputStream = null;
InputStream inputStream = null;
HttpURLConnection urlCon = null;
try {
String fileName = soundRecordingEntity.getDownloadUrl().substring(soundRecordingEntity.getDownloadUrl().lastIndexOf("/") + 1, soundRecordingEntity.getDownloadUrl().length());
response.setHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("gbk"), "ISO8859-1"));
outputStream = response.getOutputStream();
URL url = new URL(soundRecordingEntity.getDownloadUrl());
urlCon = (HttpURLConnection)url.openConnection();
urlCon.setConnectTimeout(30000);
urlCon.setReadTimeout(30000); //最多连接30秒
inputStream = urlCon.getInputStream();
byte []bytes = new byte[1024];
int len = 0;
while ((len = inputStream.read(bytes, 0, bytes.length)) != -1) {
outputStream.write(bytes, 0, len);
outputStream.flush();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (urlCon != null) {urlCon.disconnect();}
try {
if (inputStream != null) {inputStream.close();}
if (outputStream != null) {outputStream.close();}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment