package wjb.action.base;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;
import wjb.action.BaseAction;
import wjb.constant.WjbConstants;
import wjb.model.BaseBussinessLog;
import wjb.model.BaseNetDisk;
import wjb.model.base.SessionInfo;
import wjb.model.easyui.Grid;
import wjb.model.easyui.Json;
import wjb.service.BaseNetDiskServiceI;
import wjb.service.BussinessLogServiceI;
import wjb.utils.ConfigUtil;
import wjb.utils.HqlFilter;
import wjb.utils.StringUtil;
/**
* @描述: 网络硬盘业务
* @版权: Copyright (c) 2018
* @作者: wujiangbo(QQ:1134135987)
* @版本: 1.0
* @创建时间: 2018年8月28日 上午10:41:46
*/
@Action(value = "netDiskAction")
@Namespace("/base")
public class BaseNetDiskAction extends BaseAction<BaseNetDisk> {
private static final long serialVersionUID = -1190787179858309411L;
@Autowired
public void setService(BaseNetDiskServiceI service) {
this.service = service;
}
@Autowired
public void setServiceLog(BussinessLogServiceI service) {
this.serviceLog = service;
}
// 记录用户操作日志
public void writeLog(String log_context) {
SessionInfo sessionInfo = (SessionInfo) this.getSession().getAttribute(ConfigUtil.getSessionInfoName());
if (sessionInfo != null && sessionInfo.getUser() != null) {
// 记录操作日志
BaseBussinessLog bussiness_log = new BaseBussinessLog();
bussiness_log.setUpdateUser(sessionInfo.getUser().getUserName());
bussiness_log.setLogDescs(log_context);
serviceLog.save(bussiness_log);
}
}
/**
* @描述:详情
* @说明:暂无
* @作者:吴江波(QQ:1134135987) @创建日期:2018年6月4日 @创建时间:下午4:17:45
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public void doNotNeedSecurity_getById() {
if (StringUtils.isNotBlank(id)) {
List<Map> obj_list = ((BaseNetDiskServiceI) service).getInfoById(id);
if (obj_list != null && obj_list.size() > 0) {
writeJson(obj_list.get(0));
} else {
writeJson(new BaseNetDisk());
}
} else {
Json j = new Json();
j.setMsg(StringUtil.getMessage("A000005"));
writeJson(j);
}
}
/**
* @Description 下载文件
* @MethodName : doNotNeedSecurity_downloadObj
* @author : wujiangbo(QQ:1134135987@qq.com)
* @Date : 2018年8月29日 下午1:14:22
*/
public void doNotNeedSecurity_downloadObj() {
String id = this.getRequest().getParameter("id");
BaseNetDisk obj = service.getById(id);
writeLog("从网络硬盘下载文件[" + obj.getFileName() + "]成功");
this.uploadFile(obj.getFilePath(), obj.getFileName());
}
/**
* @Description 验证密码
* @MethodName : doNotNeedSecurity_validateResourcePwd
* @author : wujiangbo(QQ:1134135987@qq.com)
* @Date : 2018年8月29日 下午12:30:26
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public void doNotNeedSecurity_validateResourcePwd() {
String id = this.getRequest().getParameter("id");
String pwd_content = this.getRequest().getParameter("pwd_content");
Json j = new Json();
if (StringUtils.isBlank(pwd_content)) {
j.setMsg(StringUtil.getMessage("YW000017"));
} else {
List<Map> obj_list = ((BaseNetDiskServiceI) service).validateResourcePwd(id, StringUtil.getPassWord(pwd_content));
if (obj_list != null && obj_list.size() > 0) {
j.setSuccess(true);
} else {
j.setMsg(StringUtil.getMessage("YW000016"));
}
}
writeJson(j);
}
/**
* @Description 保存
* @MethodName : save
* @author : wujiangbo(QQ:1134135987@qq.com)
* @Date : 2018年8月28日 上午11:43:25
*/
@Override
public void save() {
String title = this.getRequest().getParameter("title");
// 首先检测标题是否存在
HqlFilter hqlFilter1 = new HqlFilter();
hqlFilter1.addFilter("QUERY_t#title_S_EQ", title);
BaseNetDisk share = service.getByFilter(hqlFilter1);
Json json = new Json();
if (share != null) {
json.setMsg(StringUtil.getMessage("YW000015"));
writeJson(json);
return;
}
String keyWord = this.getRequest().getParameter("keyWord");
String category = this.getRequest().getParameter("category");
String pwdFlag = this.getRequest().getParameter("pwdFlag");
String pwdContent = this.getRequest().getParameter("pwdContent");
// 获取文件类型
int index = this.getFileContextFileName().lastIndexOf('.');
String file_type = "";
if (index != -1) {
file_type = this.getFileContextFileName().substring(index + 1);
}
// 上传文件的保存路径
String save_path = WjbConstants.TOMCAT_PATH + WjbConstants.FILE_SEPARATOR + "NetDisk";
// 保存文件操作,返回保存文件的绝对路径
String file_save_path = this.saveFile(this.getFileContext(), save_path, this.getFileContextFileName());
BaseNetDisk object = new BaseNetDisk();
object.setId(StringUtil.getPrimaryKey());
object.setUpdateTime(new Date());
object.setUpdateUser(getCurrentUser().getId());
object.setTitle(title);
object.setCategory(category);
object.setKeyWord(keyWord);
object.setPwdFlag(pwdFlag);
if (StringUtils.isNotBlank(pwdContent)) {
object.setPwdContent(StringUtil.getPassWord(pwdContent));
}
object.setFilePath(file_save_path);
object.setFileType(file_type);
object.setFileName(this.getFileContextFileName());
service.save(object);
json.setSuccess(true);
json.setMsg(StringUtil.getMessage("A000003"));
writeLog("上传文件[" + this.getFileContextFileName() + "]到网络硬盘成功!");
writeJson(json);
}
/**
* @Description 删除
* @MethodName : delete
* @author : wujiangbo(QQ:1134135987@qq.com)
* @Date : 2018年8月28日 上午11:10:35
*/
@Override
public void delete() {
Json json = new Json();
if (!StringUtils.isBlank(id)) {
BaseNetDisk t = service.getById(id);
// 首先删除磁盘上的文件
File file = new File(t.getFilePath());
if (file.exists()) {
file.delete();
}
// 然后删除数据库记录
service.delete(t);
json.setSuccess(true);
json.setMsg(StringUtil.getMessage("A000003"));
writeLog("删除网络硬盘资源[" + t.getFileName() + "]成功!");
}
writeJson(json);
}
/**
* @Description 查找分页后的所有数据
* @MethodName : grid
* @author : wujiangbo(QQ:1134135987@qq.com)
* @Date : 2018年8月28日 上午11:09:58
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void grid() {
Grid grid = new Grid();
Map<String, String> params = new HashMap<String, String>();
params.put("update_user_name", this.getRequest().getParameter("update_user_name"));
params.put("title", this.getRequest().getParameter("title"));
params.put("category", this.getRequest().getParameter("category"));
params.put("time_begin", this.getRequest().getParameter("time_begin"));
params.put("time_end", this.getRequest().getParameter("time_end"));
params.put("key_word", this.getRequest().getParameter("key_word"));
params.put("pwd_flag", this.getRequest().getParameter("pwd_flag"));
params.put("file_type", this.getRequest().getParameter("file_type"));
List<Map> list_data = ((BaseNetDiskServiceI) service).findListBySql(params, page, rows);
List<Map> list_size = ((BaseNetDiskServiceI) service).findListCountBySql(params);
if (list_data != null && list_data.size() > 0) {
grid.setRows(list_data);
} else {
grid.setRows(new ArrayList<String>());
}
if (list_size != null && list_size.size() > 0) {
grid.setTotal((long) list_size.size());
} else {
grid.setTotal(0L);
}
writeJson(grid);
}
}
最近下载更多
最近浏览更多
SERE81192 LV19
6月23日
暂无贡献等级
WBelong LV8
2024年9月19日
wanxiaoqiao52866414 LV1
2024年7月1日
quartz LV8
2024年7月1日
荣》Cowboy LV12
2024年4月11日
Gin19960217 LV4
2024年1月15日
123456wadff LV3
2024年1月15日
lasttimeapp
2023年11月27日
暂无贡献等级
季明亮
2023年11月21日
暂无贡献等级

