/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved. <a>http://www.cqcis.com</a>
 */
package com.crunii.micro.service.sysmgr.controller;

import com.crunii.micro.common.dto.PageReq;
import com.crunii.micro.common.dto.PageRsp;
import com.crunii.micro.common.dto.Result;
import com.crunii.micro.domain.entity.main.TfmProperty;
import com.crunii.micro.domain.entity.main.TfmPropertyValue;
import com.crunii.micro.service.sysmgr.dto.fm.*;
import com.crunii.micro.service.sysmgr.service.FmPropertyService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author 田平 create 2023-02-21 10:47:41
 */
@Api(value = "流程属性和属性值相关api")
@Controller
@Slf4j
@RequestMapping("/auth/FmPropertyController")
public class FmPropertyController {
	@Autowired
	private FmPropertyService fmPropertyService;

	@ApiOperation(value = "属性分页")
	@RequestMapping(path = "/pageProperty", method = RequestMethod.POST)
	@ResponseBody
	public Result<PageRsp<TfmProperty>> pageProperty(@RequestBody @ApiParam PageReq<FmPropertyReq> req) {
		log.info("req:" + req.toString());
		Result<PageRsp<TfmProperty>> result = new Result<>();
		result.setData(fmPropertyService.pageProperty(req));
		return result;
	}

	@ApiOperation(value = "属性值分页")
	@RequestMapping(path = "/pageValue", method = RequestMethod.POST)
	@ResponseBody
	public Result<PageRsp<TfmPropertyValue>> pageValue(@RequestBody @ApiParam PageReq<FmValueReq> req) {
		log.info("req:" + req.toString());
		Result<PageRsp<TfmPropertyValue>> result = new Result<>();
		result.setData(fmPropertyService.pageValue(req));
		return result;
	}

	@ApiOperation(value = "创建属性")
	@RequestMapping(path = "/createProperty", method = RequestMethod.POST)
	@ResponseBody
	public Result<String> createProperty(@RequestBody @ApiParam FmPropertyC propertyC) {
		Result<String> result = new Result<String>();
		fmPropertyService.createProperty(propertyC);
		return result;
	}

	@ApiOperation(value = "更新属性")
	@RequestMapping(path = "/updateProperty", method = RequestMethod.POST)
	@ResponseBody
	public Result<String> updateProperty(@RequestBody @ApiParam FmPropertyU propertyU) {
		Result<String> result = new Result<String>();
		fmPropertyService.updateProperty(propertyU);
		return result;
	}

	@ApiOperation(value = "创建属性值")
	@RequestMapping(path = "/createValue", method = RequestMethod.POST)
	@ResponseBody
	public Result<String> createValue(@RequestBody @ApiParam FmValueC valueC) {
		Result<String> result = new Result<String>();
		fmPropertyService.createValue(valueC);
		return result;
	}

	@ApiOperation(value = "更新属性值")
	@RequestMapping(path = "/updateValue", method = RequestMethod.POST)
	@ResponseBody
	public Result<String> updateValue(@RequestBody @ApiParam FmValueU valueU) {
		Result<String> result = new Result<String>();
		fmPropertyService.updateValue(valueU);
		return result;
	}

	@ApiOperation(value = "通过属性编码获取属性值列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "propCode", value = "属性编码", required = true)
	})
	@RequestMapping(path = "/getValuesByCode", method = RequestMethod.GET)
	@ResponseBody
	public Result<List<TfmPropertyValue>> getValuesByCode(String propCode) {
		Result<List<TfmPropertyValue>> result = new Result<>();
		result.setData(fmPropertyService.getValuesByCode(propCode));
		return result;
	}

}
