package com.mosty.yjzl.controller;

import com.mosty.base.model.dto.yjzl.TbZdxlFgmrpzUpdateDTO;
import com.mosty.base.utils.MessageUtils;
import com.mosty.base.utils.spring.SpringValidUtils;
import com.mosty.common.base.domain.ResponseResult;
import com.mosty.common.base.entity.log.BusinessType;
import com.mosty.common.base.entity.log.Log;
import com.mosty.common.base.util.StringUtils;
import com.mosty.common.token.JwtSysUser;
import com.mosty.yjzl.service.TbZdxlFgmrpzService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.BindingResult;
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 javax.validation.Valid;

/**
 * @author zhangzhao
 * @description 指导巡逻方格默认配置接口
 * @modifier zhangzhao
 * @modifiedTime 2025/09/05 18:58
 * @since 2025/09/05 18:58
 */
@Api(tags = {"指导巡逻-方格默认配置接口"})
@RestController
@AllArgsConstructor
@RequestMapping("/tbZdxlFgmrpz")
public class TbZdxlFgmrpzController {

    /**
     * 指导巡逻方格默认配置表Service
     */
    private final TbZdxlFgmrpzService tbZdxlFgmrpzService;

    /**
     * 修改单条
     * @param dto 修改DTO对象
     * @param bindResult 校验对象
     * @return ResponseResult 实体主键ID
     */
    @ApiOperation(value = "修改单条")
    @PostMapping("update")
    @JwtSysUser
    @Log(title = "指导巡逻-方格默认配置接口-修改单条", businessType = BusinessType.UPDATE)
    public ResponseResult<String> update(@RequestBody @Valid TbZdxlFgmrpzUpdateDTO dto, BindingResult bindResult){
        try {
            //基础信息校验
            String message = SpringValidUtils.getErrorsMsg(bindResult);
            if (StringUtils.isNotBlank(message)) {
                return ResponseResult.fail(MessageUtils.getEditFailMsg() + message);
            }

            //修改
            String resultId = tbZdxlFgmrpzService.updateEntity(dto);
            if(StringUtils.isNotBlank(resultId)){
                return ResponseResult.success(resultId);
            }
            return ResponseResult.fail(MessageUtils.getEditFailMsg());
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.fail(MessageUtils.getEditServerErrorMsg());
        }
    }

}
