package com.jtgh.qlyg.sync; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.List; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Component; import com.jtgh.qlyg.entity.SuperviseStatEntity; import com.jtgh.qlyg.service.SuperviseStatService; import com.jtgh.yjpt.common.Constants; import com.jtgh.yjpt.common.GlobalData; import com.jtgh.yjpt.common.PredicateModel; import com.jtgh.yjpt.common.SpecificationCreater; import com.jtgh.yjpt.common.Utils; import com.jtgh.yjpt.controller.BaseController; import com.jtgh.yjpt.entity.common.CodeEntity; import com.jtgh.yjpt.service.common.CodeService; import com.jtgh.yjpt.service.qlyg.ApplyService; /** * 同步监察统计信息 * * @author masn * */ @Component public class QlygSyncSuperviseStat extends BaseController { /** 日志记录 */ private Logger logger = Logger.getLogger(getClass()); @Autowired private CodeService codeService; @Autowired private ApplyService applyService; @Autowired private SuperviseStatService superviseStatService; /** * 执行上月监察统计信息情况 */ 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.DAY_OF_MONTH, 1); 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.MONTH, -1); Date startTime = c.getTime(); List filterList = new ArrayList(); addNotEmptyModel(filterList, "id", GlobalData.CITY_CODE, PredicateModel.Operator.LIKE_R); addNotEmptyModel(filterList, "groupcode", "SZD", PredicateModel.Operator.EQ); Specification spec = SpecificationCreater .searchByPredicateModels(filterList); List szdList = codeService.findAll(spec); if (szdList != null && szdList.size() > 0) { for (CodeEntity szd : szdList) { HashMap stat = applyService.findSuperviseStat( startTime, stopTime, szd.getByzd4()); if (stat != null) { SuperviseStatEntity entity = new SuperviseStatEntity(); String dept_code = GlobalData.DEPT_CODE; if (Utils.getCurrentUser() != null) { dept_code = Utils.getCurrentUser().getSzd().getByzd4() + "JT"; } entity.setNo(generateQlygNo(dept_code, generateEntityId(Constants.QLYG_SEQ_SUPERVISE_STAT))); entity.setOrgId(szd.getByzd4()); entity.setStatDate(new SimpleDateFormat("yyyyMM") .format(startTime)); entity.setAccept(stat.get("accept") == null ? 0 : ((Long) stat.get("accept")).intValue()); entity.setBanjielvAhead(stat.get("banjielvAhead") == null ? 0 : (Double) stat.get("banjielvAhead")); entity.setMonitorSum(stat.get("monitorSum") == null ? 0 : (Double) stat.get("monitorSum")); entity.setAlarmSum(stat.get("alarmSum") == null ? 0 : (Double) stat.get("alarmSum")); entity.setSuperviseSum(stat.get("superviseSum") == null ? 0 : ((Long) stat.get("superviseSum")).intValue()); entity.setSuperviseProblermSum(stat .get("superviseProblermSum") == null ? 0 : ((Long) stat.get("superviseProblermSum")) .intValue()); entity.setComplaintsSum(stat.get("complaintsSum") == null ? 0 : ((Long) stat.get("complaintsSum")).intValue()); entity.setComplaintsProblermSum(stat .get("complaintsProblermSum") == null ? 0 : ((Long) stat.get("complaintsProblermSum")) .intValue()); superviseStatService.save(entity); } } } } }