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.PcOutletCoordinateOperationLog;
import cn.cecep.talroad.service.IPcOutletCoordinateOperationLogService;
import cn.cecep.talroad.vo.PcOutletCoordinateOperationLogVo;
import cn.cecep.talroad.vo.query.PcOutletCoordinateOperationLogQuery;
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-19
 * @Version: V1.0
 */
@Api(tags = "在线监测,无组织点位,排口经纬度坐标操作记录表")
@RestController
@RequestMapping("/pcOutletCoordinateOperationLog")
public class PcOutletCoordinateOperationLogController  extends BasesController{
	@Autowired
	private IPcOutletCoordinateOperationLogService pcOutletCoordinateOperationLogService;
	
    /**
	 * 查询在线监测,无组织点位,排口经纬度坐标操作记录表列表
	 */
	@ApiOperation(value = "查询在线监测,无组织点位,排口经纬度坐标操作记录表列表")
	@GetMapping("/list")
	public AjaxResults<IPage<PcOutletCoordinateOperationLog>> list(PcOutletCoordinateOperationLogQuery pcOutletCoordinateOperationLog) {
		Long roleId = SecurityUtils.getLoginUser().getSysUser().getRoles().get(0).getRoleId();
		if(ObjectUtil.equal(roleId,10L)) {
			String factoryId = SecurityUtils.getLoginUser().getSysUser().getFactoryId();
			pcOutletCoordinateOperationLog.setFactoryId(factoryId);
		}
		Page<PcOutletCoordinateOperationLog> page = new Page<>(pcOutletCoordinateOperationLog.getPageNum(), pcOutletCoordinateOperationLog.getPageSize());
		IPage<PcOutletCoordinateOperationLog> list = pcOutletCoordinateOperationLogService.page(page, PcOutletCoordinateOperationLogQuery.createLambdaQueryWrapper(pcOutletCoordinateOperationLog));
		return AjaxResults.success(list);
	}

	/**
	 * 导出在线监测,无组织点位,排口经纬度坐标操作记录表列表
	 */
	@ApiOperation(value = "导出在线监测,无组织点位,排口经纬度坐标操作记录表列表")
	@Log(title = "在线监测,无组织点位,排口经纬度坐标操作记录表", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, PcOutletCoordinateOperationLogQuery pcOutletCoordinateOperationLogQuery) {
		List<PcOutletCoordinateOperationLog> list = pcOutletCoordinateOperationLogService.list(PcOutletCoordinateOperationLogQuery.createLambdaQueryWrapper(pcOutletCoordinateOperationLogQuery));
		ExcelUtil<PcOutletCoordinateOperationLog> util = new ExcelUtil<PcOutletCoordinateOperationLog>(PcOutletCoordinateOperationLog.class);
		util.exportExcel(response, list, "在线监测,无组织点位,排口经纬度坐标操作记录表");
	}

	/**
	 * 获取在线监测,无组织点位,排口经纬度坐标操作记录表详细信息
	 */
	@ApiOperation(value = "获取在线监测,无组织点位,排口经纬度坐标操作记录表详细信息")
	@GetMapping(value = "/{id}")
	public AjaxResults<PcOutletCoordinateOperationLog> getInfo(@PathVariable("id") String id) {
		return AjaxResults.success(pcOutletCoordinateOperationLogService.getById(id));
	}

	/**
	 * 新增在线监测,无组织点位,排口经纬度坐标操作记录表
	 */
	@ApiOperation(value = "新增在线监测,无组织点位,排口经纬度坐标操作记录表")
	@Log(title = "在线监测,无组织点位,排口经纬度坐标操作记录表", businessType = BusinessType.INSERT)
	@PostMapping(value = "/add")
	public AjaxResults<Boolean> add(@RequestBody PcOutletCoordinateOperationLogVo pcOutletCoordinateOperationLogVo) {
		PcOutletCoordinateOperationLog pcOutletCoordinateOperationLog = new PcOutletCoordinateOperationLog();
		BeanUtils.copyBeanProp(pcOutletCoordinateOperationLogVo, pcOutletCoordinateOperationLog);
		return pcOutletCoordinateOperationLogService.save(pcOutletCoordinateOperationLog) ? AjaxResults.success() : AjaxResults.error(300001, "新增失败");
	}

	/**
	 * 修改在线监测,无组织点位,排口经纬度坐标操作记录表
	 */
	@ApiOperation(value = "修改在线监测,无组织点位,排口经纬度坐标操作记录表")
	@Log(title = "在线监测,无组织点位,排口经纬度坐标操作记录表", businessType = BusinessType.UPDATE)
	@PostMapping(value = "/edit")
	public AjaxResults<Boolean> edit(@RequestBody PcOutletCoordinateOperationLogVo pcOutletCoordinateOperationLogVo) {
		PcOutletCoordinateOperationLog pcOutletCoordinateOperationLog = pcOutletCoordinateOperationLogService.getById(pcOutletCoordinateOperationLogVo.getLogId());
		if (ObjectUtil.isNull(pcOutletCoordinateOperationLog)) {
			return AjaxResults.error(300002, "修改失败");
		}
		// 赋值
		BeanUtil.copyProperties(pcOutletCoordinateOperationLogVo, pcOutletCoordinateOperationLog);
		return pcOutletCoordinateOperationLogService.saveOrUpdate(pcOutletCoordinateOperationLog) ? AjaxResults.success() : 
			AjaxResults.error(300003, "修改失败");
	}

	/**
	 * 删除在线监测,无组织点位,排口经纬度坐标操作记录表
	 */
	@ApiOperation(value = "删除在线监测,无组织点位,排口经纬度坐标操作记录表")
	// @RequiresPermissions("talroad:pcOutletCoordinateOperationLog:remove")
	@Log(title = "在线监测,无组织点位,排口经纬度坐标操作记录表", businessType = BusinessType.DELETE)
	@PostMapping("/{ids}")
	public AjaxResults<Boolean> remove(@PathVariable String[] ids) {
		return pcOutletCoordinateOperationLogService.removeByIds(Arrays.asList(ids)) ? AjaxResults.success() : 
			AjaxResults.error(300004, "删除失败");
	}
}
