/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.feesapi.wxgl.wechatofficalacctmgt.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.util.StringUtil;
import com.tofly.feesapi.common.core.ResultRespone;
import com.tofly.feesapi.wxgl.wechatofficalacctmgt.entity.WxLwsq;
import com.tofly.feesapi.wxgl.wechatofficalacctmgt.entity.dto.WxCommonDto;
import com.tofly.feesapi.wxgl.wechatofficalacctmgt.entity.dto.WxywclDto;
import com.tofly.feesapi.wxgl.wechatofficalacctmgt.entity.vo.WxLwsqVo;
import com.tofly.feesapi.wxgl.wechatofficalacctmgt.service.WxLwsqService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 微信-漏水报障申请
 *
 * @author admin
 * @date Mon May 26 00:00:00 GMT+08:00 2025
 */
@RestController
@AllArgsConstructor
@RequestMapping("/wxlwsq")
@Api(tags="微信-漏水报障申请接口")
public class WxLwsqController {

    private final WxLwsqService wxLwsqService;
    /**
     * 分页查询
     *
     * @param page   分页对象
     * @param dto 微信-报修申请
     * @return
     */
    @GetMapping("/getpage")
    @ApiOperation(value = "报修申请分页查询")
    public ResultRespone<Page<WxLwsqVo>> getWxLwsqPage(Page page, @ModelAttribute WxCommonDto dto) {
        ResultRespone<Page<WxLwsqVo>> resultRespone = new ResultRespone<>();
        try {
            Page<WxLwsqVo> wxPage = wxLwsqService.getWxLwsqPage(page, dto);
            resultRespone.setCode(1);
            resultRespone.setResult(wxPage);
        } catch (RuntimeException e) {
            resultRespone.setCode(-1);
            resultRespone.setMessage(e.getMessage());
        }
        return resultRespone;
    }

    /**
    * 分页查询
    * @param page 分页对象
    * @param wxLwsq 微信-漏水报障申请
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getWxLwsqPage(Page page, @ModelAttribute WxLwsq wxLwsq) {
      return ResultRespone.success(wxLwsqService.page(page, Wrappers.query(wxLwsq)));
    }


    /**
     * 通过id查询微信-漏水报障申请
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}" )
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String")
    })
    public ResultRespone getById(@PathVariable("id" ) String id) {
      return ResultRespone.success(wxLwsqService.getById(id));
    }

    /**
     * 新增微信-漏水报障申请
     * @param wxLwsq 微信-漏水报障申请
     * @return ResultRespone
     */
    @ApiOperation(value = "新增微信-漏水报障申请")
    @PostMapping
    public ResultRespone save(@RequestBody WxLwsq wxLwsq) {
      return ResultRespone.success(wxLwsqService.save(wxLwsq));
    }

    /**
     * 修改微信-漏水报障申请
     * @param wxLwsq 微信-漏水报障申请
     * @return ResultRespone
     */
    @ApiOperation(value = "修改微信-漏水报障申请")
    @PutMapping
    public ResultRespone updateById(@RequestBody WxLwsq wxLwsq) {
      return ResultRespone.success(wxLwsqService.updateById(wxLwsq));
    }

    /**
     * 通过id删除微信-漏水报障申请
     * @param id id
     * @return ResultRespone
     */
    @ApiOperation(value = "通过ID删除微信-漏水报障申请")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String")
    })
    @DeleteMapping("/{id}" )
    public ResultRespone removeById(@PathVariable String id) {
      return ResultRespone.success(wxLwsqService.removeById(id));
    }

    /**
     * 通过id批量删除微信-漏水报障申请
     * @param ids id
     * @return ResultRespone
     */
    @ApiOperation(value = "通过ID批量删除微信-漏水报障申请")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds" )
    public ResultRespone removeByIds(String ids) {
        return ResultRespone.success(wxLwsqService.removeByIds(Arrays.asList(ids.split(","))));
    }

    /**
     * 批量审核-漏水报障申请
     *
     * @param dto 批量审核-漏水报障申请
     * @return ResultRespone
     */
    @ApiOperation(value = "批量审核-漏水报障申请")
    @PutMapping("/updateByIds")
    public ResultRespone updateByIds(@RequestBody WxywclDto dto) {
        if (dto.getIds().isEmpty()) {
            return ResultRespone.failed("请选择要审核的记录");
        }
        if (StringUtil.isEmpty(dto.getHandleName())) {
            return ResultRespone.failed("处理人不能为空");
        }
        if (StringUtil.isEmpty(dto.getState())) {
            return ResultRespone.failed("处理状态不能为空");
        }
        if (StringUtil.isNull(dto.getHandleDate())) {
            return ResultRespone.failed("处理时间不能为空");
        }
        if (StringUtil.isEmpty(dto.getHandleResult())) {
            return ResultRespone.failed("处理结果不能为空");
        }
        return ResultRespone.success(wxLwsqService.lambdaUpdate()
                .set(WxLwsq::getState, dto.getState())
                .set(WxLwsq::getHandleName, dto.getHandleName())
                .set(WxLwsq::getHandleDate, dto.getHandleDate())
                .set(WxLwsq::getHandleResult, dto.getHandleResult())
                .in(WxLwsq::getId, dto.getIds())
                .update());
    }
}
