package weaver.interfaces.htsc.cowork;

import weaver.conn.RecordSet;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.TimeUtil;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.UUID;

/**
 * Created by K1810007 on 2020/10/21.
 */

public class taskFeedbackRequestReturnAction implements Action {
    @Override
    public String execute(RequestInfo requestInfo)
    {
        RecordSet rs = new RecordSet();
        String requestid = requestInfo.getRequestid();
        String formtable = requestInfo.getRequestManager().getBillTableName();
        int currentUserid = requestInfo.getRequestManager().getUser().getUID();
        if(!"".equals(formtable)){
            String remark = "" ;
            String sql = "  select logid,to_char(remark) as remark from workflow_requestlog where requestid="+requestid+" and logtype='t' and nodeid = 5525 order by logid desc ";
            rs.execute(sql);
            if(rs.next()){
                remark = Util.null2String(rs.getString("remark"));
            }

            String currentdate = TimeUtil.getCurrentDateString();
            String currenttime = TimeUtil.getOnlyCurrentTimeString();
            String uuid = UUID.randomUUID().toString();
            int formmodeid = 4012;
            boolean exeRes = rs.executeUpdate(" insert into uf_rwfk(fkr,fkxq,modedatacreater,modedatacreatedate,modedatacreatetime,formmodeid,modeuuid) " +
                    "values(?,?,?,?,?,?,?) ",new Object[]{currentUserid,currentUserid,remark,currentdate,currenttime,formmodeid,uuid});
            int billid = -1;
            if (exeRes) {
                //重构权限
                rs.execute(" select id from uf_rwfk where modeuuid='" + uuid + "' ");
                rs.next();
                billid = rs.getInt("id");
                ModeRightInfo moderight = new ModeRightInfo();
                moderight.editModeDataShare(currentUserid, formmodeid, billid);
            }else{
                requestInfo.getRequestManager().setMessageid("1111");
                requestInfo.getRequestManager().setMessagecontent("反馈意见增加失败,请联系系统管理员！");
                return Action.FAILURE_AND_CONTINUE;
            }
        }
        return Action.SUCCESS;
    }
}
