package com.skr.mdm.api.user.controller;

import com.skr.mdm.api.user.service.AuLabelService;
import com.skr.mdm.dto.LoginAdminDTO;
import com.skr.mdm.result.ResponseResult;
import com.skr.mdm.entity.AuLabelDO;
import com.skr.mdm.bean.qo.controller.UserManagerQO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
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.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @ProjectName: mdm_new
 * @Package: com.skr.mdm.userManagement.controller
 * @ClassName: AuLableManagementController
 * @Author: tty
 * @Description: 标签管理
 * @Date: 2020/7/13 19:11
 * @Version: 1.0
 */
@RestController
@RequestMapping("/AuLabel")
@Api(value = "标签管理", tags = "标签")
public class AuLabelManagementController {

	@Autowired
	private AuLabelService auLabelService;


	@ApiOperation("获取标签分页信息")
	@PostMapping("listAuLabelManagement")
//	@PreAuthorize("hasAnyAuthority('sys:user:label:list')")
	public ResponseResult listAuLabelManagement(@RequestBody UserManagerQO userManagerQO,
												@ApiIgnore Authentication authentication) {
		LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
		ResponseResult responseResult = auLabelService.listAuLabelManagement(userManagerQO, loginAdminDTO.getCompanyId());
		return responseResult;
	}

	@ApiOperation("添加标签信息")
	@PostMapping("addAuLabel")
	@PreAuthorize("hasAnyAuthority('sys:user:label:add')")
	public ResponseResult addAuLabel(AuLabelDO auLabelDo, @ApiIgnore Authentication authentication) {
		LoginAdminDTO admin = (LoginAdminDTO) authentication.getPrincipal();
		return auLabelService.addAuLabel(auLabelDo, admin);
	}

	@ApiOperation("删除标签信息")
	@PostMapping("delAuLabel")
	@PreAuthorize("hasAnyAuthority('sys:user:label:delete')")
	public ResponseResult delAuLabel(@ApiParam("标签id") String auLabelId, @ApiIgnore Authentication authentication) {
		LoginAdminDTO admin = (LoginAdminDTO) authentication.getPrincipal();
		ResponseResult responseResult = auLabelService.delAuLabel(auLabelId, admin);
		return responseResult;
	}

	@ApiOperation("查看标签信息")
	@PostMapping("getAuLabelInfo")
	@PreAuthorize("hasAnyAuthority('sys:user:label:list')")
	public ResponseResult getAuLabelInfo(@ApiParam("标签id") Integer auLabelId) {
		ResponseResult responseResult = auLabelService.getAuLabelInfo(auLabelId);
		return responseResult;
	}

	@ApiOperation("修改标签信息")
	@PostMapping("updateAuLabel")
	@PreAuthorize("hasAnyAuthority('sys:user:label:update')")
	public ResponseResult updateAuLabel(AuLabelDO auLabelDo, @ApiIgnore Authentication authentication) {
		LoginAdminDTO admin = (LoginAdminDTO) authentication.getPrincipal();
		ResponseResult responseResult = auLabelService.updateAuLabel(auLabelDo, admin);
		return responseResult;
	}

}