whyclxw
2025-02-27 5636f3f0e6005cc30dca08ce33f5e6f1e7cd457f
src/main/java/com/whyc/service/SoftcodeService.java
@@ -37,7 +37,7 @@
    //源码上传
    public Response uploadCode(MultipartFile file, String fileNames) throws IOException {
        String[] nameList=fileNames.split(",");
        String fileName = file.getOriginalFilename();
        String codeName = file.getOriginalFilename();
        Date date = new Date();
        String dateUnion = DateUtil.YYYY_MM_DD_HH_MM_SS_UNION.format(date);
        //存储路径
@@ -48,13 +48,15 @@
        if(!softwareDirFile.exists()){
            softwareDirFile.mkdirs();
        }
        String codeUrl=softcodeDir+File.separator+fileName;
        String codeUrl=softcodeDir+File.separator+codeName;
        file.transferTo(new File(codeUrl));
        if(nameList.length>0){
            for(String name:nameList){
                Softcode softcode=new Softcode();
                softcode.setFileName(name);
                softcode.setCodeUrl(softcodeHttpUrl+File.separator+fileName);
                softcode.setCreateTime(new Date());
                softcode.setCodeUrl(softcodeHttpUrl+File.separator+codeName);
                softcode.setCodeName(codeName.substring(0,codeName.lastIndexOf(".")));
                //判断是否存在源码,存在修改,不存在添加
                if(mapper.selectOne(new QueryWrapper<Softcode>().eq("file_name",name))!=null){
                    mapper.update(softcode,new UpdateWrapper<Softcode>().eq("file_name",name));
@@ -75,11 +77,11 @@
        wrapper.last("limit 1");
        Softcode softcode=mapper.selectOne(wrapper);
        String filename=softcode.getCodeUrl().substring(softcode.getCodeUrl().lastIndexOf("\\")+1);
        String name=softcode.getCodeUrl().substring(softcode.getCodeUrl().lastIndexOf("\\")+1);
        try {
            // 转码防止乱码
            //resp.addHeader("Content-Disposition", "attachment;filename=" + new String(softwareName.getBytes("UTF-8"), "ISO8859-1"));
            resp.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode (filename, "utf-8"));
            resp.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode (name, "utf-8"));
            OutputStream out = resp.getOutputStream();
            FileInputStream in = new FileInputStream(fileDirName+ File.separator+softcode.getCodeUrl());
            int len=0;
@@ -97,6 +99,6 @@
        }
        //记录日志
        logService.recordOperationLogDownLoad(ActionUtil.getUser().getId(),ActionUtil.getUser().getName(), UserOperation.TYPE_DOWNLOAD_SOFWARE.getType(),new Date(),req.getRemoteAddr()
                ,filename,fileDirName+File.separator+softcode.getCodeUrl(),"",fileName,"");
                ,name,fileDirName+File.separator+softcode.getCodeUrl(),"",name,"");
    }
}