package com.zteits.park.job; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.PageInfo; import com.xiaoleilu.hutool.date.DateUtil; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.context.XxlJobHelper; import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.context.XxlJobHelper; import com.zteits.clouds.api.dto.clouds.param.QueryEmployeeRequest; import com.zteits.clouds.api.dto.park.dto.TpEEmployeeChargeDTO; import com.zteits.park.dao.TpEEmployeeChargeDao; import com.zteits.park.service.chargerincomediff.oper.ChargerIncomeDiffOperInnerService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.CountDownLatch; /** * Copyright: Copyright (c) 2019 zteits * * @ClassName: com.zteits.park.job * @Description: * @version: v1.0.0 * @author: atao * @date: 2019-01-15 18:56 * Modification History: * Date Author Version Description * ---------------------------------------------------------* * 2019-01-15 atao v1.0.0 创建 */ @Component public class ChargerIncomeDiffJob { @Autowired private ChargerIncomeDiffOperInnerService chargerIncomeDiffOperInnerService; @Autowired private TpEEmployeeChargeDao tpEEmployeeChargeDao; @XxlJob("ChargerIncomeDiffJob") public ReturnT execute(String... params) throws Exception { String param = XxlJobHelper.getJobParam(); if (StringUtils.isNotEmpty(param) && params == null) { params = param.split(","); } Date initDate = DateUtil.yesterday(); if (null != params && params.length > 0) { initDate = DateUtil.parseDate(params[0]); } Date startDate = DateUtil.beginOfDay(initDate); Date endDate = DateUtil.endOfDay(initDate); XxlJobHelper.log("开始时间为:" + startDate + "结束时间为:" + endDate); Integer delNum = chargerIncomeDiffOperInnerService.deleteChargerIncomeDiffByDate(startDate, endDate); XxlJobHelper.log("删除数据:" + delNum); QueryEmployeeRequest request = new QueryEmployeeRequest(); request.setEntryStatus(1); request.setChargerType("0"); request.getBaseRequest().setPageNum(1); request.getBaseRequest().setPageSize(Integer.MAX_VALUE); PageInfo pageInfo = tpEEmployeeChargeDao.queryEmployeesForPage(request); if (null == pageInfo) { XxlJobHelper.log("查询收费员失败"); return ReturnT.FAIL; } List chargeDTOS = pageInfo.getList(); if (CollectionUtils.isEmpty(chargeDTOS)) { XxlJobHelper.log("查询收费员为空"); return ReturnT.FAIL; } CountDownLatch countDownLatch = new CountDownLatch(chargeDTOS.size()); Map falilMap = new HashMap<>(10); for (TpEEmployeeChargeDTO dto : chargeDTOS) { chargerIncomeDiffOperInnerService.handelChargerIncomeDiffByChargerCodeAsync(dto.getChargerCode(), startDate, endDate, countDownLatch, falilMap); } countDownLatch.await(); return new ReturnT<>(JSONObject.toJSONString(falilMap)); } }