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


import java.util.List;

import com.gci.boot.common.log.annotation.AddSysLog;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gci.boot.annotation.Query.handle.QueryGenerator;
import com.gci.boot.common.vo.Result;
import com.gci.boot.modules.projects.entity.TbVehicleCheckProject;
import com.gci.boot.modules.projects.service.ITbVehicleCheckProjectService;
import com.gci.boot.modules.system.vo.LoginUser;

/**
 * <p>
 * 车辆验收项目 前端控制器
 * </p>
 *
 * @author xushuhan
 * @since 2023-09-11
 */
@RestController
@RequestMapping("/projects/vehicleCheckProject")
public class TbVehicleCheckProjectController {

	@Autowired
	private ITbVehicleCheckProjectService tbVehicleCheckProjectService;

	@AddSysLog(value = "车辆验收项目-列表查询")
	@GetMapping("/list")
	public Result<?> list(TbVehicleCheckProject item) {
		LambdaQueryWrapper<TbVehicleCheckProject> queryWrapper = QueryGenerator.initQueryWrapper(TbVehicleCheckProject.class, item);
		/*LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		if(sysUser!=null) {
			queryWrapper.likeRight(StringUtils.hasLength(sysUser.getOrgCode()),TbVehicleCheckProject::getSysOrgCode, sysUser.getOrgCode());
		}*/
		//queryWrapper.eq(TbVehicleCheckProject::getCancelFlag, CommonConstant.STATUS_1);
		queryWrapper.orderByDesc(TbVehicleCheckProject::getCreateTime);
		List<TbVehicleCheckProject> list = tbVehicleCheckProjectService.list(queryWrapper);
		return Result.ok(list);
	}

	@AddSysLog(value = "车辆验收项目-分页列表查询")
	@GetMapping("/page")
	public Result<?> page(TbVehicleCheckProject item,@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
						  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {

		LambdaQueryWrapper<TbVehicleCheckProject> queryWrapper = QueryGenerator.initQueryWrapper(TbVehicleCheckProject.class, item);
		/*LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		if(sysUser!=null) {
			queryWrapper.likeRight(StringUtils.hasLength(sysUser.getOrgCode()),TbVehicleCheckProject::getSysOrgCode, sysUser.getOrgCode());
		}*/
		queryWrapper.orderByDesc(TbVehicleCheckProject::getCreateTime);
		Page<TbVehicleCheckProject> page = new Page<TbVehicleCheckProject>(pageNo, pageSize);
		IPage<TbVehicleCheckProject> pageList = tbVehicleCheckProjectService.page(page,queryWrapper);
		return Result.ok(pageList);
	}

	@AddSysLog(value = "车辆验收项目-添加")
	@PostMapping("/add")
	public Result<?> add(@RequestBody TbVehicleCheckProject item){
		tbVehicleCheckProjectService.save(item);
		return Result.ok();
	}

	@AddSysLog(value = "车辆验收项目-编辑")
	@PutMapping("/edit")
	public Result<?> edit(@RequestBody TbVehicleCheckProject item){
		tbVehicleCheckProjectService.updateById(item);
		return Result.ok();
	}

	@AddSysLog(value = "车辆验收项目-删除")
	@DeleteMapping("/delete")
	public Result<?> delete(TbVehicleCheckProject item){
		tbVehicleCheckProjectService.removeById(item.getId());
		return Result.ok();
	}

}
