package com.jwipc.spe.controller;

import cn.hutool.core.util.StrUtil;
import com.jwipc.page.PageView;
import com.jwipc.security.LoginUtil;
import com.jwipc.security.dto.CurrentUserDTO;
import com.jwipc.spe.dto.SupAppraiseQuotaDTO;
import com.jwipc.spe.logic.SupAppraiseQuotaLogic;
import com.jwipc.spe.model.query.SupAppraiseQuotaQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.jwipc.spe.constant.ModuleConst.MODULE_ROOT;

/**
 * @author Al
 * @create 2024-02-28 16:01
 * 考核指标
 */
@RestController
@RequestMapping(MODULE_ROOT + "/supAppraiseQuota/rest/")
@RequiredArgsConstructor
public class SupAppraiseQuotaRestController {
    private final SupAppraiseQuotaLogic supAppraiseQuotaLogic;
    /**
     * 列表
     *
     * @param query
     * @return
     */
    @RequestMapping("/list")
    public PageView list(SupAppraiseQuotaQuery query) {
        return supAppraiseQuotaLogic.findByPage(query);
    }
    /**
     * 保存更新
     * @param param 参数
     */
    @PostMapping("/saveOrUpdate")
    public ResponseEntity saveOrUpdate(SupAppraiseQuotaDTO param){
        supAppraiseQuotaLogic.saveOrUpdate(param);
        return ResponseEntity.ok(true);
    }
    /**
     * 启用或停用考核指标数据
     *
     * @param ids 数据ID
     * @param status 1:启用 2:停用
     * @return 结果
     */
    @PostMapping("/invalidOrEffective")
    public ResponseEntity invalidOrEffectiveTarget(String ids, Integer status){
        final CurrentUserDTO user =  LoginUtil.getCurrentUser();
        final boolean b = supAppraiseQuotaLogic.invalidOrEffectiveTarget(ids, status, user);
        if(!b){
            return ResponseEntity.badRequest().body("操作失败");
        }
        return ResponseEntity.ok(StrUtil.EMPTY);
    }
}
