package cn.lihongjie.coal.coalAnalysis.controller;

import cn.lihongjie.coal.annotation.OrgScope;
import cn.lihongjie.coal.annotation.SysLog;
import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.coalAnalysis.dto.CoalAnalysisDto;
import cn.lihongjie.coal.coalAnalysis.dto.CreateCoalAnalysisDto;
import cn.lihongjie.coal.coalAnalysis.dto.UpdateCoalAnalysisDto;
import cn.lihongjie.coal.coalAnalysis.service.CoalAnalysisService;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
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;

@RestController
@RequestMapping("/coalAnalysis")
@SysLog(module = "煤源化验")
@Slf4j
@OrgScope
public class CoalAnalysisController {
    @Autowired private CoalAnalysisService service;

    @PostMapping("/create")
    public CoalAnalysisDto create(@RequestBody CreateCoalAnalysisDto request) {
        return this.service.create(request);
    }

    @PostMapping("/calculate")
    public CoalAnalysisDto calculate(@RequestBody CoalAnalysisDto request) {
        return this.service.calculate(request);
    }

    @PostMapping("/update")
    public CoalAnalysisDto update(@RequestBody UpdateCoalAnalysisDto request) {
        return this.service.update(request);
    }

    @PostMapping("/delete")
    public Object delete(@RequestBody IdRequest request) {
        this.service.delete(request);
        return true;
    }

    @PostMapping("/archive")
    @SysLog(action = "归档")
    public Object archive(@RequestBody IdRequest dto) {
        this.service.archive(dto);
        return true;
    }

    @PostMapping("/unarchive")
    @SysLog(action = "取消归档")
    public Object unarchive(@RequestBody IdRequest dto) {
        this.service.unarchive(dto);
        return true;
    }
    @PostMapping("/getById")
    public CoalAnalysisDto getById(@RequestBody IdRequest request) {
        return this.service.getById(request.getId());
    }

    @PostMapping("/list")
    public Page<CoalAnalysisDto> list(@RequestBody CommonQuery request) {
        return this.service.list(request);
    }
}
