package com.sys.bus.sys.service;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.sys.bus.sys.model.DtBean;
import com.sys.bus.sys.model.User;

import java.util.List;

/**
 * 做业务逻辑处理,事务处理放在service层
 * @author tangzy115049
 *
 */
public class UserService {

    private static final User dao = new User().dao();
    private static final DtBean comDao = new DtBean().dao();

    public static final UserService me =  new UserService();
    //制造异常，测试事务回滚
    @Before(Tx.class)
    public void save(User user) {
        user.save();
       // System.out.println(1/0);
    }

    //可以关联查询
    public List<DtBean> list(String para){
        String sql = "select * from ZX_TEST_USER a,ZX_TEST_ADDRESS b,ZX_TEST_detail c where b.tuid =a.id and c.aid = b.id  " + para;
        return comDao.find(sql);
    }

    ///////////////
    public Page<User> page(int pageNumber, int pageSize) {
        return dao.paginate(pageNumber, pageSize, "select *", "from ZX_TEST_USER order by id asc");
    }

    public User findById(String id) {
        return dao.findById(id);
    }

    public void deleteById(int id) {
        //	dao.deleteById((Integer)id);

    }
    //事务处理，异常必须抛出去才能事务回滚
    @Before(Tx.class)
    public void testTransactin(){

    }


}
