package com.gyee.runeconomy.controller.update;/*
@author   谢生杰
@date   2023/5/16-9:54
*/

import com.gyee.common.model.StringUtils;
import com.gyee.runeconomy.dto.R;
import com.gyee.runeconomy.dto.ResultMsg;
import com.gyee.runeconomy.model.auto.ProBasicPowerstation;
import com.gyee.runeconomy.model.auto.ProBasicUser;
import com.gyee.runeconomy.model.auto.ProEconTargetdata;
import com.gyee.runeconomy.service.update.TargetEnterService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("//enter")
public class TargetEnterController {
    @Resource
    private TargetEnterService targetEnterService;


    @PostMapping(value = "/enter")
    @ApiOperation(value = "登录", notes = "登录")
    public R login(@RequestBody ProBasicUser user
    ) {
        ProBasicUser proBasicUser = targetEnterService.login(user);


        if (StringUtils.isNotNull(proBasicUser)) {
            return R.data(ResultMsg.ok(proBasicUser));
        } else {
            return R.error(ResultMsg.error());
        }
    }


    @PostMapping(value = "/target")
    @ApiOperation(value = "增", notes = "增")
    public R save(@RequestBody ProEconTargetdata data) {
        boolean b = targetEnterService.save(data);
        if (b) {
            return R.data(ResultMsg.ok(b));
        } else {
            return R.error(ResultMsg.error());
        }
    }


    @PutMapping(value = "/target")
    @ApiOperation(value = "改", notes = "改")
    public R update(@RequestBody ProEconTargetdata data) {
        boolean b = targetEnterService.update(data);
        if (b) {
            return R.data(ResultMsg.ok(b));
        } else {
            return R.error(ResultMsg.error());
        }
    }

    @DeleteMapping(value = "/target/{id}")
    @ApiOperation(value = "删", notes = "删")
    public R delete(@PathVariable String id) {
        boolean b = targetEnterService.delete(id);
        if (b) {
            return R.data(ResultMsg.ok(b));
        } else {
            return R.error(ResultMsg.error());
        }
    }

    @GetMapping(value = "/target")
    @ApiOperation(value = "查", notes = "查")
    public R get(@RequestParam(value = "wpid", required = true) String wpid,
                 @RequestParam(value = "date", required = true) String date) {
        List<ProEconTargetdata> resultList = targetEnterService.get(wpid, date);
        if (StringUtils.isNotNull(resultList)) {
            return R.data(ResultMsg.ok(resultList));
        } else {
            return R.error(ResultMsg.error());
        }
    }


    @GetMapping(value = "/wpls")
    @ApiOperation(value = "查场站", notes = "查场站")
    public R wpls(@RequestParam(value = "wpid", required = true) String wpid) {
        List<ProBasicPowerstation> resultList = targetEnterService.wpls(wpid);
        if (StringUtils.isNotNull(resultList)) {
            return R.data(ResultMsg.ok(resultList));
        } else {
            return R.error(ResultMsg.error());
        }
    }


}
