定时任务,sqlserver ERP数据转移到mysql中

package org.jeecg.modules.quartz.job;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jeecg.qywx.api.message.vo.News;
import com.sun.xml.bind.v2.TODO;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.system.entity.Huayuerp;
import org.jeecg.modules.system.entity.Product;
import org.jeecg.modules.system.entity.ResultToFornt;
import org.jeecg.modules.system.mapper.ProductMapper;
import org.jeecg.modules.system.service.IHuayuerpService;
import org.jeecg.modules.system.service.IProductService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import java.io.File;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 示例不带参定时任务
 *
 * @Author Scott
 */
@Slf4j
public class ErpInteractive implements Job {

    @Autowired
    IHuayuerpService huayuerpService;
    @Autowired
    private IProductService productService;
    @Resource
    private ProductMapper productMapper;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {

        log.info(String.format("  ERP定时交互 ErpInteractive !  时间:" + DateUtils.getTimestamp()));

        List<Huayuerp> list = huayuerpService.list();
        List<Huayuerp>  list1 =new ArrayList<>();
//        遍历查出来的数据,如果商品名称在product表中存在 就不管,不存在就进行添加
//        List<Huayuerp> filtered = list.stream().map(x -> {
//            String productname = x.getProductname();
//            QueryWrapper<Product> queryWrapper = new QueryWrapper<>();
//            queryWrapper.eq("name", productname);
//            Product product = productService.getOne(queryWrapper);
//            if (product == null) {
//                list1.add(x);
//            }
//
//            return x;
//        }).collect(Collectors.toList());
        Iterator<Huayuerp> iter = list.iterator();
        while (iter.hasNext()) {
            Huayuerp huayuerp = iter.next();
            String productname = huayuerp.getProductname();
            QueryWrapper<Product> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("name", productname);
            Product product = productService.getOne(queryWrapper);
            if (product == null) {
                list1.add(huayuerp);
        }

        }
        if(list1.size()!=0){
            List<Product> products = list1.stream().map(x -> {
                Product product = new Product();
                Double custom1 = x.getCustom1();
                Double custom2 = x.getCustom2();
                Integer dqqty = x.getDqqty();

                String hlqty = x.getHlqty();
                String lnum = x.getLnum();

                String productname = x.getProductname();
                String roprmtr2 = x.getRoprmtr2();
                String svousrt = x.getSvousrt();
                product.setStock(dqqty);
                product.setProportionOfRawMaterial(hlqty);
                product.setComponentProportion(roprmtr2);
                product.setWide(custom1);
                product.setGramWeightRatio(custom2);
                product.setCombBar(lnum);
                product.setCategory(svousrt);
                product.setName(productname);
//                BeanUtils.copyProperties(x, product);
                return product;

            }).collect(Collectors.toList());

            productService.saveBatch(products);


        }else{
            System.out.println("数据已经转移完毕");
        }


    }



}

  

posted @ 2021-12-28 20:40  11111ghm  阅读(37)  评论(0编辑  收藏  举报