FeatureController.java 4.05 KB
package com.objecteye.controller;

import com.objecteye.common.CommonResult;
import com.objecteye.entity.PageResult;
import com.objecteye.entity.SyFeature;
import com.objecteye.service.DeployService;
import com.objecteye.service.FeatureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * controller
 *
 * @author YU MIU
 */
@RestController
@Api(tags = "FeatureController", description = "人像库管理")
@RequestMapping("/feature")
@CrossOrigin
public class FeatureController {

    @Autowired
    private FeatureService featureService;
    @Autowired
    private DeployService deployService;

    /**
     * 人像库下拉框
     *
     * @return
     */
    @ApiOperation("人像库下拉框")
    @RequestMapping(value = "/findAllName", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public CommonResult findAllName() {
        List<Map<String, String>> all = featureService.findAllName();
        if (all != null) {
            return CommonResult.success(all);
        }
        return CommonResult.success("", "人像库为空");
    }

    /**
     * 返回全部列表
     *
     * @return
     */
    @ApiOperation("分页返回全部人像库")
    @RequestMapping(value = "/findPage", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public CommonResult findPage(@RequestParam int currentpage, @RequestParam int pagevolume) {
        PageResult page = featureService.findPage(currentpage, pagevolume);
        if (page != null) {
            return CommonResult.success(page);
        }
        return CommonResult.success("", "无符合条件的数据");
    }

    /**
     * 增加
     *
     * @param feature
     * @return
     */
    @ApiOperation("添加人像库")
    @RequestMapping(value = "/add", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public CommonResult add(@RequestBody SyFeature feature) {

        int count = featureService.add(feature);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    /**
     * @param feature
     * @return
     */
    @ApiOperation("更新人像库")
    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public CommonResult update(@RequestBody SyFeature feature) {
        int count = featureService.update(feature);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    /**
     * 批量删除
     *
     * @param
     * @return
     */
    @ApiOperation("删除人像库")
    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public CommonResult delete(@RequestBody Map<String, int[]> map) {
        try {
            int[] ids = map.get("ids");
            featureService.delete(ids);
            return CommonResult.success("操作成功");
        } catch (RuntimeException e) {
            e.printStackTrace();
            return CommonResult.failed();
        } catch (Exception e) {
            return CommonResult.failed();
        }
    }

    /**
     * 判断人像库是否被使用
     *
     * @param map 请求参数
     * @return 操作状态
     */
    @ApiOperation("判断人像库是否被使用")
    @RequestMapping(value = "/checkDelete", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public CommonResult checkDelete(@RequestBody Map<String, Integer> map) {
        List<Integer> deploys = deployService.getDeployListByLibAndDeployType(map.get("id"), 2);
        if (deploys != null && deploys.size() > 0) {
            return CommonResult.success(201, "存在布控任务使用该人像库", "");
        } else {
            return CommonResult.success(200, "不存在布控任务使用该人像库", "");
        }
    }
}