package weaver.interfaces.mfkj.job;

import com.wbi.util.Util;
import ln.TimeUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.interfaces.schedule.BaseCronJob;

/**
 * @Title 定时查询每个人的信息，生日当天 自动增加 100 积分
 * @Author wangchaofa
 * @CreateDate 2024/2/4
 * @Version 1.0
 * @Description
 */
public class SynUserBirthPointsJob extends BaseCronJob {

    BaseBean bb = new BaseBean();

    @Override
    public void execute() {
        bb.writeLog("========== start to syn user birthday info ==========");
        try{
            String currdate = TimeUtil.getCurrentDateString();
            String currtime = currdate.substring(5,10);
            RecordSet rs = new RecordSet();
            RecordSet rs1 = new RecordSet();
            RecordSet rst = new RecordSet();

            int birthday_points = Integer.parseInt(bb.getPropValue("syn_points_mfkj","birthday_points"));

            rs.executeQuery("select * from hrmresource where status<4 and birthday is not null");
            while(rs.next()){
                int userid = Util.getIntValue(rs.getString("id"));
                String birthday = Util.null2String(rs.getString("birthday"));
                if(birthday != null && !"".equals(birthday)){
                    String birthdate = birthday.substring(5,10);
                    //生日当天
                    if(currtime.equals(birthdate)){
                        rs1.executeQuery("select * from uf_jftz where jfhdr=?",userid);
                        if(rs1.next()){
                            double zjf = weaver.general.Util.getDoubleValue(rs1.getString("zjf"),0);
                            double syjfs = weaver.general.Util.getDoubleValue(rs1.getString("syjfs"),0);
                            zjf += birthday_points;
                            syjfs += birthday_points;
                            boolean bool = rst.executeUpdate("update uf_jftz set zjf=?,syjfs=? where jfhdr=?",zjf,syjfs,userid);
                            rs.writeLog(userid+ " ====  生日当天  ============ 获得100积分  bool  =============== "+ bool);
                        }
                    }
                }
            }
        }catch(Exception e){
            e.printStackTrace();
            bb.writeLog(e);
        }
        bb.writeLog("========== end to syn user birthday info ==========");
    }
}
