//package jj.tech.paolu.biz.demo.controller;
//
//import com.fasterxml.jackson.databind.ObjectMapper;
//import jj.tech.paolu.biz.demo.dao.UserDao;
//import jj.tech.paolu.biz.demo.service.AService;
//import jj.tech.paolu.biz.demo.service.BService;
//import jj.tech.paolu.biz.webadmin.dao.SelectMapper;
//import jj.tech.paolu.repository.jooq.tables.SysAdminRole;
//import jj.tech.paolu.repository.jooq.tables.pojos.SysAdmin;
//import jj.tech.paolu.repository.jooq.tables.records.SysAdminRoleRecord;
//import jj.tech.paolu.repository.mybatis.dao.UserInfoMapper;
//import jj.tech.paolu.utils.IDHelp;
//import org.jooq.*;
//import org.mybatis.dynamic.sql.BasicColumn;
//import org.mybatis.dynamic.sql.SqlBuilder;
//import org.mybatis.dynamic.sql.render.RenderingStrategies;
//import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.web.bind.annotation.*;
//
//import java.time.LocalDateTime;
//import java.util.HashMap;
//
//import static jj.tech.paolu.repository.jooq.Tables.*;
//import static jj.tech.paolu.repository.mybatis.dao.support.UserInfoDynamicSqlSupport.*;
//import static org.mybatis.dynamic.sql.SqlBuilder.count;
//
//
////@RequestMapping(value="/demo", name="demo11")
//@RestController
//public class DemoController {
//
//	@Value("${server.port}")
//  	String port;
//
//	@Autowired ObjectMapper objectMapper;
//	@Autowired UserDao userDao;
//	
//	@Autowired UserInfoMapper userInfoMapper;
//	@Autowired DSLContext dsl;
//	
//	
//	@Autowired AService aService;
//	@Autowired BService bService;
//	@Autowired SelectMapper selectMapper;
//  
////  @Autowired SysAdminDao sysAdminDaos;
//  
//  
//  /**
//   * JOOQ默认嵌入式事务
//   * @return
//   */
////	@GetMapping(value="/")
////	@Transactional
////	public Object mian() {
////		aService.aa();
////		try {
////			aService.bb();
////		}catch(Exception e) {
////		  e.printStackTrace();
////		}
////	    return "ok";
////	}
//  
//	/**
//	* JOOQ默认嵌入式事务
//	* @return
//	*/
//	@GetMapping("/t")
//	@Transactional
//	public Object t() {
//		aService.aa();
//		try {
//			aService.cc();
//		}catch(Exception e) {
//			e.printStackTrace();
//		}
//		return "ok";
//	}
//  
//  
//  
//
//	@GetMapping("/get")
//	public Object get(String username, String password) {
//	  
////	  //获取实际jdbc连接
////	  Object  r = 
////	  dslContext.connectionResult(c ->{
////		   Object result =
////				 DSL.using(c)
////			       .select(USER_INFO.USER_NAME)
////			       .from(USER_INFO)
////			       .where(USER_INFO.USER_NAME.eq(username))
////		           .and(USER_INFO.PASSWORD.eq(password))
////		           .orderBy(USER_INFO.ID.desc())
////		           .fetchAnyMap();
////		   return result;
////		});
////	   return r;
//	  return "OK";
//    
//	}
//  
//  
//	@GetMapping("/getById/{id}")
//	public Object getById(@PathVariable Long id) {
//	 //create.fetch("SELECT * FROM BOOK WHERE ID = ? AND TITLE = ?", 5, "Animal Farm");
////	SysAdmin result =  sysAdminDaos.fetchOneById(id);
////    return result;
//	  return "OK";
//	}
//  
//
//	@PostMapping("/add")
//	public Object add() {
//
////    if (bean.getId() == null) {
////    	IDHelp id = IDHelp.getInstance(1,1);
////      bean.setId(id.nextId());
////    }
////    int i =
////        dslContext
////            .insertInto(USER_INFO)
////            .set(USER_INFO.ID, bean.getId())
////            .set(USER_INFO.REAL_NAME, bean.getRealName())
////            .set(USER_INFO.USER_NAME, bean.getUserName())
////            .set(USER_INFO.PASSWORD, bean.getPassword())
////            .set(USER_INFO.HEAD_IMG, bean.getHeadImg())
////            .execute();
//	  
////	  UserInfoRecord r = dslContext.newRecord(USER_INFO); 
////	  r.setUserName("ssss");
////	  r.setRealName("bbbbb");
////	  r.setPassword("ssss");
////	  r.setPassword("ssss");
////	  r.store();
////	  System.out.println(r.getUserName());
////	  r.setHeadImg((String)null);
////	  int i = r.store();
//
////    return i;
//		return "";
//	}
//
//	@PostMapping("/updata/{id}")
//	public Object updata(@PathVariable Integer id) {
////    int ok =
////        dslContext
////            .update(USER_INFO)
////            .set(USER_INFO.ID, 1L)
////            .set(USER_INFO.USER_NAME, "")
////            .set(USER_INFO.PASSWORD, "")
////            .set(USER_INFO.HEAD_IMG, (String)null)
////            .where(USER_INFO.ID.eq(id))
////            .execute();
////    dslContext.newRecord(USER_INFO);
//		dsl.update(USER_INFO).set(USER_INFO.ID, 2L);
//	 
//		return "OK";
//	}
//
//	@PostMapping("/ss")
//	public Object ss() {
//		LocalDateTime d = LocalDateTime.now();
//		HashMap<String,Object> h = new HashMap<String,Object>();
//		IDHelp id = IDHelp.getInstance(0, 0);
//		Long i = id.nextId();
//		System.out.println(i);
//		h.put("s", i);
//		h.put("d", d);
//	  
////	  U s = new U();
//		SysAdmin s = 
//				dsl.selectFrom(SYS_ADMIN)
//				.where(SYS_ADMIN.USERNAME.eq("admin"))
//				.fetchOne().into(SysAdmin.class);
//	  
//		Table<?> ur = 
//				dsl.select(SYS_ROLE.ID)
//				.from(SYS_ROLE)
//				.where(SYS_ROLE.ID.eq(1L))
//				.asTable("ur");
//      
//		Field<Long> role_id = ur.field("role_id").coerce(Long.class);
//		SysAdminRole r = SYS_ADMIN_ROLE.as("r");
//		Result<Record1<SysAdminRoleRecord>>  bb =
//	    dsl.select(r).from(ur)
//	  		.leftJoin(r)
//	  		.on(r.ID.equal(role_id)).fetch();
//	
//	    return bb.intoMaps(); 
//	}
//  
//  
//	@GetMapping("/mybatis")
//	@Transactional
//	public Object mybatis() {
//		
//		BasicColumn[] selectList = BasicColumn.columnList(id, realname, count(id).as("idss"));
//	    SelectStatementProvider provider = SqlBuilder.select(selectList)
//	            .from(userInfo)
////	            .leftJoin(sysAdmin.withAlias("admin")).on(id, equalTo(sysAdmin.id))
//	            .groupBy(id)
//	            .build().render(RenderingStrategies.MYBATIS3);
//	    System.out.println(provider.getSelectStatement());
//	    Object m = userDao.selectSome(provider);
//	    // selectMapper.select(provider);
//		return selectMapper.select(provider);
//	}
//  
//	@GetMapping("66")
//	public Object a() {
//		aService.aa();
//		try {
//			aService.bb();
//		}catch(Exception e) {
//		  e.printStackTrace();
//		}
//	    return "ok";
//	}
//  
//}
