📄 tpzlaction.java
字号:
/**
*文件功能:
*/
package com.tech.action;
import java.io.File;
import java.io.FileInputStream;
import java.net.URLEncoder;
import java.util.List;
import java.util.ArrayList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.lang.StringUtils;
import com.common.Config;
import com.common.action.BaseAction;
import com.common.dao.HibernateDaoHelper;
import com.common.exception.BusinessException;
import com.common.hibernate.IdGenerator;
import com.common.util.PaginationSupport;
import com.common.dao.DaoHelper;
import com.tech.model.Rygl;
import com.tech.model.Tpzl;
import com.tech.service.TpzlService;
/**
* @作者 徐建协
* @日期 2009-03-20
*/
public class TpzlAction extends BaseAction {
private Log log = LogFactory.getLog(TpzlAction.class);
private Tpzl tpzl;
private Long[] idKeys;
private List list;
private PaginationSupport page;
private TpzlService tpzlService;
private File[] file;
private String[] fileContentType;
private String[] fileFileName;
//private Long sdid;
private HibernateDaoHelper hibernateDaoHelper;
public void setHibernateDaoHelper(HibernateDaoHelper hibernateDaoHelper) {
this.hibernateDaoHelper = hibernateDaoHelper;
}
public Tpzl getTpzl() {
return tpzl;
}
public void setTpzl(Tpzl tpzl) {
this.tpzl = tpzl;
}
public Long[] getIdKeys() {
return idKeys;
}
public void setIdKeys(Long[] idKeys) {
this.idKeys = idKeys;
}
public File[] getFile() {
return file;
}
public void setFile(File[] file) {
this.file = file;
}
public String[] getFileContentType() {
return fileContentType;
}
public void setFileContentType(String[] fileContentType) {
this.fileContentType = fileContentType;
}
public String[] getFileFileName() {
return fileFileName;
}
public void setFileFileName(String[] fileFileName) {
this.fileFileName = fileFileName;
}
public List getList() {
return list;
}
public PaginationSupport getPage() {
return page;
}
public void setTpzlService(TpzlService tpzlService) {
this.tpzlService = tpzlService;
}
private byte[] getBytes(File f) throws Exception {
byte[] buffer = new byte[(int) f.length()];
int len = 0;
FileInputStream fileIn = new FileInputStream(f);
len = fileIn.read(buffer);
return buffer;
}
public String save() throws Exception {
if(null!=file)
{
int count=0;
String str="";
// Rygl rygl=this.getRyglSession();
String sql="select count(id) count from tpzl where tid=?";
try {
// if(hibernateDaoHelper.countBySQL(sql,"count",new Object[]{hyxx.getSdid()})>2){
// throw new BusinessException("最多只能上传3张照片");
// }
List<Tpzl> listTmp=new ArrayList<Tpzl>();
for(int i=0;i<file.length;i++){
if(file[i]!=null){
count++;
Tpzl t=new Tpzl();
t.setTpnr(getBytes(file[i]));
t.setId(new Long(IdGenerator.getId()));
//t.setTid(rygl.getId());
t.setTplx(fileContentType[i]);
t.setScbz(new Long("0"));
t.setTplxbz(new Long("3"));
t.setTplybz(new Long("13"));
t.setTpsm(tpzl.getTpsm());
listTmp.add(t);
}
}
Tpzl[] array=new Tpzl[listTmp.size()];
for(int i=0;i<array.length;i++){
array[i]=new Tpzl();
}
listTmp.toArray(array);
tpzlService.saveEntity(array);
setActionMessage("图片保存成功");
return "list";
} catch (Exception ex) {
setErrMessage(ex.getMessage());
page = new PaginationSupport(getMap());
page.setContextPath(this.getContextPath());
this.setUrlParams(page.getParams()+"&actionMessage="+URLEncoder.encode("最多只能上传3张图片","GBK"));
return "list";
}
}
return "list";
}
public String saveByYh() throws Exception {
if(null!=file)
{
int count=0;
String str="";
String sql="select count(id) count from tpzl where tid=?";
try {
// if(hibernateDaoHelper.countBySQL(sql,"count",new Object[]{sdid})>2){
// throw new BusinessException("最多只能上传3张照片");
// }
List<Tpzl> listTmp=new ArrayList<Tpzl>();
for(int i=0;i<file.length;i++){
if(file[i]!=null){
count++;
Tpzl t=new Tpzl();
t.setTpnr(getBytes(file[i]));
t.setId(new Long(IdGenerator.getId()));
//t.setTid(sdid);
t.setTplx(fileContentType[i]);
t.setScbz(new Long("0"));
t.setTplxbz(new Long("3"));
t.setTplybz(new Long("13"));
t.setTpsm(tpzl.getTpsm());
listTmp.add(t);
}
}
Tpzl[] array=new Tpzl[listTmp.size()];
for(int i=0;i<array.length;i++){
array[i]=new Tpzl();
}
listTmp.toArray(array);
tpzlService.saveEntity(array);
setActionMessage("图片保存成功");
this.setUrlParams(page.getParams()+"&actionMessage="+URLEncoder.encode("图片保存成功","GBK"));
return "list";
} catch (Exception ex) {
setErrMessage(ex.getMessage());
page = new PaginationSupport(getMap());
page.setContextPath(this.getContextPath());
this.setUrlParams(page.getParams()+"&actionMessage="+URLEncoder.encode("最多只能上传3张图片","GBK"));
return "list";
}
}
return "list";
}
public String remove(){
try {
//Hyxx hyxx=this.getHyxxSession();
//tpzl.setTid(rygl.getId());
//tpzlService.removeRygl(tpzl);
setActionMessage(Config.DELETE_SUCCESS_MESSAGE);
page = new PaginationSupport(getMap());
page.setContextPath(this.getContextPath());
this.setUrlParams(page.getParams()+"&actionMessage="+URLEncoder.encode(Config.DELETE_SUCCESS_MESSAGE));
return "list";
} catch (Exception ex) {
setErrMessage(ex.getMessage());
return "list";
}
}
public String removeByYh(){
try {
//tpzl.setTid(sdid);
//tpzlService.removeHyxx(tpzl);
setActionMessage(Config.DELETE_SUCCESS_MESSAGE);
page = new PaginationSupport(getMap());
page.setContextPath(this.getContextPath());
this.setUrlParams(page.getParams()+"&actionMessage="+URLEncoder.encode(Config.DELETE_SUCCESS_MESSAGE));
return "list";
} catch (Exception ex) {
setErrMessage(ex.getMessage());
return "list";
}
}
public String list(){
try {
//Hyxx hyxx=this.getHyxxSession();
page = new PaginationSupport(getMap());
page.setContextPath(this.getContextPath());
this.setUrlParams(page.getParams());
String countSQL="select count(t.id) count from tpzl t where tid=?";
String countAlias="count";
String sql="select {t.*} from tpzl t where tid=?";
String sqlAlias="t";
ArrayList<String> paramMeters=new ArrayList<String>();
//paramMeters.add(hyxx.getSdid()+"");
page=hibernateDaoHelper.findBySQL(page, countSQL, countAlias, sql, sqlAlias, paramMeters.toArray(), Tpzl.class, false);
list=page.getItems();
this.setRecordCount(page.getTotalCount());
} catch (Exception ex) {
setErrMessage(ex.getMessage());
}
return this.SUCCESS;
}
public String listByYh(){
try {
page = new PaginationSupport(getMap());
page.setContextPath(this.getContextPath());
this.setUrlParams(page.getParams());
String countSQL="select count(t.id) count from tpzl t where tid=?";
String countAlias="count";
String sql="select {t.*} from tpzl t where tid=?";
String sqlAlias="t";
ArrayList<String> paramMeters=new ArrayList<String>();
//paramMeters.add(sdid+"");
page=hibernateDaoHelper.findBySQL(page, countSQL, countAlias, sql, sqlAlias, paramMeters.toArray(), Tpzl.class, false);
list=page.getItems();
this.setRecordCount(page.getTotalCount());
} catch (Exception ex) {
setErrMessage(ex.getMessage());
}
return this.SUCCESS;
}
// public Long getSdid() {
// return sdid;
// }
//
// public void setSdid(Long sdid) {
// this.sdid = sdid;
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -