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.PcFactoryCoordinateOperationLog;
import cn.cecep.talroad.service.IPcFactoryCoordinateOperationLogService;
import cn.cecep.talroad.vo.PcFactoryCoordinateOperationLogVo;
import cn.cecep.talroad.vo.query.PcFactoryCoordinateOperationLogQuery;
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("/pcFactoryCoordinateOperationLog")
public class PcFactoryCoordinateOperationLogController  extends BasesController{
	@Autowired
	private IPcFactoryCoordinateOperationLogService pcFactoryCoordinateOperationLogService;
	
    /**
	 * 查询企业坐标操作记录表列表
	 */
	@ApiOperation(value = "查询企业坐标操作记录表列表")
	@GetMapping("/list")
	public AjaxResults<IPage<PcFactoryCoordinateOperationLog>> list(PcFactoryCoordinateOperationLogQuery pcFactoryCoordinateOperationLog) {
		Long roleId = SecurityUtils.getLoginUser().getSysUser().getRoles().get(0).getRoleId();
		if(ObjectUtil.equal(roleId,10L)) {
			String factoryId = SecurityUtils.getLoginUser().getSysUser().getFactoryId();
			pcFactoryCoordinateOperationLog.setFactoryId(factoryId);
		}
		Page<PcFactoryCoordinateOperationLog> page = new Page<>(pcFactoryCoordinateOperationLog.getPageNum(), pcFactoryCoordinateOperationLog.getPageSize());
		IPage<PcFactoryCoordinateOperationLog> list = pcFactoryCoordinateOperationLogService.page(page, PcFactoryCoordinateOperationLogQuery.createLambdaQueryWrapper(pcFactoryCoordinateOperationLog));
		return AjaxResults.success(list);
	}

	/**
	 * 导出企业坐标操作记录表列表
	 */
	@ApiOperation(value = "导出企业坐标操作记录表列表")
	@Log(title = "企业坐标操作记录表", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, PcFactoryCoordinateOperationLogQuery pcFactoryCoordinateOperationLogQuery) {
		List<PcFactoryCoordinateOperationLog> list = pcFactoryCoordinateOperationLogService.list(PcFactoryCoordinateOperationLogQuery.createLambdaQueryWrapper(pcFactoryCoordinateOperationLogQuery));
		ExcelUtil<PcFactoryCoordinateOperationLog> util = new ExcelUtil<PcFactoryCoordinateOperationLog>(PcFactoryCoordinateOperationLog.class);
		util.exportExcel(response, list, "企业坐标操作记录表");
	}

	/**
	 * 获取企业坐标操作记录表详细信息
	 */
	@ApiOperation(value = "获取企业坐标操作记录表详细信息")
	@GetMapping(value = "/{id}")
	public AjaxResults<PcFactoryCoordinateOperationLog> getInfo(@PathVariable("id") String id) {
		return AjaxResults.success(pcFactoryCoordinateOperationLogService.getById(id));
	}

	/**
	 * 新增企业坐标操作记录表
	 */
	@ApiOperation(value = "新增企业坐标操作记录表")
	@Log(title = "企业坐标操作记录表", businessType = BusinessType.INSERT)
	@PostMapping(value = "/add")
	public AjaxResults<Boolean> add(@RequestBody PcFactoryCoordinateOperationLogVo pcFactoryCoordinateOperationLogVo) {
		PcFactoryCoordinateOperationLog pcFactoryCoordinateOperationLog = new PcFactoryCoordinateOperationLog();
		BeanUtils.copyBeanProp(pcFactoryCoordinateOperationLogVo, pcFactoryCoordinateOperationLog);
		return pcFactoryCoordinateOperationLogService.save(pcFactoryCoordinateOperationLog) ? AjaxResults.success() : AjaxResults.error(300001, "新增失败");
	}

	/**
	 * 修改企业坐标操作记录表
	 */
	@ApiOperation(value = "修改企业坐标操作记录表")
	@Log(title = "企业坐标操作记录表", businessType = BusinessType.UPDATE)
	@PostMapping(value = "/edit")
	public AjaxResults<Boolean> edit(@RequestBody PcFactoryCoordinateOperationLogVo pcFactoryCoordinateOperationLogVo) {
		PcFactoryCoordinateOperationLog pcFactoryCoordinateOperationLog = pcFactoryCoordinateOperationLogService.getById(pcFactoryCoordinateOperationLogVo.getLogId());
		if (ObjectUtil.isNull(pcFactoryCoordinateOperationLog)) {
			return AjaxResults.error(300002, "修改失败");
		}
		// 赋值
		BeanUtil.copyProperties(pcFactoryCoordinateOperationLogVo, pcFactoryCoordinateOperationLog);
		return pcFactoryCoordinateOperationLogService.saveOrUpdate(pcFactoryCoordinateOperationLog) ? AjaxResults.success() : 
			AjaxResults.error(300003, "修改失败");
	}

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