中扬CRM客户关系管理系统
LSH
2023-08-21 3787470f3a3195a71fefb7b64b19f67f9b4b6b31
#报销申请
6个文件已修改
191 ■■■■ 已修改文件
src/main/java/com/zy/crm/manager/controller/PlanController.java 64 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/crm/manager/mapper/PlanMapper.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/crm/manager/service/PlanService.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/crm/manager/service/impl/PlanServiceImpl.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/PlanMapper.xml 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/plan/plan.js 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/crm/manager/controller/PlanController.java
@@ -14,6 +14,7 @@
import com.core.exception.CoolException;
import com.zy.crm.common.entity.RouteCollectCountType;
import com.zy.crm.common.model.SettleDto;
import com.zy.crm.common.service.OssService;
import com.zy.crm.common.utils.FileSaveExampleUtil;
import com.zy.crm.common.utils.SetOfUtils;
import com.zy.crm.common.web.BaseController;
@@ -61,6 +62,8 @@
    private PlanTypeService planTypeService;
    @Autowired
    private DeptService deptService;
    @Autowired
    private OssService ossService;
    @GetMapping(value = "/plan/{id}/auth")
    @ManagerAuth
@@ -220,16 +223,39 @@
    @RequestMapping(value = "/plan/insert/file/auth")
//    @ManagerAuth
    public R insertFile(@RequestParam("planId") String planId,@RequestParam MultipartFile file){
        String[] split = planId.split("-");
        int id = Integer.parseInt(split[1]);
        System.out.println("---开始---");
        String savePath = "D:/crm/plan/file/"+id+"/"; // 指定保存文件的路径
        try{
            FileSaveExampleUtil.saveFile(file, savePath);
            InputStream inputStream = file.getInputStream();
            String suffix = getFileSuffix(file.getOriginalFilename());
//            String url = ossService.upload(inputStream, suffix);
            String url = "http://tjdt.oss-cn-hangzhou.aliyuncs.com/"+file.getOriginalFilename();
            String[] names = url.split("com/");
            String name= names[1];
            String[] split = planId.split("-");
            int id = Integer.parseInt(split[1]);
            planService.increasePlanUrl(id,url,name,file.getSize());
            /*String[] split = planId.split("-");
            int id = Integer.parseInt(split[1]);
            System.out.println("---开始---");
            String savePath = "D:/crm/plan/file/"+id+"/"; // 指定保存文件的路径
            try{
                FileSaveExampleUtil.saveFile(file, savePath);
            }catch (Exception e){
                return R.error();
            }*/
            return R.ok();
        }catch (Exception e){
            System.out.println(e);
            return R.error();
        }
        return R.ok();
    }
    private String getFileSuffix(String filename) {
        int dotIndex = filename.lastIndexOf(".");
        if (dotIndex > 0 && dotIndex < filename.length() - 1) {
            return filename.substring(dotIndex + 1);
        }
        return "";
    }
    @RequestMapping(value = "/plan/delete/file/auth")
@@ -252,9 +278,18 @@
//    @ManagerAuth
    public R viewFile(@RequestParam("planId") String planId){
        int id = Integer.parseInt(planId);
        String savePath = "D:/crm/plan/file/"+id+"/"; // 指定保存文件的路径
//        String savePath = "D:/crm/plan/file/"+id+"/"; // 指定保存文件的路径
        try{
            List<FileSaveExampleUtil.FileDTO> fileDTOS = FileSaveExampleUtil.viewFileList(savePath);
            List<Integer> ids = planService.selectPlanUrlId(id);
            List<FileSaveExampleUtil.FileDTO> fileDTOS = new ArrayList<>();
            for (int id2 : ids){
                String url = planService.selectPlanUrlPlanIdUrl(id2);
                String name = planService.selectPlanUrlPlanIdName(id2);
                Long size = planService.selectPlanUrlPlanIdSize(id2);
                FileSaveExampleUtil.FileDTO dto = new FileSaveExampleUtil.FileDTO(name,size,url);
                fileDTOS.add(dto);
            }
//            List<FileSaveExampleUtil.FileDTO> fileDTOS = FileSaveExampleUtil.viewFileList(savePath);
            return R.ok(fileDTOS);
        }catch (Exception e){
            return R.error();
@@ -263,14 +298,17 @@
    @RequestMapping(value = "/plan/download/file/auth")
//    @ManagerAuth
    public R downloadFile(@RequestParam("downloadUrl") String downloadUrl,HttpServletResponse response){
        System.out.println("---开始---");
    public void downloadFile(@RequestParam("downloadUrl") String downloadUrl,HttpServletResponse response){
//        System.out.println("---开始---");
//        MultipartFile
        try{
            ResponseEntity<Resource> resourceResponseEntity = FileSaveExampleUtil.downloadFile(downloadUrl, response);
            return R.ok(resourceResponseEntity);
            String[] names = downloadUrl.split("com/");
            String name= names[1];
//            ResponseEntity<Resource> resourceResponseEntity = FileSaveExampleUtil.downloadFile(downloadUrl, response);
//            return R.ok(resourceResponseEntity);
            ossService.download(name);
        }catch (Exception e){
            return R.error();
        }
    }
src/main/java/com/zy/crm/manager/mapper/PlanMapper.java
@@ -15,6 +15,13 @@
    Plan selectByUuid(@Param("hostId") Long hostId, @Param("uuid") String uuid);
    void increasePlanUrl(@Param("planId") int planId, @Param("url") String url, @Param("name") String name, @Param("size") Long size);
    String selectPlanUrlPlanIdUrl(@Param("id") int id);
    String selectPlanUrlPlanIdName(@Param("id") int id);
    Long selectPlanUrlPlanIdSize(@Param("id") int id);
    List<Integer> selectPlanUrlId(@Param("planId") int planId);
    Plan selectPlanByNewestUuid(@Param("hostId") Long hostId);
    List<Plan> listByPage(Page<Plan> page, @Param("hostId")Long hostId, @Param("deptId") String deptId, @Param("userId") Long userId , @Param("condition") String condition);
src/main/java/com/zy/crm/manager/service/PlanService.java
@@ -4,9 +4,16 @@
import com.baomidou.mybatisplus.service.IService;
import com.zy.crm.manager.entity.Plan;
import java.util.List;
public interface PlanService extends IService<Plan> {
    Plan selectByUuid(Long hostId, String uuid);
    void increasePlanUrl(int planId, String url,String name,Long size);
    String selectPlanUrlPlanIdUrl(int planId);
    String selectPlanUrlPlanIdName(int planId);
    Long selectPlanUrlPlanIdSize(int planId);
    List<Integer> selectPlanUrlId(int planId);
    String getUuid(Long hostId);
src/main/java/com/zy/crm/manager/service/impl/PlanServiceImpl.java
@@ -6,7 +6,10 @@
import com.zy.crm.manager.entity.Plan;
import com.zy.crm.manager.mapper.PlanMapper;
import com.zy.crm.manager.service.PlanService;
import io.swagger.models.License;
import org.springframework.stereotype.Service;
import java.util.List;
@Service("planService")
public class PlanServiceImpl extends ServiceImpl<PlanMapper, Plan> implements PlanService {
@@ -17,6 +20,32 @@
    }
    @Override
    public void increasePlanUrl(int planId, String url,String name,Long size) {
        this.baseMapper.increasePlanUrl(planId, url,name,size);
    }
    @Override
    public List<Integer> selectPlanUrlId(int planId) {
        return this.baseMapper.selectPlanUrlId(planId);
    }
    @Override
    public String selectPlanUrlPlanIdUrl(int id) {
        return this.baseMapper.selectPlanUrlPlanIdUrl(id);
    }
    @Override
    public String selectPlanUrlPlanIdName(int id) {
        return this.baseMapper.selectPlanUrlPlanIdName(id);
    }
    @Override
    public Long selectPlanUrlPlanIdSize(int id) {
        return this.baseMapper.selectPlanUrlPlanIdSize(id);
    }
    @Override
    public String getUuid(Long hostId) {
        String uuid = null;
        int times = 0;
src/main/resources/mapper/PlanMapper.xml
@@ -107,4 +107,34 @@
        ORDER BY mp.create_time DESC
    </select>
    <select id="selectPlanUrlPlanIdUrl" resultType="java.lang.String">
        select url from man_plan_url
        where 1=1
        and id=#{id}
    </select>
    <select id="selectPlanUrlPlanIdName" resultType="java.lang.String">
        select name from man_plan_url
        where 1=1
        and id=#{id}
    </select>
    <select id="selectPlanUrlPlanIdSize" resultType="java.lang.Long">
        select file_size from man_plan_url
        where 1=1
        and id=#{id}
    </select>
    <select id="selectPlanUrlId" resultType="java.lang.Integer">
        select id from man_plan_url
        where 1=1
        and plan_id=#{planId}
    </select>
    <insert id="increasePlanUrl">
        insert into man_plan_url(plan_id,url,name,file_size)
        values(#{planId},#{url},#{name},#{size})
    </insert>
</mapper>
src/main/webapp/static/js/plan/plan.js
@@ -588,30 +588,40 @@
    $('#data-btn-file3').on('click', 'a', function() {
        // var downloadUrl = $(this).attr('href');
        // console.log(downloadUrl)
        // console.log(baseUrl)
        // window.open("/\//"+downloadUrl);
        // return false;
        // // console.log(baseUrl)
        // // window.open("/\//"+downloadUrl);
        // // return false;
        // // var downloadUrl = $(this).attr('href');
        // // console.log(downloadUrl)
        // // // 发起 AJAX 请求,获取文件
        // $.ajax({
        //     url: '/plan/download/file/auth',
        //     type: 'POST',
        //     data: { downloadUrl: downloadUrl },  // 传递下载链接作为参数
        //     success: function(response) {
        //         // console.log(response)
        // //         // window.open(baseUrl+response.msg)
        // //         // 创建一个Blob对象
        // //         var blob = new Blob([response]);
        // //         // 使用FileSaver保存文件
        // //         var fileName = downloadUrl.substring(downloadUrl.lastIndexOf('\\') + 1);
        // //         console.log(fileName)
        // //         saveAs(blob, fileName);
        //         return false;
        //     },
        //     error: function() {
        //         layer.msg('请求文件下载失败');
        //     }
        // });
        var downloadUrl = $(this).attr('href');
        console.log(downloadUrl)
        // 发起 AJAX 请求,获取文件
        $.ajax({
            url: '/plan/download/file/auth',
            type: 'POST',
            data: { downloadUrl: downloadUrl },  // 传递下载链接作为参数
            success: function(response) {
                console.log(response)
                // window.open(baseUrl+response.msg)
                // 创建一个Blob对象
                var blob = new Blob([response]);
                // 使用FileSaver保存文件
                var fileName = downloadUrl.substring(downloadUrl.lastIndexOf('\\') + 1);
                console.log(fileName)
                saveAs(blob, fileName);
            },
            error: function() {
                layer.msg('请求文件下载失败');
            }
        });
        if (downloadUrl == "" || downloadUrl == null) {
            layer.msg('请先上传app文件',{time:1000},() => {
                parent.location.reload()
            })
        }else{
            window.open(downloadUrl);
        }
        return false;  // 阻止默认的链接跳转行为
    });