package com.gci.boot.modules.demo.controller;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.exception.ExcelDataConvertException;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.alibaba.excel.util.ListUtils;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gci.boot.common.util.JsonUtil;
import com.gci.boot.common.vo.Result;
import com.gci.boot.modules.system.entity.SysUser;
import com.gci.boot.modules.system.service.ISysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author chenzhiwei
 * @since 2023-08-14
 */
@Slf4j
@RestController
@RequestMapping("/demo/crud")
public class CRUDDemoController {

	@Autowired
	private ISysUserService sysUserService;


	@GetMapping("/list")
	public Result<?> list() {
		List<SysUser> list = sysUserService.list();
		return Result.ok(list);
	}

	@GetMapping("/page")
	public Result<?> page(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
						  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
		Page page = sysUserService.page(new Page(pageNo, pageSize));
		return Result.ok(page);
	}

	@PostMapping("/add")
	public Result<?> add(SysUser user){
		sysUserService.save(user);
		return Result.ok();
	}

	@PutMapping("/edit")
	public Result<?> edit(SysUser user){
		sysUserService.updateById(user);
		return Result.ok();
	}

	@DeleteMapping("/delete")
	public Result<?> delete(SysUser user){
		sysUserService.removeById(user.getId());
		return Result.ok();
	}

}
