package cn.cecep.talroad.controller;

import cn.cecep.talroad.common.core.utils.bean.BeanUtils;
import cn.cecep.talroad.common.core.utils.poi.ExcelUtil;
import cn.cecep.talroad.common.core.web.controller.BasesController;
import cn.cecep.talroad.common.core.web.domain.AjaxResults;
import cn.cecep.talroad.common.log.annotation.Log;
import cn.cecep.talroad.common.log.enums.BusinessType;
import cn.cecep.talroad.common.security.utils.SecurityUtils;
import cn.cecep.talroad.domain.PcFactoryAccessControlCoordinateOperationLog;
import cn.cecep.talroad.service.IPcFactoryAccessControlCoordinateOperationLogService;
import cn.cecep.talroad.vo.PcFactoryAccessControlCoordinateOperationLogVo;
import cn.cecep.talroad.vo.query.PcFactoryAccessControlCoordinateOperationLogQuery;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

 /**
 * @Description: 企业门禁坐标操作日志
 * @Author: code-generate
 * @Date:   2023-07-18
 * @Version: V1.0
 */
@Api(tags = "企业门禁坐标操作日志")
@RestController
@RequestMapping("/pcFactoryAccessControlCoordinateOperationLog")
public class PcFactoryAccessControlCoordinateOperationLogController  extends BasesController{
	@Autowired
	private IPcFactoryAccessControlCoordinateOperationLogService pcFactoryAccessControlCoordinateOperationLogService;
	
    /**
	 * 查询企业门禁坐标操作日志列表
	 */
	@ApiOperation(value = "查询企业门禁坐标操作日志列表")
	@GetMapping("/list")
	public AjaxResults<IPage<PcFactoryAccessControlCoordinateOperationLog>> list(PcFactoryAccessControlCoordinateOperationLogQuery pcFactoryAccessControlCoordinateOperationLog) {
		Long roleId = SecurityUtils.getLoginUser().getSysUser().getRoles().get(0).getRoleId();
		if(ObjectUtil.equal(roleId,10L)) {
			String factoryId = SecurityUtils.getLoginUser().getSysUser().getFactoryId();
			pcFactoryAccessControlCoordinateOperationLog.setFactoryId(factoryId);
		}
		Page<PcFactoryAccessControlCoordinateOperationLog> page = new Page<>(pcFactoryAccessControlCoordinateOperationLog.getPageNum(), pcFactoryAccessControlCoordinateOperationLog.getPageSize());
		IPage<PcFactoryAccessControlCoordinateOperationLog> list = pcFactoryAccessControlCoordinateOperationLogService.page(page, PcFactoryAccessControlCoordinateOperationLogQuery.createLambdaQueryWrapper(pcFactoryAccessControlCoordinateOperationLog));
		return AjaxResults.success(list);
	}

	/**
	 * 导出企业门禁坐标操作日志列表
	 */
	@ApiOperation(value = "导出企业门禁坐标操作日志列表")
	@Log(title = "企业门禁坐标操作日志", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, PcFactoryAccessControlCoordinateOperationLogQuery pcFactoryAccessControlCoordinateOperationLogQuery) {
		List<PcFactoryAccessControlCoordinateOperationLog> list = pcFactoryAccessControlCoordinateOperationLogService.list(PcFactoryAccessControlCoordinateOperationLogQuery.createLambdaQueryWrapper(pcFactoryAccessControlCoordinateOperationLogQuery));
		ExcelUtil<PcFactoryAccessControlCoordinateOperationLog> util = new ExcelUtil<PcFactoryAccessControlCoordinateOperationLog>(PcFactoryAccessControlCoordinateOperationLog.class);
		util.exportExcel(response, list, "企业门禁坐标操作日志");
	}

	/**
	 * 获取企业门禁坐标操作日志详细信息
	 */
	@ApiOperation(value = "获取企业门禁坐标操作日志详细信息")
	@GetMapping(value = "/{id}")
	public AjaxResults<PcFactoryAccessControlCoordinateOperationLog> getInfo(@PathVariable("id") String id) {
		return AjaxResults.success(pcFactoryAccessControlCoordinateOperationLogService.getById(id));
	}

	/**
	 * 新增企业门禁坐标操作日志
	 */
	@ApiOperation(value = "新增企业门禁坐标操作日志")
	@Log(title = "企业门禁坐标操作日志", businessType = BusinessType.INSERT)
	@PostMapping(value = "/add")
	public AjaxResults<Boolean> add(@RequestBody PcFactoryAccessControlCoordinateOperationLogVo pcFactoryAccessControlCoordinateOperationLogVo) {
		PcFactoryAccessControlCoordinateOperationLog pcFactoryAccessControlCoordinateOperationLog = new PcFactoryAccessControlCoordinateOperationLog();
		BeanUtils.copyBeanProp(pcFactoryAccessControlCoordinateOperationLogVo, pcFactoryAccessControlCoordinateOperationLog);
		return pcFactoryAccessControlCoordinateOperationLogService.save(pcFactoryAccessControlCoordinateOperationLog) ? AjaxResults.success() : AjaxResults.error(300001, "新增失败");
	}

	/**
	 * 修改企业门禁坐标操作日志
	 */
	@ApiOperation(value = "修改企业门禁坐标操作日志")
	@Log(title = "企业门禁坐标操作日志", businessType = BusinessType.UPDATE)
	@PostMapping(value = "/edit")
	public AjaxResults<Boolean> edit(@RequestBody PcFactoryAccessControlCoordinateOperationLogVo pcFactoryAccessControlCoordinateOperationLogVo) {
		PcFactoryAccessControlCoordinateOperationLog pcFactoryAccessControlCoordinateOperationLog = pcFactoryAccessControlCoordinateOperationLogService.getById(pcFactoryAccessControlCoordinateOperationLogVo.getLogId());
		if (ObjectUtil.isNull(pcFactoryAccessControlCoordinateOperationLog)) {
			return AjaxResults.error(300002, "修改失败");
		}
		// 赋值
		BeanUtil.copyProperties(pcFactoryAccessControlCoordinateOperationLogVo, pcFactoryAccessControlCoordinateOperationLog);
		return pcFactoryAccessControlCoordinateOperationLogService.saveOrUpdate(pcFactoryAccessControlCoordinateOperationLog) ? AjaxResults.success() : 
			AjaxResults.error(300003, "修改失败");
	}

	/**
	 * 删除企业门禁坐标操作日志
	 */
	@ApiOperation(value = "删除企业门禁坐标操作日志")
	// @RequiresPermissions("talroad:pcFactoryAccessControlCoordinateOperationLog:remove")
	@Log(title = "企业门禁坐标操作日志", businessType = BusinessType.DELETE)
	@PostMapping("/{ids}")
	public AjaxResults<Boolean> remove(@PathVariable String[] ids) {
		return pcFactoryAccessControlCoordinateOperationLogService.removeByIds(Arrays.asList(ids)) ? AjaxResults.success() : 
			AjaxResults.error(300004, "删除失败");
	}
}
