package com.jwipc.spe.controller;

import cn.hutool.core.util.StrUtil;
import com.jwipc.constant.EnableStatus;
import com.jwipc.page.PageView;
import com.jwipc.security.LoginUtil;
import com.jwipc.security.dto.CurrentUserDTO;
import com.jwipc.spe.dto.SupAppraiseDimensionDTO;
import com.jwipc.spe.logic.SupAppraiseDimensionLogic;
import com.jwipc.spe.model.query.SupAppraiseDimensionQuery;
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 java.util.List;

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

/**
 * @author Al
 * @create 2024-02-28 16:01
 * 考核指标
 */
@RestController
@RequestMapping(MODULE_ROOT + "/supAppraiseDimension/rest/")
@RequiredArgsConstructor
public class SupAppraiseDimensionRestController {
    private final SupAppraiseDimensionLogic supAppraiseDimensionLogic;

    /**
     * 列表
     *
     * @param query
     * @return
     */
    @RequestMapping("/list")
    public PageView list(SupAppraiseDimensionQuery query) {
        return supAppraiseDimensionLogic.findByPage(query);
    }

    /**
     * 列表数据
     *
     * @param query
     * @return
     */
    @RequestMapping("/listAll")
    public ResponseEntity<List<SupAppraiseDimensionDTO>> listAll(SupAppraiseDimensionQuery query) {
        query.setDimensionStatus(EnableStatus.ENABLE.getStatus());
        return ResponseEntity.ok(supAppraiseDimensionLogic.listAll(query));
    }

    /**
     * 保存更新
     *
     * @param param 参数
     */
    @PostMapping("/saveOrUpdate")
    public ResponseEntity saveOrUpdate(SupAppraiseDimensionDTO param) {
        supAppraiseDimensionLogic.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 = supAppraiseDimensionLogic.invalidOrEffectiveTarget(ids, status, user);
        if (!b) {
            return ResponseEntity.badRequest().body("操作失败");
        }
        return ResponseEntity.ok(StrUtil.EMPTY);
    }
}
