package com.prolog.rdc.tms.controller.basicConfigure;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
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.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.model.dto.basicConfigure.SignconfigPageDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.SignconfigPopDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.SignconfigViewDTO;
import com.prolog.rdc.tms.model.vo.basicConfigure.SignconfigPageVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.SignconfigPopVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.SignconfigSaveVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.SignconfigUpdateVO;
import com.prolog.rdc.tms.service.basicConfigure.SignconfigService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 标记配置表控制层
 *
 * @author zhangsj
 * @since 2022-04-26 15:50:54
 */
@RestController
@Api(tags = "基础配置-标记配置表控制层")
@RequestMapping("signconfig")
public class SignconfigController {

	@Autowired
	private SignconfigService service;

	@UserLog("标记配置分页查询")
	@ApiOperation(value = "标记配置分页查询", notes = "标记配置分页查询")
	@PostMapping("query")
	public RestMessage<Page<SignconfigPageDTO>> queryExecute(@RequestBody SignconfigPageVO signconfigPageVO) {
		try {
			Page<SignconfigPageDTO> page = service.queryData(signconfigPageVO);
			return RestMessage.newInstance(true, "查询成功", page);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("标记配置弹窗查询")
	@ApiOperation(value = "标记配置弹窗查询", notes = "标记配置弹窗查询")
	@PostMapping("get_list")
	public RestMessage<List<SignconfigPopDTO>> popExecute(@RequestBody SignconfigPopVO signconfigPopVO) {
		try {
			List<SignconfigPopDTO> list = service.popData(signconfigPopVO);
			return RestMessage.newInstance(true, "查询成功", list);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("标记配置查看")
	@ApiOperation(value = "标记配置查看", notes = "标记配置查看")
	@PostMapping("view")
	public RestMessage<SignconfigViewDTO> viewExecute(@RequestParam("id") Long id) {
		try {
			SignconfigViewDTO dto = service.viewData(id);
			return RestMessage.newInstance(true, "查看成功", dto);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("标记配置新增")
	@ApiOperation(value = "标记配置新增", notes = "标记配置新增")
	@PostMapping("save")
	public RestMessage<String> saveExecute(@RequestBody SignconfigSaveVO signconfigSaveVO) {
		try {
			String str = service.saveData(signconfigSaveVO);
			return RestMessage.newInstance(true, "新增成功", str);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("标记配置修改")
	@ApiOperation(value = "标记配置修改", notes = "标记配置修改")
	@PostMapping("update")
	public RestMessage<Long> updateExecute(@RequestBody SignconfigUpdateVO signconfigUpdateVO) {
		try {
			Long id = service.updateData(signconfigUpdateVO);
			return RestMessage.newInstance(true, "修改成功", id);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("标记配置删除")
	@ApiOperation(value = "标记配置删除", notes = "标记配置删除")
	@PostMapping("delete")
	public RestMessage<Object> deleteExecute(@RequestBody List<String> list) {
		try {
			service.deleteData(list);
			return RestMessage.newInstance(true, "删除成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}
}
