package cn.com.ty.lift.ud.dataBank.controller;

import java.util.List;

import cn.com.ty.lift.ud.dataBank.controller.query.LiftFaultCodeQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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;

import com.baomidou.mybatisplus.extension.service.IService;

import cn.com.ty.lift.ud.common.BaseController;
import cn.com.ty.lift.ud.common.DelReq;
import cn.com.ty.lift.ud.dataBank.mapper.entity.LiftFaultCodeEntity;
import cn.com.ty.lift.ud.dataBank.service.ILiftFaultCodeService;
import cn.com.xwy.boot.web.dto.RestResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 错误代码 API
 * 
 * @author Xson
 * @date 2020-04-23
 */
@Api(tags = "错误代码 API- 魏瑞锋")
@RestController
@RequestMapping("/api/liftFaultCodes")
public class LiftFaultCodeController extends BaseController<LiftFaultCodeEntity, LiftFaultCodeQuery> {

    private final Logger log = LoggerFactory.getLogger(LiftFaultCodeController.class);
    
    private @Autowired ILiftFaultCodeService liftFaultCodeService;

    @Override
    protected IService<LiftFaultCodeEntity> getService() {
        return liftFaultCodeService;
    }
    
    @PostMapping("/query-page")
    @ApiOperation(value = "分页查询")
    @Override
    public RestResponse getCondition(@RequestBody LiftFaultCodeQuery request) {
        return liftFaultCodeService.selectByExample(request);
    }
    
    @ApiOperation(value = "批量上架")
    @PostMapping("useBath")
    public RestResponse useBath(@RequestBody DelReq ids) {
    	liftFaultCodeService.updateByIds(ids.getIds(),1);
        return RestResponse.success( "上架成功");
    }
    
    @ApiOperation(value = "批量下架")
    @PostMapping("noUseBath")
    public RestResponse noUseBath(@RequestBody DelReq ids) {
    	liftFaultCodeService.updateByIds(ids.getIds(),0);
        return RestResponse.success( "下架成功");
    }
    
    @ApiOperation(value = "批量首页显示")
    @PostMapping("showIndex")
    public RestResponse showIndex(@RequestBody DelReq ids) {
    	liftFaultCodeService.updateTopFlagByIds(ids.getIds(),1);
        return RestResponse.success( "首页显示");
    }
    
    @ApiOperation(value = "取消批量首页显示")
    @PostMapping("noshowIndex")
    public RestResponse noshowIndex(@RequestBody DelReq ids) {
    	liftFaultCodeService.updateTopFlagByIds(ids.getIds(),0);
        return RestResponse.success( "取消首页显示");
    }
}