package com.dayou.controller;

import com.dayou.annotation.DataPermission;
import com.dayou.vo.UserTargetVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dayou.service.IUserTargetService;
import com.dayou.entity.UserTarget;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.dayou.common.Constants.MANAGER_OFFICE;

/**
 * 员工目标
 *
 * @author wucl
 * @since 2023-02-14
 */
@RestController
@RequestMapping("userTarget")
@Slf4j
public class UserTargetController extends BaseController {
    @Autowired
    private IUserTargetService userTargetService;

    @DataPermission(teamData = true,postChild = false,ignoreDepartment = {MANAGER_OFFICE})
    @GetMapping("/list")
    public RestResponse<List<UserTargetVO>> list(UserTargetVO userTargetVO){
        List<UserTargetVO> result = userTargetService.getList(userTargetVO);
        return RestResponse.data(result);
    }

    /**
     * 员工目标详情
     */
    @GetMapping("/{id}")
    public RestResponse<UserTarget> detail(@PathVariable Long id){
        UserTarget xUserTarget =userTargetService.detail(id);
        return RestResponse.data(xUserTarget);
     }

    /**
     * 员工目标新增
     */
    @PostMapping("")
    public RestResponse<Boolean> save(@RequestBody UserTarget userTarget) {
        Boolean ret = userTargetService.add(userTarget);
        return RestResponse.data(ret);
    }

}

