package com.kuyuntech.vrv.corerestful.controller.core;

import com.kuyuntech.vrv.coreapi.service.core.DeviceAlarmRepairRecordService;
import com.kuyuntech.vrv.coreapi.bean.core.DeviceAlarmRepairRecordBean;
import com.wbspool.fastboot.core.common.bean.ResponseBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wbspool.fastboot.core.web.result.ParamErrorResultBuilder;
import com.wbspool.fastboot.core.common.bean.PagerBean;
import java.util.Map;
import com.wbspool.fastboot.core.common.builder.MapBuilder;
import com.wbspool.fastboot.core.web.annotation.ParamErrorAutoResponse;
import org.springframework.validation.annotation.Validated;
import org.springframework.validation.Errors;
import com.wbspool.fastboot.core.common.constant.ValidGroup;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;




/**
* DeviceAlarmRepairRecordController
*
*/
@RestController
public class DeviceAlarmRepairRecordController {

    private static final Logger logger = LoggerFactory.getLogger(DeviceAlarmRepairRecordController.class);

    @Autowired
    DeviceAlarmRepairRecordService deviceAlarmRepairRecordService;

    

    /**
    * 新增
    * TODO 待实现
    * @param deviceAlarmRepairRecordBean 新增参数
    * @return
    *
    */
    @RequestMapping
    @ParamErrorAutoResponse
    public Object add(@Validated(ValidGroup.Add.class) DeviceAlarmRepairRecordBean deviceAlarmRepairRecordBean){

         deviceAlarmRepairRecordBean = this.deviceAlarmRepairRecordService.add(deviceAlarmRepairRecordBean);


         if (deviceAlarmRepairRecordBean == null) {
               return ResponseBean.serverError("操作失败！");
         }

          return ResponseBean.success("操作成功！").addData("code", deviceAlarmRepairRecordBean.getCode());

    }

    /**
    * 更新
    * TODO 待实现
    * @param deviceAlarmRepairRecordBean 更新参数
    * @return
    */
    @RequestMapping
    @ParamErrorAutoResponse
    public Object update(@Validated(ValidGroup.Update.class) DeviceAlarmRepairRecordBean deviceAlarmRepairRecordBean){

       deviceAlarmRepairRecordBean = this.deviceAlarmRepairRecordService.update(deviceAlarmRepairRecordBean);


       if (deviceAlarmRepairRecordBean == null) {
           return ResponseBean.serverError("操作失败！");
       }

       return ResponseBean.success("操作成功！").addData("code", deviceAlarmRepairRecordBean.getCode());

    }


    /**
    * 删除
    * TODO 待实现
    * @param deviceAlarmRepairRecordBean 删除参数
    * @return
    */
    @RequestMapping
    @ParamErrorAutoResponse
    public Object delete(@Validated(ValidGroup.Delete.class) DeviceAlarmRepairRecordBean deviceAlarmRepairRecordBean){

         deviceAlarmRepairRecordBean = this.deviceAlarmRepairRecordService.delete(deviceAlarmRepairRecordBean);

          if (deviceAlarmRepairRecordBean == null) {
             return ResponseBean.serverError("操作失败！");
          }

          return ResponseBean.success("操作成功！");

    }


    /**
    * 查询列表
    * TODO 待实现
    * @param deviceAlarmRepairRecordBean 查询参数
    * @return
    */
    @RequestMapping
    public Object list(DeviceAlarmRepairRecordBean deviceAlarmRepairRecordBean, PagerBean pagerBean){

        PagerBean<DeviceAlarmRepairRecordBean> deviceAlarmRepairRecordBeanPagerBean = this.deviceAlarmRepairRecordService.findPager(deviceAlarmRepairRecordBean,pagerBean);

        List<Map> deviceAlarmRepairRecordMapList = new ArrayList<>();

        deviceAlarmRepairRecordBeanPagerBean.getItems().forEach((e) ->{
             Map deviceAlarmRepairRecordMap = MapBuilder.newBuilder()
                                            .put("sn",e.getSn())
                                            .put("deviceCode",e.getDeviceCode())
                                            .put("operatorNumber",e.getOperatorNumber())
                                            .put("operatorCode",e.getOperatorCode())
                                            .put("projectNumber",e.getProjectNumber())
                                            .put("projectCode",e.getProjectCode())
                                            .put("gatewayNumber",e.getGatewayNumber())
                                            .put("gatewayCode",e.getGatewayCode())
                                            .put("repairName",e.getRepairName())
                                            .put("variableId",e.getVariableId())
                                            .put("promptInterval",e.getPromptInterval())
                                            .put("status",e.getStatus())
                                            .put("lastCreateTime",e.getLastCreateTime())
                                            .put("repairType",e.getRepairType())
                                            .put("code",e.getCode())
                                            .put("createTime",e.getCreateTime())
                                            .put("updateTime",e.getUpdateTime())
                                            .build();
                    deviceAlarmRepairRecordMapList.add(deviceAlarmRepairRecordMap);
             });


                return ResponseBean.success("操作成功！").addData("deviceAlarmRepairRecords",deviceAlarmRepairRecordMapList).addData("pager",deviceAlarmRepairRecordBeanPagerBean.simplePager());

    }



    /**
    * 查询详情
    * TODO 待实现
    * @param deviceAlarmRepairRecordBean 查询参数
    * @return
    */
    @RequestMapping
    @ParamErrorAutoResponse
    public Object detail(@Validated(ValidGroup.Detail.class) DeviceAlarmRepairRecordBean deviceAlarmRepairRecordBean,Errors errors){

           deviceAlarmRepairRecordBean = this.deviceAlarmRepairRecordService.find(deviceAlarmRepairRecordBean);

                if(deviceAlarmRepairRecordBean == null){
                    return  ResponseBean.serverError("该记录不存在!");
                }

                Map deviceAlarmRepairRecordMap = MapBuilder.newBuilder()
                        .put("sn",deviceAlarmRepairRecordBean.getSn())
                        .put("deviceCode",deviceAlarmRepairRecordBean.getDeviceCode())
                        .put("operatorNumber",deviceAlarmRepairRecordBean.getOperatorNumber())
                        .put("operatorCode",deviceAlarmRepairRecordBean.getOperatorCode())
                        .put("projectNumber",deviceAlarmRepairRecordBean.getProjectNumber())
                        .put("projectCode",deviceAlarmRepairRecordBean.getProjectCode())
                        .put("gatewayNumber",deviceAlarmRepairRecordBean.getGatewayNumber())
                        .put("gatewayCode",deviceAlarmRepairRecordBean.getGatewayCode())
                        .put("repairName",deviceAlarmRepairRecordBean.getRepairName())
                        .put("variableId",deviceAlarmRepairRecordBean.getVariableId())
                        .put("promptInterval",deviceAlarmRepairRecordBean.getPromptInterval())
                        .put("status",deviceAlarmRepairRecordBean.getStatus())
                        .put("lastCreateTime",deviceAlarmRepairRecordBean.getLastCreateTime())
                        .put("repairType",deviceAlarmRepairRecordBean.getRepairType())
                        .put("code",deviceAlarmRepairRecordBean.getCode())
                        .put("createTime",deviceAlarmRepairRecordBean.getCreateTime())
                        .put("updateTime",deviceAlarmRepairRecordBean.getUpdateTime())
                        .build();

        return ResponseBean.success("操作成功！").addData("deviceAlarmRepairRecord",deviceAlarmRepairRecordMap);

    }

    /**
    * 批量删除
    * @param codes 删除唯一标识集合
    * @return
    */
    @RequestMapping
    public Object batchDelete(List<String> codes){

        if(codes.isEmpty()){
            return ParamErrorResultBuilder.newBuilder().message("未选择任何删除记录！").paramError("codes","不能为空！").build();
        }

        try{
            this.deviceAlarmRepairRecordService.batchDeleteByCodes(codes);
        }catch (Exception e){
            return  ResponseBean.serverError("操作失败！");
        }


        return ResponseBean.success("操作成功！");
    }

    

}
