package weaver.interfaces.mfkj.action;

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

import java.util.UUID;

/**
 * @Title 积分兑换流程 更新积分台账
 * @Author wangchaofa
 * @CreateDate 2024/2/4
 * @Version 1.0
 * @Description
 */
public class PointsExchangeAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        try {
            String tablename = requestInfo.getRequestManager().getBillTableName();
            String requestid = requestInfo.getRequestid();

            RecordSet rs = new RecordSet();
            RecordSet rs1 = new RecordSet();
            RecordSet rst = new RecordSet();
            String dataSql = " select * from "+tablename+" where requestid="+requestid;
            rs.execute(dataSql);
            while(rs.next()){
                String sqr = Util.null2String(rs.getString("sqr")); //申请人
                double dqkyjf = Util.getDoubleValue(rs.getString("dqkyjf"),0);//当前可用积分
                double syjfhz = Util.getDoubleValue(rs.getString("syjfhz"),0);//使用积分汇总
                double sykyjf = Util.getDoubleValue(rs.getString("sykyjf"),0);//剩余可用积分
                rs1.executeQuery("select * from uf_jftz where jfhdr=?",sqr);
                if(rs1.next()){
                    double zjf = Util.getDoubleValue(rs1.getString("zjf"),0);
                    double dhjf = Util.getDoubleValue(rs1.getString("dhjf"),0);
                    dhjf += syjfhz;
                    double syjfs = Util.getDoubleValue(rs1.getString("syjfs"),0);

                    boolean bool = rst.executeUpdate("update uf_jftz set dhjf=?,syjfs=? where jfhdr=?",dhjf,sykyjf,sqr);
                    writeLog(requestid + " ================ 积分兑换流程更新积分台账 bool  =============== "+ bool);
                }
            }
        }catch (Exception e){
            requestInfo.getRequestManager().setMessagecontent("积分兑换操作失败，请联系管理员！");
            return Action.FAILURE_AND_CONTINUE;
        }
        return Action.SUCCESS;
    }
}
