package com.product.file.controller;


import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.product.common.lang.StringUtils;
import com.product.core.dao.BaseDao;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.service.support.AbstractBaseService;
import com.product.lucene.service.LuceneService;
import com.product.util.BaseUtil;

/**
 * 	鑷姩娓呯悊闄勪欢鏁版嵁锛屾湇鍔″櫒闄勪欢锛堟殏涓嶅鐞嗭級
 * 	鏂囨。妫€绱㈢储寮曪紝
 * 	姣忓ぉ鎵ц
 */
@Service("fileAutoClear")
public class FileAutoClearService extends AbstractBaseService{

	@Autowired
	BaseDao baseDao;
	
	@Autowired
	LuceneService luceneService;

	
	public void getFileInfo(){
		//鑾峰彇鎵€鏈夐檮浠朵俊鎭�
		DataTableEntity dtFileInfo=baseDao.listTable("product_sys_attachments");
		if (!BaseUtil.dataTableIsEmpty(dtFileInfo)) {
			//閬嶅巻闄勪欢淇℃伅
			for (int i = 0; i < dtFileInfo.getRows(); i++) {
				FieldSetEntity fseFileInfo=dtFileInfo.getFieldSetEntity(i);
				String table_name=fseFileInfo.getString("attachment_data_table");	//鏉ユ簮琛�
				String table_filed=fseFileInfo.getString("attachment_data_field");	//鏉ユ簮瀛楁
				String uuid=fseFileInfo.getUUID();
				
				//闈炵┖楠岃瘉
				if (StringUtils.isEmpty(table_name) || StringUtils.isEmpty(table_filed)) {
					continue;
				}
				//鑾峰彇鍘熸暟鎹�
				FieldSetEntity fseService=baseDao.getFieldSetEntityByFilter(table_name, table_filed+"=?", new Object[] {uuid}, false);
				if (fseService==null) {
					try {
						//娓呴櫎绱㈠紩
						luceneService.deleteIndexByUUID(uuid);
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
		}
	}
}