package com.hr.repository.service;

import com.alibaba.fastjson2.JSONObject;
import com.hr.dto.QueryDto;
import com.hr.fegin.dto.MyDemoDto;
import com.hr.repository.domain.Demo1Entity;
import com.hr.repository.domain.TestEntity;
import com.hr.repository.jpa.Demo1Jpa;
import com.hr.repository.jpa.TestJpa;
import com.yy.basedevelop.common.data.BasePageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Component
@Slf4j
public class DemoService {

    @Autowired
    private TestJpa testJpa;
    @Autowired
    private Demo1Jpa demo1Jpa;


    public void savee(){
        Demo1Entity md=demo1Jpa.findByFid(1L);
        if(md!=null){
            md.setFname("test");
        }
        else{
            md=new Demo1Entity();
            md.setFname("test");
        }
        log.info("save test");
        demo1Jpa.save(md);

//        if(1==1){
//            throw new RuntimeException("测试事务");
//        }
    }

    @Transactional
    public void insertLog(){
        TestEntity tt1=new TestEntity();
        tt1.setName("测试日志2");
        testJpa.save(tt1);
        log.info("===完成了一个日志的插入===={}",tt1);

//        if(1==1){
//            throw new RuntimeException("测试事务");
//        }
    }

    public BasePageResult<MyDemoDto> qyeryList(QueryDto dto){
        BasePageResult<MyDemoDto> list= demo1Jpa.queryList(dto.getName(),dto.getIds());
        return list;
    }

    public BasePageResult<MyDemoDto> qyeryList3(QueryDto dto){
        BasePageResult<MyDemoDto> list= demo1Jpa.queryList3(dto);
        return list;
    }

    public BasePageResult<MyDemoDto> selectList1(String name){
       return demo1Jpa.select1(name,null);

    }


}
