package cn.wise.sc.energy.power.plant.business.controller;

import cn.hutool.core.util.StrUtil;
import cn.wise.sc.energy.power.plant.business.domain.PageQuery;
import cn.wise.sc.energy.power.plant.business.domain.UserInfo;
import cn.wise.sc.energy.power.plant.business.domain.UserInfoQuery;
import cn.wise.sc.energy.power.plant.business.service.IUserInfoService;
import cn.wise.sc.energy.power.plant.common.core.bean.BaseResponse;
import org.springframework.data.domain.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
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;

/**
 * @description: 用户信息
 * @author: qh
 * @create: 2020-08-12 11:28
 **/
@Validated
@CrossOrigin
@RestController
//@Api(tags = "用户管理")
@RequestMapping("userInfo/")
public class UserInfoController {

    final
    IUserInfoService iUserInfoService;

    public UserInfoController(IUserInfoService iUserInfoService) {
        this.iUserInfoService = iUserInfoService;
    }

    @GetMapping("/page")
    public BaseResponse<Page<UserInfo>> page(PageQuery page, String username, String plantId) {

        if (StrUtil.isBlank(plantId)){
            return BaseResponse.errorMsg("电厂id不能为空！");
        }
        return iUserInfoService.page(page.getPageNo(),
                page.getPageSize(), username, plantId);
    }

    @PostMapping("/new")
    public BaseResponse<Boolean> add(@RequestBody UserInfoQuery userInfo) {
        return iUserInfoService.addUserInfo(userInfo);
    }

    @PostMapping("/edit")
    public BaseResponse<Boolean> edit(@RequestBody UserInfoQuery userInfo) {
        return iUserInfoService.edit(userInfo);
    }

    @PostMapping("/del")
    public BaseResponse<Boolean> del(String id){
        return iUserInfoService.del(id);
    }
}
