Commit 40077fd1 authored by liuchao's avatar liuchao

no message

parent 621b2551
package com.qiankun.controller;
import java.io.File;
import java.util.Date;
import java.util.ResourceBundle;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import com.qiankun.controller.base.BaseController;
......@@ -41,17 +46,51 @@ public class CertificateController extends BaseController<Object>{
if(StringUtils.isNotBlank(id)) {
certificate = certificateService.findById(id);
}
view.setViewName("activity/saveactivity");
view.setViewName("certificate/save");
view.getModel().put("certificate", certificate);
return view;
}
@RequestMapping(value = "/api/certificate/save", method = RequestMethod.POST)
public ModelAndView save(@RequestParam(value = "file", required = false) MultipartFile file, Certificate certificate, HttpServletResponse response, HttpServletRequest request) throws Exception {
@RequestMapping("/api/certificate/save")
public void save(String id, String name, HttpServletResponse response, HttpServletRequest request) throws Exception {
Certificate certificate = new Certificate();
ModelAndView view = new ModelAndView();
if (StringUtils.isEmpty(certificate.getId())) {
view.getModel().put("status", 1);
} else {
String id = certificate.getId();
String name = certificate.getName();
String position = certificate.getPosition();
String uploadImage = certificate.getUploadImage();
Boolean status = certificate.getStatus();
certificate = certificateService.findById(id);
certificate.setName(name);
certificate.setPosition(position);
certificate.setUploadImage(uploadImage);
certificate.setStatus(status);
view.getModel().put("status", 2);
}
if (file != null) {
String fileFullName = file.getOriginalFilename();
String[] originalFileName = fileFullName.split("\\.");
String fileName = System.currentTimeMillis() + "." + originalFileName[originalFileName.length-1];
String rootPath = rb.getString("file_path");
if (StringUtils.isNotBlank(certificate.getUploadImage())) {
File oldFile = new File(rootPath + certificate.getUploadImage());
if (oldFile.isFile())
FileUtils.forceDelete(oldFile);
}
certificateService.save(certificate);
File destFile = new File(rootPath + certificateImagePath,fileName);
FileUtils.writeByteArrayToFile(destFile,file.getBytes());
certificate.setUploadImage(certificateImagePath + File.separator + fileName);
}
Certificate entity = certificateService.save(certificate);
view.getModel().put("entity", entity);
return view;
}
@RequestMapping("/api/certificate/del")
......
......@@ -29,6 +29,8 @@ public class Certificate {
private String uploadImage;//证书照片路径
private Boolean status = false; //true 启用 false 停用
public String getId() {
return id;
......@@ -63,6 +65,14 @@ public class Certificate {
this.position = position;
}
public Boolean getStatus() {
return status;
}
public void setStatus(Boolean status) {
this.status = status;
}
......
......@@ -226,14 +226,14 @@
</li>
<li>
<a href="#" class="dropdown-toggle">
<a href="<webpath:path/>/certificate/list" class="dropdown-toggle">
<i class="icon-book"></i>
<span class="menu-text"> 电子证书 </span>
<span class="menu-text"> 证书管理 </span>
<b class="arrow icon-angle-down"></b>
<!-- <b class="arrow icon-angle-down"></b> -->
</a>
<ul class="submenu">
<!-- <ul class="submenu">
<li>
<a href="tables.html">
<i class="icon-double-angle-right"></i>
......@@ -247,7 +247,7 @@
证书管理
</a>
</li>
</ul>
</ul> -->
</li>
<li>
......
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="webpath" uri="/WEB-INF/tlds/path.tld"%>
<%@ taglib prefix="webpage" uri="/WEB-INF/tlds/pageview.tld"%>
<head>
</head>
<div class="main-content">
<div class="breadcrumbs" id="breadcrumbs">
<ul class="breadcrumb">
<li>
<i class="icon-home home-icon"></i>
<a href="#">首页</a>
</li>
<li class="active">证书管理</li>
</ul><!-- .breadcrumb -->
</div>
<div class="page-content">
<div class="row">
<div class="col-xs-12">
<div class="widget-toolbox">
<div class="btn-group">
<button class="btn btn-sm btn-success" onclick="window.location.href='<webpath:path/>/certificate/add'">
<i class="icon-plus-sign-alt bigger-110"></i>
新增
</button>
<!-- button class="btn btn-sm btn-success">
<i class="icon-ban-circle bigger-110"></i>
禁用
</button-->
</div>
<div class="pull-right">
</div>
</div>
<div class="pull-left"></div>
<table id="table-data" class="table table-bordered ">
<thead>
<tr class="">
<!-- <th class="center">
<label>
<input type="checkbox" class="ace">
<span class="lbl"></span>
</label>
</th> -->
<th width="">证书照片</th>
<th width="15%">证书名称</th>
<th width="8%">位置坐标</th>
<th width="8%" class="">状态</th>
<th width="100">操作</th>
</tr>
</thead>
<tbody>
<c:forEach var="list" items="${list}">
<tr class="tr-highlight">
<!-- <td class="center" width=10>
<label>
<input type="checkbox" class="ace">
<span class="lbl"></span>
</label>
</td> -->
<td title=""><img id="uploadImage" src="<webpath:path/>/wx/rainbowplan/loadResource?imageName=${list.uploadImage}" height="100"/></td>
<td title="">${list.name}</td>
<td title="">${list.position}</td>
<td title="">${list.status}</td>
<td>
<div class="visible-md visible-lg hidden-sm hidden-xs btn-group">
<button class="btn btn-xs btn-info" onclick="window.location.href='<webpath:path/>/certificate/add?id=${list.id}'">
<i class="icon-edit"></i>
</button>
&nbsp;
<c:if test="${!list.status}">
<button class="btn btn-xs btn-danger " onclick="certificate.remove('${list.id}')">
<i class="icon-trash"></i>
</button>
</c:if>
</div>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script src="<webpath:path/>/resources/js/certificate/certificate.js" type="text/javascript"></script>
\ No newline at end of file
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="webpath" uri="/WEB-INF/tlds/path.tld"%>
<%@ taglib prefix="webpage" uri="/WEB-INF/tlds/pageview.tld"%>
<head>
</head>
<div class="main-content">
<div class="breadcrumbs" id="breadcrumbs">
<ul class="breadcrumb">
<li>
<i class="icon-home home-icon"></i>
<a href="#">首页</a>
</li>
<li class="active">证书管理</li>
<li class="active">保存</li>
</ul><!-- .breadcrumb -->
</div>
<div class="page-content">
<div class="row">
<div class="col-xs-12">
<form action="#" id="certificateForm" name="certificateForm" method="post" onsubmit="return false" class="form-horizontal" role="form">
<input type="hidden" id="id" name="id" value="${certificate.id}"/>
<input type="hidden" id="uploadImage" name="uploadImage" value="${certificate.uploadImage}"/>
<div class="row">
<div class="col-xs-5">
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> <font color="red">*</font> 证书名称 </label>
<div class="col-sm-9">
<input type="text" id="name" name="name" class="col-xs-10 col-sm-10" value="${certificate.name}"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for="form-input-readonly"> 状态 </label>
<div class="col-sm-9">
<select name="status" id="status" class="col-xs-10 col-sm-10">
<option value="true" <c:if test="${certificate.status==true}">selected</c:if>>启用</option>
<option value="false" <c:if test="${certificate.status==false}">selected</c:if>>停用</option>
</select>
</div>
</div>
<c:if test="${certificate.id!=null}">
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> <font color="red">*</font> 位置坐标 </label>
<div class="col-sm-9">
<textarea rows="4" class="col-xs-10 col-sm-10" id="position" name="position">${certificate.position}</textarea>
</div>
</div>
</c:if>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for="form-field-1">图片</label>
<div class="col-sm-9">
<input type="file" id="input_file" name="file" >
</div>
</div>
<div class="col-md-offset-3 col-md-9">
<button class="btn btn-sm btn-success" type="submit">
<i class="icon-save bigger-110"></i>
保存
</button>
&nbsp; &nbsp; &nbsp;
<a class="btn btn-sm btn-success" href="javascript:history.go(-1)">
<i class="icon-reply bigger-110"></i>
返回
</a>
</div>
</div>
<div class="col-xs-7">
<c:if test="${certificate.uploadImage!=null}">
<a href="javascript:;" onclick="certificate.editpic()"><img id="pic" src="<webpath:path/>/wx/rainbowplan/loadResource?imageName=${certificate.uploadImage}" width="300"/></a><br></c:if>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script src="<webpath:path/>/resources/js/certificate/certificate.js" type="text/javascript"></script>
\ No newline at end of file
var isSubmit = true;
$(document).ready(function(){
if ($('#certificateForm').length>0){
$('#certificateForm').validate({
rules : {
"name" : {
required : true
}
},
messages:{
"name" : {
required : "不能为空"
}
},
submitHandler: function(form){
certificate.save(form);
}
});
}
})
var certificate = {
remove : function(id){
bootbox.confirm({
buttons: {
cancel: {
label: '取消',
className: 'btn-default'
},
confirm: {
label: '确认',
className: 'btn-myStyle'
}
},
message: '请确认是否删除?',
callback: function(result) {
if(result) {
$.ajax({
type: 'GET',
url: webPath + '/api/certificate/del?id='+id,
dataType:'json',
success: function(data){
window.location.reload();
}
})
} else {
}
}
});
},
save : function(form){
if (isSubmit){
isSubmit = false;
var formData = new FormData();
formData.append('file', $('#input_file')[0].files[0]);
formData.append('id', $('#id').val());
formData.append('name', $('#name').val());
formData.append('status', $('#status').val());
formData.append('uploadImage', $('#uploadImage').val());
if (typeof($('#position').val()) != "undefined" ){
formData.append('position', $('#position').val());
}
$.ajax({
url: webPath + '/api/certificate/save',
type: 'POST',
cache: false,
data: formData,
processData: false,
contentType: false,
dataType:"json",
beforeSend: function(){
},
success: function(data){
var status=data.status;
var entity = data.certificate;
if(status==1){//成功
bootbox.dialog({
message:"上传证书成功",
buttons:{
"success":{
"label":"下一步",
"className":"btn-sm btn-primary",
"callback": function () {
window.location.href = webPath + '/certificate/add?id=' + entity.id;
}
}
}
});
} else if (status == 2){
isSubmit = true;
bootbox.dialog({
message:"修改成功",
buttons:{
"success":{
"label":"确定",
"className":"btn-sm btn-primary",
"callback": function () {
window.location.reload();
}
}
}
});
}
}
});
}
},
editpic : function() {
var jsonstr = [];
if ($("#position").val() != ""){
jsonstr = JSON.parse($("#position").val());
}
window.c = imageLabel({
img: $("#pic").attr("src"),
editPop: true,
data:jsonstr,
close: function(t) {
return true;
},
clickArea: function() {},
edit: function(t) {},
startArea: function() {},
confirm: function(t) {
//alert(JSON.stringify(t))
if ( t != null ){
$("#position").val(JSON.stringify(t));
}
//return t.length && alert(JSON.stringify(t)), true
return true;
}
})
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment