中扬CRM客户关系管理系统
LSH
2023-07-29 b67aab4c69b0c2619a334e7ae110becd97cec4bf
src/main/java/com/zy/crm/manager/controller/PriOnlineController.java
@@ -18,8 +18,13 @@
import com.zy.crm.common.web.BaseController;
import com.zy.crm.manager.service.PriService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.ClassUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -181,16 +186,73 @@
    @RequestMapping(value = "/priOnline/uploadCheck/auth")
    @ManagerAuth
    public R uploadCheck(@RequestBody Map<String,Object> map){
        PriOnline priOnline = priOnlineService.selectById(Long.parseLong(map.get("id").toString()));
    public R uploadCheck(@RequestParam("id") Integer id,
                         @RequestParam("checkData") String checkData,
                         @RequestParam("file") MultipartFile[] files){
        PriOnline priOnline = priOnlineService.selectById(id);
        if (priOnline.getStatus() == 1) {
            return R.error("核价已完成,禁止上传");
        }
        priOnline.setCheckData(map.get("checkData").toString());
        priOnline.setCheckData(checkData);
        MultipartFile file = files[0];
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd_HHmmss");
        String path =  ClassUtils.getDefaultClassLoader().getResource("excel/uploadCheckData").getPath();
        //文件后缀名
        String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
        //上传文件名
        String filename = format.format(new Date()) + suffix;
        //最终文件路径
        String filepath = path + "/" + filename;
        //服务器端保存的文件对象
        File serverFile = new File(filepath);
        if(!serverFile.exists()) {
            try {
                //创建文件
                serverFile.createNewFile();
                //将上传的文件写入到服务器端文件内
                file.transferTo(serverFile);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        //保存文件名
        priOnline.setCheckDataFile(filename);
        priOnlineService.updateById(priOnline);
        return R.ok();
    }
    @GetMapping("/priOnline/checkDataDownload/{filename}")
    public void download(@PathVariable String filename, HttpServletResponse response) {
        try {
            ClassPathResource pathResource = new ClassPathResource("excel/uploadCheckData/" + filename);
            File file = pathResource.getFile();
            InputStream inputStream = pathResource.getInputStream();
            //输出文件
            InputStream fis = new BufferedInputStream(inputStream);
            byte[] buffer = new byte[fis.available()];
            fis.read(buffer);
            fis.close();
            response.reset();
            //获取文件的名字再浏览器下载页面
            String name = file.getName();
            response.addHeader("Content-Disposition", "attachment;filename=" + new String(name.getBytes(), "iso-8859-1"));
            response.addHeader("Content-Length", "" + file.length());
            OutputStream out = new BufferedOutputStream(response.getOutputStream());
            response.setContentType("application/octet-stream");
            out.write(buffer);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @RequestMapping(value = "/priOnline/delete/auth")
    @ManagerAuth
    public R delete(Long[] ids){