package com.jtgh.qlyg.sync; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.List; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.jtgh.qlyg.entity.InfLoginLogEntity; import com.jtgh.qlyg.service.InfLoginLogService; import com.jtgh.yjpt.common.Constants; import com.jtgh.yjpt.common.GlobalData; import com.jtgh.yjpt.common.Utils; import com.jtgh.yjpt.controller.BaseController; import com.jtgh.yjpt.service.common.LogService; /** * 同步登录信息 * * @author masn * */ @Component public class QlygSyncLoginLog extends BaseController { /** 日志记录 */ private Logger logger = Logger.getLogger(getClass()); @Autowired private LogService logService; @Autowired private InfLoginLogService infLoginLogService; /** * 执行前一天登录情况 */ public void execute() { if (Constants.NO.equals(GlobalData.QLYG_SYNC)) return; logger.info(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") .format(new Date()) + "执行QlygSyncLoginLog"); Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); Date stopTime = c.getTime(); c.add(Calendar.DAY_OF_MONTH, -1); Date startTime = c.getTime(); List logs = logService.findInfLoginLog(startTime, stopTime); if (logs != null && logs.size() > 0) { for (Object[] log : logs) { InfLoginLogEntity loginLog = new InfLoginLogEntity(); String dept_code = GlobalData.DEPT_CODE; if (Utils.getCurrentUser() != null) { dept_code = Utils.getCurrentUser().getSzd().getByzd4() + "JT"; } loginLog.setLogId(generateQlygNo(dept_code, generateEntityId(Constants.QLYG_SEQ_INF_LOGIN_LOG))); loginLog.setNo(loginLog.getLogId()); loginLog.setLogPerson((String) log[0]); loginLog.setOrgId((String) log[1]); loginLog.setLogDate(c.getTime()); loginLog.setLogNumber(((BigDecimal) log[2]).intValue()); loginLog.setLogTime(((BigDecimal) log[3]).longValue()); infLoginLogService.save(loginLog); } } } }