package weaver.interfaces.htsc.wpscenter.impl;

import weaver.general.Util;
import weaver.hrm.User;
import weaver.interfaces.htsc.wpscenter.RevisionInterface;
import weaver.interfaces.htsc.wpscenter.convert.OfficeOperate;
import weaver.interfaces.htsc.wpscenter.utils.Config;
import weaver.interfaces.htsc.wpscenter.utils.Tools;
import weaver.workflow.logging.Logger;
import weaver.workflow.logging.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

public class ClearRevisionAndComents implements RevisionInterface {
    private Logger log = LoggerFactory.getLogger(ClearRevisionAndComents.class);

    private User user;

    public ClearRevisionAndComents(){
    }

    public ClearRevisionAndComents(User user){
        this.user = user;
    }

    public User getUser() {
        return user;
    }

    public ClearRevisionAndComents setUser(User user) {
        this.user = user;
        return this;
    }

    public Logger getLog() {
        return log;
    }

    public ClearRevisionAndComents setLog(Logger log) {
        this.log = log;
        return this;
    }

    @Override
    public int acceptRevisions(Map<String, Object> paramsMap) {
        if(Config.isLogInfo()) {
            log.info("paramsMap:" + paramsMap.toString());
        }

        if(null == user) {
            user = paramsMap.containsKey("user") ? (User)paramsMap.get("user") : null;
        }
        //文档imageFileId
        int imagefileId = (int)paramsMap.get("imagefileId");
        //生成的文件名称
        String fileName = (String)paramsMap.get("fileName");
        String fromMould = Tools.getFromMould(Util.null2String((String)paramsMap.get("fromMould")));

        OfficeOperate officeOperate = new OfficeOperate(user);
        Map<String, String> convertParam = new HashMap<String, String>();
        convertParam.put("imagefileId", imagefileId+"");
        convertParam.put("fromMould", fromMould);
        convertParam.put("fileName", fileName);
        convertParam.put("operate", OfficeOperate.OPERATE_CLEAN);
        Map<String, String> result = null;
        try {
            result = officeOperate.clearDoc(convertParam);
            if("0".equals(result.get("status"))){
                return Util.getIntValue(result.get("imagefileid"));
            }
        } catch (Exception e) {
            log.error(e);
        }
        return -1;
    }

    @Override
    public int deleteRevisions(Map<String, Object> paramsMap) {
        int imagefileId = (int)paramsMap.get("imagefileId");
        log.warn("deleteRevisions not implement");
        return imagefileId;
    }
}
