package com.codvision.basic.controller.patrol;


import com.codvision.basic.entity.patrol.PatrolClueType;
import com.codvision.basic.entity.vo.patrol.PatrolClueTypeVO;
import com.codvision.basic.service.patrol.PatrolClueTypeService;
import com.codvision.commoncore.common.ResponseEntity;
import com.codvision.commoncore.exception.BusinessException;
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.HashMap;
import java.util.List;


/**
 * @author codvision
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/patrolClueType")
public class PatrolClueTypeController {

    private final PatrolClueTypeService service;

    @PostMapping("/findAll")
    @ApiOperation("通用查询")
    public ResponseEntity<List<PatrolClueTypeVO>> findAll() {
        return new ResponseEntity<List<PatrolClueTypeVO>>().data(service.findAll(new HashMap<>(2)));
    }

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

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

}

