| 对比新文件 |
| | |
| | | package com.mzl.flower.thread; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.mzl.flower.entity.flower.FlowerCategory; |
| | | import com.mzl.flower.entity.partner.Partner; |
| | | import com.mzl.flower.mapper.flower.FlowerCategoryMapper; |
| | | import com.mzl.flower.mapper.partner.PartnerMapper; |
| | | import com.mzl.flower.service.flower.FlowerService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.List; |
| | | import java.util.concurrent.ExecutorService; |
| | | import java.util.concurrent.Executors; |
| | | |
| | | @Component |
| | | @Slf4j |
| | | public class FlowerCategoryPriceThread { |
| | | |
| | | ExecutorService fixedThreadPool = Executors.newFixedThreadPool(3); |
| | | |
| | | @Autowired |
| | | private FlowerService flowerService; |
| | | |
| | | @Autowired |
| | | private FlowerCategoryMapper categoryMapper; |
| | | |
| | | @Autowired |
| | | private PartnerMapper partnerMapper; |
| | | |
| | | public void run() { |
| | | List<FlowerCategory> cLs = categoryMapper.selectList(new QueryWrapper<FlowerCategory>() |
| | | .isNotNull("parent_id")); |
| | | if(cLs != null && cLs.size() > 0){ |
| | | List<Partner> ls = partnerMapper.selectList(new QueryWrapper<Partner>().eq("status", "P")); |
| | | for(FlowerCategory c : cLs){ |
| | | addTask(flowerService, c.getId(), null); |
| | | |
| | | if(ls != null && ls.size() > 0){ |
| | | for(Partner p : ls){ |
| | | addTask(flowerService, c.getId(), p.getId()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void addTask(FlowerService service, Long categoryId, Long partnerId) { |
| | | SelfTask t = new SelfTask(service, categoryId, partnerId); |
| | | fixedThreadPool.execute(t); |
| | | } |
| | | |
| | | private class SelfTask implements Runnable { |
| | | private FlowerService service; |
| | | |
| | | private Long categoryId; |
| | | |
| | | private Long partnerId; |
| | | |
| | | public SelfTask(FlowerService service, Long categoryId, Long partnerId) { |
| | | this.service = service; |
| | | this.categoryId = categoryId; |
| | | this.partnerId = partnerId; |
| | | } |
| | | |
| | | public void run() { |
| | | try { |
| | | service.calculateCategoryDaily(categoryId, partnerId); |
| | | } catch (Exception e) { |
| | | log.error("==> 计算均价 categoryId: " + categoryId + "; partnerId: " + partnerId + "; 错误信息:" + e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |