DeleteTemporaryFileProcess.java 3.54 KB
Newer Older
TongZuu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
/*
 * Created on 23 .. 2550
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.csc.library.process;

import java.io.File;
import java.rmi.RemoteException;
import java.util.HashMap;

import com.csc.library.database.StaticProperties;
import com.csc.library.mail.SendMail;
import com.csc.library.session.DbRecord;
import com.csc.library.session.InitialEnvironment;
import com.csc.library.session.InitialRecord;
import com.csc.library.utilities.CscCalendar;
import com.csc.library.utilities.MyLog;
import com.csc.library.utilities.UProfile;

/**
 * @author Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class DeleteTemporaryFileProcess extends MyProcess{
	CscCalendar toDay = new CscCalendar();
	
	public int delete(UProfile up, String path, int amountDay) throws RemoteException {
		int result = 0;
		DbRecord db = new InitialRecord(upf).getDbRecord("com.csc.entity.CSC_Quque");
		HashMap condition = new HashMap();
		condition.put("UProfile", up);
		condition.put("path", path);
		condition.put("amountDay", String.valueOf(amountDay));
		condition.put("cond", condition);
		this.setParam(condition);
		CscCalendar d  = new CscCalendar();
		db.clearField();
		db.set("ename","Delete Temporary File "+path);
		db.set("tname","źŪǤ "+path);
		db.set("class_name","DeleteTemporaryFileProcess");
		db.set("process_status","W");
		db.set("process_type","N");
		db.set("process_group","P");
        db.set("owner", (String) upf.get("appname"));
        db.set("remote_ip", (String) upf.get("remote_ip"));
        db.set("employeeid", (String) upf.getEmployee());
        db.set("companyid", (String) upf.getComCode());
        db.set("user_name", (String) upf.getUserName());
        db.set("screen_name", "Delete Temporary File");
        db.set("server_name", "NONE");
        db.set("next_time", d.getYYYYMMDDHHMMSS());
        db.set("start_time", "waiting");
        db.set("end_time", "waiting");
		db.set("remark","");
        db.set("process_priority", 9);
		db.set("condition",this.saveCondition());
		db.set("parentid",db.getString("condition").substring(0,db.getString("condition").indexOf(".ser")));
		result = db.save();
		StaticProperties.serverManager.inviteServerCheckQuque();
		return result; 
	}
	
	public void deleteSystemTemporary() throws RemoteException {
		String path = new InitialEnvironment("GLOBAL").getValue("temp-dir") + "/process/condition";
		this.deleteProcess(path, 3);
	}
	
	public void process() throws Exception {
		String path = data.get("path").toString();
		String amountDay = data.get("amountDay").toString();
		int day = Integer.parseInt(amountDay);
	    this.deleteProcess(path, day);
	}

	public void deleteProcess(String path, int day) {		
		File file = new File(path);		
		String[] filelist = file.list();
		String ext = "";
		boolean del = false;
		boolean deleteAll = false;
		for (int i = 0; i < filelist.length; i++) {
			String filename = filelist[i];	
			String fullpath = path+"\\"+ filename;
			File f2 = new File(fullpath);
			CscCalendar d = new CscCalendar();
			d.setTimeInMillis(f2.lastModified());
			if (f2.isDirectory()) {
				this.deleteProcess(fullpath, day);
			} else {
				if (toDay.subForDay(d)>=day) {
					System.out.println("delete file : "+fullpath);
					MyLog.debug(this.getUProfile(), "delete file : "+fullpath);
				}	
			}
		}
	}

}