pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoSe/SeGeneralMapper.java
@@ -8,6 +8,7 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.util.Date; import java.util.List; import java.util.Map; @@ -46,6 +47,13 @@ List<SeGeneral> getGeneralByOperateDate(@Param("operateDate") String operateDate); /** * 根据交易日期获取总账记录列表(待生成的) * @param cashierId 收银员 * @param operateDate 交易日期 * @return 取总账记录列表 */ List<SeGeneral> getGeneralByUserIdAndDt(@Param("cashierId") Long cashierId, @Param("operateDate") Date operateDate) ; /** * 根据指定条件获取总账记录数 * @param params * @return pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoSe/SeGeneral.java
@@ -93,4 +93,11 @@ @Max(message = "审核状态最大为3", value = 3) @Min(message = "审核状态最小为1",value = 1) private Byte auditStatus; public void updateFrom(SeGeneral fromPo){ this.tradeAmount = fromPo.tradeAmount ; this.gift = fromPo.gift ; this.refundAmount = fromPo.refundAmount ; } } pipIrr-platform/pipIrr-global/src/main/resources/mapper/SeGeneralMapper.xml
@@ -189,6 +189,15 @@ GROUP BY Date(audit_time) </select> <!--根据收银员和交易日期获取总账记录列表 --> <select id="getGeneralByUserIdAndDt" resultType="com.dy.pipIrrGlobal.pojoSe.SeGeneral"> select <include refid="Base_Column_List" /> from se_general where cashier_id = #{cashierId,jdbcType=BIGINT} and operate_date = #{operateDate,jdbcType=TIMESTAMP} </select> <!--根据指定条件获取总账记录数--> <select id="getRecordCount" parameterType="java.util.Map" resultType="java.lang.Long"> SELECT pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/autoTask/StAccount.java
New file @@ -0,0 +1,47 @@ package com.dy.pipIrrSell.autoTask; import com.dy.pipIrrGlobal.pojoSe.SeGeneral; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; /** * @Author: liurunyu * @Date: 2025/9/23 14:44 * @Description */ @Slf4j @Component public class StAccount { @Autowired protected StAccountSv sv ; protected void statistics4Day(String yyyy_MM_dd){ this.statisticsDay(yyyy_MM_dd) ; } /** * 日统计---对账 */ private void statisticsDay(String yyyy_MM_dd){ // 根据交易日期获取总账记录列表(待生成的) List<SeGeneral> list_general = sv.getGeneralByOperateDate(yyyy_MM_dd) ; if(list_general != null && list_general.size() > 0) { for(int j = 0; j < list_general.size(); j++) { SeGeneral general = list_general.get(j); List<SeGeneral> one_list_general = sv.getGeneralByUserIdAndDt(general.getCashierId(), general.getOperateDate()); if(one_list_general == null || one_list_general.size() == 0){ sv.addGeneral(general); }else{ SeGeneral onePo = one_list_general.get(0); onePo.updateFrom(general); sv.updateGeneral(onePo); } } } } } pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/autoTask/StAccountSv.java
New file @@ -0,0 +1,65 @@ package com.dy.pipIrrSell.autoTask; import com.dy.pipIrrGlobal.daoSe.*; import com.dy.pipIrrGlobal.pojoSe.SeGeneral; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.List; import java.util.Map; /** * @Author: liurunyu * @Date: 2025/9/23 14:44 * @Description */ @Component public class StAccountSv { @Autowired private SeGeneralMapper seGeneralMapper; /** * 根据交易日期获取总账记录列表(待生成的) * @param operateDate 交易日期 * @return 取总账记录列表 */ public List<SeGeneral> getGeneralByOperateDate(String operateDate) { return seGeneralMapper.getGeneralByOperateDate(operateDate); } /** * 根据交易日期获取总账记录列表(待生成的) * @param cashierId 收银员 * @param operateDate 交易日期 * @return 取总账记录列表 */ public List<SeGeneral> getGeneralByUserIdAndDt(Long cashierId, Date operateDate) { return seGeneralMapper.getGeneralByUserIdAndDt(cashierId, operateDate); } /** * 添加总账 * @param po 总账对象 * @return */ @Transactional(rollbackFor = Exception.class) public Integer addGeneral(SeGeneral po) { return seGeneralMapper.insert(po); } /** * 添加总账 * @param po 总账对象 * @return */ @Transactional(rollbackFor = Exception.class) public Integer updateGeneral(SeGeneral po) { return seGeneralMapper.updateByPrimaryKey(po); } } pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/autoTask/StatisticsJob.java
New file @@ -0,0 +1,54 @@ package com.dy.pipIrrSell.autoTask; import com.dy.common.multiDataSource.DataSourceContext; import com.dy.common.schedulerTask.TaskJob; import com.dy.common.springUtil.SpringContextUtil; import com.dy.common.util.DateTime; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.quartz.JobDataMap; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; /** * @Author: liurunyu * @Date: 2025/9/23 14:21 * @Description */ public class StatisticsJob extends TaskJob { private static Logger log = LogManager.getLogger(StatisticsJob.class.getName()) ; private String orgTag ; private StAccount stAccount; private String yesterday; @Override public void execute(JobExecutionContext ctx) throws JobExecutionException { JobDataMap jobDataMap = ctx.getJobDetail().getJobDataMap() ; if(jobDataMap != null){ orgTag = (String)jobDataMap.get(StatisticsListener.orgKey) ; } if(orgTag == null){ return ; } DataSourceContext.set(orgTag);//设置数据源 stAccount = SpringContextUtil.getBean(StAccount.class); if(stAccount != null){ yesterday = DateTime.lastXDay_yyyy_MM_dd(1) ;//得到昨天,零晨时刻统计,统计昨天的数 //统计日的量 doStatisticsDay() ; }else{ log.error("未能从Spring容器中得到统计bean"); } } /** * 统计 */ private void doStatisticsDay(){ stAccount.statistics4Day(yesterday) ; } } pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/autoTask/StatisticsListener.java
New file @@ -0,0 +1,90 @@ package com.dy.pipIrrSell.autoTask; import com.dy.common.schedulerTask.SchedulerTaskSupport; import com.dy.pipIrrGlobal.util.Org; import com.dy.pipIrrGlobal.util.OrgListenerSupport; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.ApplicationListener; import org.springframework.core.io.ResourceLoader; import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; import java.util.HashMap; import java.util.List; /** * @Author: liurunyu * @Date: 2025/9/23 14:15 * @Description * 监听器,实现功能:启动日 统计 收银员对账 定时任务 * 本监听器不能采用ServletContextListener方式,因为Servlet上下文Context创建后 * Spring容器并没有创建完,而本类中用了Spring容器中的Bean,即*Dao 。 * 所以采用了Spring事件监听器来实现 */ @Slf4j @Component public class StatisticsListener extends OrgListenerSupport implements ApplicationListener<ApplicationReadyEvent> { protected static final String orgKey = "tag" ; private static final String JobName = "statisticsAccountJob" ; private static final String JobGroupName = "statisticsAccountGroup" ; private static final Integer ThreadPoolMaxCount = 1 ;//线程池线程最大个数 private static final Integer ThreadPoolPriority = 5 ;//线程优先级 /** * 统计开始小时,必须0点或之后,见StatisticsJob中统计,日统计是统计昨天的 */ @Value("${auto-statistics.startHour: 0}") protected Integer startHour;//统计开始小时 @Value("${auto-statistics.startMinute: 5}") protected Integer startMinute;//统计开始分钟 @Autowired protected ResourceLoader resourceLoader ; /** * SpringBoot容器已经准备好了,执行下面方法 * @param event 事件 */ @Override public void onApplicationEvent(@NonNull ApplicationReadyEvent event) { try { //等1秒,等待com.alibaba.druid.pool.DruidDataSource初始化完成 Thread.sleep(1000L); } catch (InterruptedException e) { e.printStackTrace(); }finally { try{ super.init(resourceLoader); this.start(event); }catch (Exception e){ log.error("注册统计定时任务出错", e); } } } /** * 初始化 */ private void start(ApplicationReadyEvent event) throws Exception{ if(startHour < 0 || startHour > 5){ startHour = 0 ; } List<Org.OrgVo> orgList = Org.OrgList ; if(orgList != null && orgList.size() >0){ SchedulerTaskSupport.setThreadPoolPro(ThreadPoolMaxCount * orgList.size(), ThreadPoolPriority); for(Org.OrgVo vo : orgList){ HashMap<String , Object> jobDataMap = new HashMap<String , Object>() ; jobDataMap.put(orgKey, vo.tag) ; SchedulerTaskSupport.addDailyJob(JobName + vo.tag, JobGroupName, StatisticsJob.class, jobDataMap, startHour, startMinute ) ; } } } }