package com.hs.api.unusecontroller;

import com.hs.api.common.base.RequestResult;
import com.hs.api.common.enums.RequestResultType;
import com.hs.api.model.DicDim;
import com.hs.api.model.DicIndInfo;
import com.hs.api.model.respmodel.ListPage;
import com.hs.api.service.DicIndService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
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;

@Api(tags = {"指标库"}, hidden = true)
@RequestMapping("ind")
@RestController
public class DicIndController {
    @Autowired
    private DicIndService dicIndService;


    @GetMapping("list")
    public Object list() {
        List<DicIndInfo> list = dicIndService.findAll();
        return new RequestResult(RequestResultType.SUCCESS.getValue(),RequestResultType.SUCCESS.getDesc(),list);
    }

    @GetMapping("listpage")
    public Object listpage(Integer pageSize,Integer pageIndex) {
        List<DicIndInfo> list = dicIndService.findAll();
        ListPage<DicDim> listPage = new ListPage(list,pageSize,pageIndex,0);
        return new RequestResult(RequestResultType.SUCCESS.getValue(),RequestResultType.SUCCESS.getDesc(),list);
    }

    @GetMapping("info")
    public Object info(Long id) {
        dicIndService.find(id);
        return new RequestResult(RequestResultType.SUCCESS.getValue(),RequestResultType.SUCCESS.getDesc(),null);
    }

    @PostMapping("add")
    public Object add(DicIndInfo dicInd) {
        dicIndService.add(dicInd);
        return new RequestResult(RequestResultType.SUCCESS.getValue(),RequestResultType.SUCCESS.getDesc(),null);
    }

    @PostMapping("update")
    public Object update(DicIndInfo dicInd) {
        dicIndService.update(dicInd);
        return new RequestResult(RequestResultType.SUCCESS.getValue(),RequestResultType.SUCCESS.getDesc(),null);
    }

    @PostMapping("delete")
    public Object delete(Long id) {
        dicIndService.delete(id);
        return new RequestResult(RequestResultType.SUCCESS.getValue(),RequestResultType.SUCCESS.getDesc(),null);
    }
}
