PDF合同生成下载预览

     调用freemaker配置类
    @Autowired
    private FreeMarkerConfigurer freeMarkerConfigurer;

   生成合同同时提交

 @RequestMapping("saveHt")
    public ResponseResult saveHt(@RequestBody Map<String,Object> map) throws Exception {

        //防止重复提交

        //生成合同
        Map<String, String> saveht = htongService.saveht(map);

        ResponseResult responseResult = ResponseResult.getResponseResult().setCode(ResultStatus.AUTH_SUCCESS.getCode())
                .setMsg(ResultStatus.AUTH_SUCCESS.getMsg()).setResult(saveht);

        return responseResult;

    }+

service层进行判断

  @Transactional(rollbackFor = Exception.class,timeout = 20000)
    public Map<String, String> saveht(Map<String,Object> htMap) throws Exception {

        //合同编号
        String htcode = sequenceUtilsDao.getSequence(1);
        htMap.put("htcode",htcode);

        //上传minio
        String fileName=htMap.get("title").toString()+".pdf";
        Map<String, String> map = PdfUtils.uploadToMonio(fileName, minioClient, "images2", freeMarkerConfigurer, "hetong.html", htMap);
        map.put("htcode",htcode);

        //存数据库
        htMap.put("fileName",fileName);
        htMap.put("filePath",map.get("filePath"));
        htongDao.insertIntoHt(htMap);

        return map;
    }

  

 @Autowired
    private HtongDao htongDao;

    @RequestMapping("xiazai/{htcode}")
    public void yulan(@PathVariable("htcode") String htcode, HttpServletResponse response) throws Exception {

        Map<String, String> map = htongDao.gethtInfo(htcode);

        PdfUtils.xizai(minioClient,map.get("filePath"),map.get("fileName"),"images2",response);

    }
   合同模板

<template>
   <div style="width: 50%;margin-left: 50px">

     <el-form :inline="false" :model="formData1" class="demo-form-inline">
       <el-form-item label="合同名称">
         <el-input v-model="formData1.title" placeholder="合同名称"></el-input>
       </el-form-item>
       <el-form-item label="合同内容">
         <el-input type="textarea" :rows="10"  placeholder="合同内容" v-model="formData1.content"></el-input>
       </el-form-item>
       <el-form-item label="甲方代表">
         <el-input v-model="formData1.jiafang" placeholder="甲方代表"></el-input>
       </el-form-item>
       <el-form-item label="乙方代表">
         <el-input v-model="formData1.yifang" placeholder="乙方代表"></el-input>
       </el-form-item>
       <el-form-item label="日期">
         <el-date-picker v-model="formData1.riqi" format="yyyy-MM-dd HH:mm:ss"
                         value-format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择签署日期时间"></el-date-picker>
       </el-form-item>
       <el-form-item>
         <el-button type="primary" @click="saveHt">提交生成合同</el-button>
       </el-form-item>
     </el-form>

     <el-link type="primary"  :href="myhref" v-show="isshow">预览合同</el-link>
     <el-button type="primary" @click="xiazaiht"  v-show="isshow">下载合同</el-button>

   </div>
</template>

<script>
    export default {
        name: "hetong",
        data(){
           return{
             isshow:false,
             myhref:"",
             htcode:"",
             xiazai:this.$myInfo.loginPath+'xiazai'+"?htcode="+this.htcode,
             formData1:{
                 title:"",
               content:"",
               jiafang:"",
               yifang:"",
               riqi:""
             }
           }
        },
        methods:{
          //预览合同
          xiazaiht(){
            window.location.href=this.$myInfo.loginPath+"xiazai/"+this.htcode;
          },
          //保存合同
          saveHt(){

            const loading = this.$loading({ lock: true,text: '数据提交中,请等待!!',spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)'});
            this.$axios.post(this.$myInfo.loginPath+"saveHt",this.formData1).then((response)=>{
                 let  pdfminiopath=response.data.result.filePath;
                 this.htcode=response.data.result.htcode;
                 this.isshow=true;
                 this.myhref=pdfminiopath;
                 alert(this.htcode);
                 loading.close();
                 //提示一下成功
                 this.$message({type:"success",message:"保存成功"})
            })
          }
        }
    }
</script>

如果添加新的.vue页面需要添加子级路由

{ path: '/hetong',name: 'hetong',component: hetong,meta:{require:true} }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值