Java Code Examples for com.xnx3.DateUtil#currentDate()

The following examples show how to use com.xnx3.DateUtil#currentDate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TemplateController.java    From wangmarket with Apache License 2.0 6 votes vote down vote up
/**
 * 导出当前网站当前的模版文件,包含模版页面,模版变量、栏目
 * @throws FileNotFoundException
 * @throws UnsupportedEncodingException
 */
@RequestMapping("exportTemplate${url.suffix}")
public void exportTemplate(HttpServletRequest request, HttpServletResponse response) throws FileNotFoundException, UnsupportedEncodingException {
	BaseVO vo = templateService.exportTemplate(request);
	String fileName = "template"+DateUtil.currentDate("yyyyMMdd_HHmm")+".wscso".toString(); // 文件的默认保存名
	//读到流中
	InputStream inStream = new ByteArrayInputStream(vo.getInfo().getBytes("UTF-8"));  
	
	AliyunLog.addActionLog(getSiteId(), "导出当前网站当前的模版文件");
	
	// 设置输出的格式
	response.reset();
	response.setContentType("bin");
	response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
        // 循环取出流中的数据
	byte[] b = new byte[1000];
	int len;
	try {
	    while ((len = inStream.read(b)) > 0)
	        response.getOutputStream().write(b, 0, len);
	    inStream.close();
	} catch (IOException e) {
	    e.printStackTrace();
	}
}
 
Example 2
Source File: SiteController.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * 获取用户的OSS已用空间
 */
@RequestMapping(value="getOSSSize${url.suffix}", method = RequestMethod.POST)
@ResponseBody
public BaseVO getOSSSize(){
	//判断一下,如果是使用的阿里云OSS存储,但是没有配置,会拦截提示
	if(AttachmentFile.isMode(AttachmentFile.MODE_ALIYUN_OSS) && OSSUtil.getOSSClient() == null){
		return error("未开通阿里云OSS服务");
	}
	
	BaseVO vo = new BaseVO();
	//获取其下有多少网站
	List<Site> list = sqlService.findBySqlQuery("SELECT * FROM site WHERE userid = "+getUserId(), Site.class);
	//属于该用户的这些网站共占用了多少存储空间去
	long sizeB = 0;
	for (int i = 0; i < list.size(); i++) {
		sizeB += AttachmentFile.getDirectorySize("site/"+list.get(i).getId()+"/");
	}
	
	int kb = Math.round(sizeB/1024);
	String currentDate = DateUtil.currentDate("yyyyMMdd");
	sqlService.executeSql("UPDATE user SET oss_update_date = '"+currentDate+"' , oss_size = "+kb+" WHERE id = "+getUserId());
	vo.setBaseVO(BaseVO.SUCCESS, kb+"");
	
	AliyunLog.addActionLog(getSiteId(), "计算我当前网站使用了多少存储空间,已使用:"+Lang.fileSizeToInfo(sizeB));
	
	ShiroFunc.setUEditorAllowUpload(kb<ShiroFunc.getUser().getOssSizeHave()*1000);
	return vo;
}
 
Example 3
Source File: LoginController_.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * 用户登陆成功后,计算其所使用的资源,如OSS占用
 * <br/>1.计算用户空间大小
 * <br/>2.设定用户是否可进行上传附件、图片
 */
public void loginSuccessComputeUsedResource(){
	//获取其下有多少网站
	final List<Site> list = sqlService.findBySqlQuery("SELECT * FROM site WHERE userid = "+getUserId(), Site.class);
	
	//如果这个用户是单纯的网站用户,并且今天并没有过空间计算,那么就要计算其所有的空间了
	final String currentDate = DateUtil.currentDate("yyyyMMdd");

	
	if((getUser().getOssUpdateDate() == null) || (getUser().getAuthority().equals(Global.get("USER_REG_ROLE")) && !getUser().getOssUpdateDate().equals(currentDate))){
		//计算当前用户下面有多少站点,每个站点的OSS的news文件夹下用了多少存储空间了
		new Thread(new Runnable() {
			public void run() {
				
				//属于该用户的这些网站共占用了多少存储空间去
				long sizeB = 0;
				try {
					for (int i = 0; i < list.size(); i++) {
						sizeB += AttachmentFile.getDirectorySize("site/"+list.get(i).getId()+"/");
					}
				} catch (Exception e) {
					e.printStackTrace();
					System.out.println("你应该是还没配置开通OSS吧~~要想上传图片上传附件,还是老老实实,访问 /instal/index.do 进行安装吧");
				}
				int kb = Math.round(sizeB/1024);
				sqlService.executeSql("UPDATE user SET oss_update_date = '"+currentDate+"' , oss_size = "+kb+" WHERE id = "+getUserId());
				ShiroFunc.getUser().setOssSize(kb);
				
				ShiroFunc.setUEditorAllowUpload(kb<ShiroFunc.getUser().getOssSizeHave()*1000);
			}
		}).start();
	}else{
		ShiroFunc.setUEditorAllowUpload(getUser().getOssSize()<ShiroFunc.getUser().getOssSizeHave()*1000);
	}
}