Package site.action.ecom.mejtao.personalinfo;
Import Java.awt.image.BufferedImage;
Import Java.io.ByteArrayInputStream;
Import Java.io.ByteArrayOutputStream;
Import Java.io.File;
Import Java.io.FileInputStream;
Import java.io.IOException;
Import Java.util.HashMap;
Import Java.util.Map;
Import Javax.imageio.ImageIO;
Import Javax.imageio.stream.ImageOutputStream;
Import org.apache.struts2.convention.annotation.Action;
Import Org.apache.struts2.convention.annotation.Namespace;
Import Org.apache.struts2.convention.annotation.ParentPackage;
Import Org.apache.struts2.convention.annotation.Result;
Import org.springframework.beans.factory.annotation.Autowired;
Import Rop.thirdparty.com.alibaba.fastjson.JSON;
Import site.base.action.FrontendBaseAction;
Import Site.base.businessbean.FileBean;
Import Site.base.pojo.FrontUser;
Import Site.base.service.BaseService;
Import Site.common.PropertyUtil;
Import site.common.constant.Constants;
Import Site.service.ecom.customer.CustomerService;
Import Site.vo.ecom.customer.CustomerBizBean;
@ParentPackage ("Base_for_front_json")
@Namespace ("/personalinfo")
public class Personalinfoaction extends frontendbaseaction{
Private static final long serialversionuid = 1L;
@Autowired
Private CustomerService CustomerService;
Private String realname;
Private String identify;
Private Long Supplierheadid;
Private Long customerId;
File
private File files;
Private File Files2;
File originally
Private String Filesfilename;
Private String Files2filename;
Private Bytearrayinputstream InputStream;
Private String flag;
Private String Showflag;
/**
* Save, update identity information
* @return
*/
@Action (value= "Updateinfo")
Public String UpdateInfo () {
Boolean single=false;
Frontuser user= Super.getcurrentfrontuser ();
Customerbizbean Custombean = Customerservice.getcustomerbyid (User.getid ());//
Custombean.setcustomerheadname (Realname);
Custombean.setcustomerheadidno (identify);
try{
Customerservice.execute (custombean,baseservice.command_update);
Single=true;
}catch (Exception e) {
E.printstacktrace ();
}
Getresultmap (). put ("result", single);
return Res_json;
}
/**
* Upload ID
*/
@Action (value= "Personinfo")
public void PersonInfo () {
Frontuser user= Super.getcurrentfrontuser ();
map<string,object> map = new hashmap<string, object> ();
Customerbizbean Custombean = Customerservice.getcustomerbyid (User.getid ());//
Boolean fileflag = false;
String filePath = null;
String fileName = null;
Get upload file type
String Uploadfiletype=propertyutil.getpropertyvaluebykey (constants.commmon_pic_type,request);
Get upload file size
String Uploadfilesize=propertyutil.getpropertyvaluebykey (constants.supp_filesize,request);
Get the Upload file path
String Myuploaddir;
Myuploaddir=getuploadrootdirforservice ();
Setfileallowedtypes (Uploadfiletype);
Store by date
File Dirfile = new file (myuploaddir+ "/identity");
if (! ( Dirfile.exists ()) &&! (Dirfile.isdirectory ())) {
Boolean Creadok = Dirfile.mkdirs ();
if (Creadok) {
myuploaddir=myuploaddir+ "/identity";
}
}else{
myuploaddir=myuploaddir+ "/identity";
}
SetUploadDir1 (Myuploaddir);
Setfilemaxsize (long.valueof (uploadfilesize));
String newfilename= "";
if ("Front". Equals (flag)) {
Newfilename=custombean.getcustomerheadloginno () + "_front" +
Filesfilename.substring (Filesfilename.indexof ("."), Filesfilename.length ());
}else if ("Back". Equals (flag)) {
Newfilename=custombean.getcustomerheadloginno () + "_back" +
Files2filename.substring (Files2filename.indexof ("."), Files2filename.length ());
}
Upload
try {
if (Files! = NULL | | Files2!=null) {
Filebean filebean1=new Filebean ();
if ("Front". Equals (flag)) {
Filebean1=super.uploadfile (Files,filesfilename, NewFileName);
}else if ("Back". Equals (flag)) {
Filebean1=super.uploadfile (Files2,files2filename, NewFileName);
}
Supplierheadbean.setsupplierfeefile (Filebean1.getnewname ());
FilePath = Myuploaddir;
FileName = Filebean1.getnewname ();
Fileflag = true;
if ("Front". Equals (flag)) {
Custombean.setcustomeridnofront (myuploaddir+ "/" +newfilename);
}else if ("Back". Equals (flag)) {
Custombean.setcustomeridnoback (myuploaddir+ "/" +newfilename);
}
Customerservice.execute (custombean,baseservice.command_update);
}
} catch (Exception e) {
Log.error ("Picture upload failed!") ");
This.addfielderror ("Upload", "Upload picture Failed!") ");
}
Map.put ("FilePath", FilePath);
Map.put ("filename", filename);
Map.put ("Fileflag", Fileflag);
try {
Response.getwriter (). Write (json.tojsonstring (map));
Response.getwriter (). Flush ();
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
/**
* Download ID Card
* @return
* @throws Exception
*/
@Action (value = "Downpic", results= {@Result (name=success,type= "stream", params={"ContentType", "Image/jpeg", " InputName "," InputStream "})})
Public String Downpic () throws Exception {
Setinputstream (Createinputstream ());
return SUCCESS;
}
Write the picture in bytes to InputStream.
Public Bytearrayinputstream Createinputstream () throws Exception {
Frontuser user= Super.getcurrentfrontuser ();
Customerbizbean Custombean = Customerservice.getcustomerbyid (User.getid ());
String imgpath= "";
if ("Front". Equals (Showflag)) {
Imgpath = Custombean.getcustomeridnofront ();
}else if ("Back". Equals (Showflag)) {
Imgpath = Custombean.getcustomeridnoback ();
}
BufferedImage image = Imageio.read (new FileInputStream (Imgpath));
Bytearrayoutputstream output = new Bytearrayoutputstream ();
Imageoutputstream imageout = imageio.createimageoutputstream (output);
Imageio.write (Image, "JPEG", imageout);
Imageout.close ();
Bytearrayinputstream input = new Bytearrayinputstream (Output.tobytearray ());
Output.close ();
return input;
}
Public Long Getsupplierheadid () {
return supplierheadid;
}
public void Setsupplierheadid (Long supplierheadid) {
This.supplierheadid = Supplierheadid;
}
Public Long Getcustomerid () {
return customerId;
}
public void Setcustomerid (Long customerId) {
This.customerid = customerId;
}
public void Setfiles (File files) {
This.files = files;
}
public void Setfilesfilename (String filesfilename) {
This.filesfilename = Filesfilename;
}
Public Bytearrayinputstream getInputStream () {
return inputstream;
}
public void Setinputstream (Bytearrayinputstream inputstream) {
This.inputstream = InputStream;
}
Public String Getrealname () {
return realname;
}
public void Setrealname (String realname) {
This.realname = Realname;
}
Public String getidentify () {
return identify;
}
public void Setidentify (String identify) {
This.identify = identify;
}
Public String Getflag () {
return flag;
}
public void Setflag (String flag) {
This.flag = Flag;
}
Public File GetFiles2 () {
return files2;
}
public void SetFiles2 (File files2) {
This.files2 = Files2;
}
Public String Getfiles2filename () {
return files2filename;
}
public void Setfiles2filename (String files2filename) {
This.files2filename = Files2filename;
}
Public String Getshowflag () {
return showflag;
}
public void Setshowflag (String showflag) {
This.showflag = Showflag;
}
}
Define (function (Require, exports, module) {
var $base = require (' pageinit ');//introduction of Basic JS with scrolling page
var $ = $base. query;//Gets the jquery global variable for the module
Require (' Jquery/jquery.ajaxfileupload ') ($);
$ (document). Ready (function () {
Download ()
Returnurl=getquerystring ("ReturnUrl");
});
});
Return
var ReturnUrl;
function GoBack () {
if (returnurl== "") {
Returnurl= "/html/persona/my.html";
}
Returnurl= "/http" +window.location.hostname+ ":" +window.location.port+returnurl;
Window.location.hostname+ ":" +window.location.port "http://localhost:8080"
Window.location.href=returnurl;
}
var falg;
var file;
function Uploadfront () {
if ($ (' #files '). val () = = "") {
Alert ("Please select a picture");
Return
}
Flag= "front";
file= "Files";
Upload ();
}
function Uploadback () {
if ($ (' #files2 '). val () = = "") {
Alert ("Please select a picture");
Return
}
Flag= "Back";
File= "Files2";
Upload ();
}
Upload image
function upload () {
$.ajaxfileupload ({url: '/personalinfo/personinfo.do?flag= ' +flag,
Secureuri:false,
Fileelementid:file,
Async:false,
DataType: ' JSON ',
Success:function (data,status) {
Alert ("Upload success");
Download ();
},
Error:function (data, status, E) {
Alert ("Upload failed");
}
});
}
Download image
function Download () {
var Imgfront=document.getelementbyid ("Idimage");
Imgfront.src= "/personalinfo/downpic.do?showflag=front";
var Imgback=document.getelementbyid ("Idimage2");
Imgback.src= "/personalinfo/downpic.do?showflag=back"
}
Save personal Information
function Updateinfo () {
var realname=$ ("#realname"). Val ();
var identiy=$ ("#identifi"). Val ();
if (realname.trim () = = "" | | realname==null) {
Alert ("Please enter your real name!") ");
Return
}
if (identiy.trim () = = "" | | identiy==null) {
Alert ("Please enter the correct ID!") ");
Return
}
$.getjson ("/personalinfo/updateinfo.do",
{"Realname": realname, "identify": identiy},
function (Element) {
var F=element.result;
if (f) {
Alert ("Save success!") ");
}else{
Alert ("Message save Failed");
}
});
}
<table>
<tr>
<td><a class= "f_l MR10" href= "javascript:addimg ();" ></a></td>
<td><a class= "f_l MR10" href= "javascript:addimg ();" ></a></td>
</tr>
<tr>
<td><input id= "Files" name= "Files" type= "file" onchange= "Uploadfront ()"/><br></td>
<td><input id= "Files2" name= "Files2" type= "file" onchange= "Uploadback ()"/><br></td>
</tr>
</table>
Upload, download ID case