package com.codvision.basic.controller.patrol;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.codvision.basic.entity.patrol.PatrolClue;
import com.codvision.basic.entity.vo.patrol.PatrolClueVO;
import com.codvision.basic.service.patrol.PatrolClueService;
import com.codvision.commoncore.common.ResponseEntity;
import com.codvision.commoncore.exception.BusinessException;
import com.codvision.webcore.bean.QueryPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
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 java.util.Map;


/**
 * @author codvision
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/patrolClue")
@Api(tags = "巡查--线索")
public class PatrolClueController {

    private final PatrolClueService service;

    @PostMapping("/getPageResult")
    @ApiOperation("分页列表")
    public ResponseEntity<IPage<PatrolClueVO>> getPageResult(@RequestBody QueryPage<Map<String, Object>> queryPage) {
        return new ResponseEntity<IPage<PatrolClueVO>>().data(service.getPageResult(queryPage));
    }

    @PostMapping("/add")
    @ApiOperation("添加")
    public ResponseEntity<String> add(@Validated @RequestBody PatrolClue patrolclue) {
        service.save(patrolclue);
        return new ResponseEntity<String>().ok();
    }

    @PostMapping("/update")
    @ApiOperation("编辑")
    public ResponseEntity<String> update(@RequestBody PatrolClue patrolclue) {
        ResponseEntity<String> responseEntity = new ResponseEntity<>();
        if (patrolclue.getId() == null) {
            throw new BusinessException(30002);
        }
        service.updateById(patrolclue);
        return responseEntity.ok();
    }

}

