| | |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.constant.UserOperation; |
| | | import com.whyc.dto.FileDirPath; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.ZipUtils; |
| | | import com.whyc.mapper.ProductSoftwareMapper; |
| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.*; |
| | | import java.net.URLEncoder; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | |
| | | wrapper.orderByAsc("id"); |
| | | List list=mapper.selectList(wrapper); |
| | | PageInfo pageInfo=new PageInfo(list); |
| | | return new Response().setII(1,list.size()>0?true:false,pageInfo,"返回数据"); |
| | | return new Response().setII(1,list.size()>0,pageInfo,"返回数据"); |
| | | } |
| | | //根据软件名称实现软件下载 |
| | | public void downLoadSoftware(HttpServletRequest req, HttpServletResponse resp, String softwareName) { |
| | | String fileDirName = FileDirPath.getFileDirName(); |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("software_name",softwareName); |
| | | wrapper.last("limit 1"); |
| | | ProductSoftware software=mapper.selectOne(wrapper); |
| | | try { |
| | | // 转码防止乱码 |
| | | resp.addHeader("Content-Disposition", "attachment;filename=" |
| | | + new String(softwareName.getBytes("UTF-8"), "ISO8859-1")); |
| | | //resp.addHeader("Content-Disposition", "attachment;filename=" + new String(softwareName.getBytes("UTF-8"), "ISO8859-1")); |
| | | resp.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode ( softwareName, "utf-8")); |
| | | OutputStream out = resp.getOutputStream(); |
| | | FileInputStream in = new FileInputStream(software.getSoftwareUrl()); |
| | | FileInputStream in = new FileInputStream(fileDirName+File.separator+software.getSoftwareUrl()); |
| | | int len=0; |
| | | byte[] buffer =new byte[1024]; |
| | | //7. 将缓冲区中的数据输出 |
| | |
| | | String terminalIp=req.getRemoteAddr(); |
| | | logService.recordOperationLog(docUser.getId(),docUser.getName(), UserOperation.TYPE_DOWNLOAD.getType(),new Date(),terminalIp,opreationMsg,operationDetail); |
| | | } |
| | | |
| | | public void insert(ProductSoftware productSoftware) { |
| | | mapper.insert(productSoftware); |
| | | } |
| | | |
| | | public List<ProductSoftware> getAll() { |
| | | return mapper.selectList(null); |
| | | } |
| | | |
| | | public static void main(String[] args) throws UnsupportedEncodingException { |
| | | String softwareName="散装件.zip"; |
| | | //ISO8859-1 UTF-8 |
| | | System.out.println(new String(softwareName.getBytes("GBK"), "UTF-8")); |
| | | } |
| | | } |