SupplierErpService.java 3.94 KB
package com.huaheng.pc.config.supplier.service;

import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.DateUtils;
import com.huaheng.pc.config.address.domain.Address;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.srm.domain.SrmDetail;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.framework.aspectj.lang.annotation.Ds;
import com.huaheng.framework.aspectj.lang.constant.DataSourceName;
import com.huaheng.pc.config.supplier.domain.SupplierErp;
import com.huaheng.pc.config.supplier.mapper.SupplierErpMapper;


@Service
public class SupplierErpService extends ServiceImpl<SupplierErpMapper, SupplierErp>{

    @Resource
    private SupplierErpMapper supplierErpMapper;


    SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    /**
     * 查找erp数据库的供应商数据
     * @return
     */
    @Ds(name= DataSourceName.SLAVE)
   public List<SupplierErp> findSupplierData(Integer supplierTime,Address address,Date syncTimes){
        // 将Date转换为Instant
        Instant instant = syncTimes.toInstant();
        // 将Instant往前推移10分钟
        Instant newInstant = instant.minus(5, ChronoUnit.MINUTES);
        // 将新的Instant转换回Date
        Date newDate = Date.from(newInstant);

//        String startTime= DateUtils.getNowPreMin("yyyy-MM-dd HH:mm:ss", supplierTime);
//        Date date=null;
//        try{
//            date=sf.parse(startTime);
//        }catch (Exception e){
//        }


        QueryWrapper<SupplierErp> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("交易对象类型", 1,3);
        queryWrapper.eq("企业编号", address.getUserDef2());
//        queryWrapper.isNull("最近更改日");
        queryWrapper.ge("最近更改日", newDate);
        queryWrapper.select(" DISTINCT 交易对象编号 as pmaa001, 交易对象类型 AS pmaa002,交易对象简称 AS pmaal, \n" +
                "最近更改日 AS pmaamodd");
//        queryWrapper.last(" and rownum<=1");
        List<SupplierErp> lists = this.list(queryWrapper);
        return lists;
   }

    /**
     * 查找erp数据库的客户数据
     * @return
     */
    @Ds(name= DataSourceName.SLAVE)
    public List<SupplierErp> findCustomerData(Integer time, Address address,Date syncTimes){
//        String startTime= DateUtils.getNowPreDays("yyyy-MM-dd HH:mm:ss", 30);
//        time=time*24*14;
        // 将Date转换为Instant
        Instant instant = syncTimes.toInstant();
        // 将Instant往前推移10分钟
        Instant newInstant = instant.minus(5, ChronoUnit.MINUTES);
        // 将新的Instant转换回Date
        Date newDate = Date.from(newInstant);
//        String startTime= DateUtils.getNowPreMin("yyyy-MM-dd HH:mm:ss", time);
//        Date date=null;
//        try{
//            date=sf.parse(startTime);
//        }catch (Exception e){
//        }
        QueryWrapper<SupplierErp> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("交易对象类型", 2,3);
//        queryWrapper.isNull("最近更改日");
        queryWrapper.ge("最近更改日", newDate);
        queryWrapper.eq("企业编号", address.getUserDef2());
        queryWrapper.select(" DISTINCT 交易对象编号 as pmaa001, 交易对象类型 AS pmaa002,交易对象简称 AS pmaal, \n" +
                "最近更改日 AS pmaamodd");
//        queryWrapper.last(" and rownum<=1");
        List<SupplierErp> lists = this.list(queryWrapper);
        return lists;
    }
}