mg
2022-10-02 0d931fe3d16e11b9a94787380c0bc6e9e0696dba
ycl-platform/src/main/java/com/ycl/controller/caseHandler/BaseCaseController.java
@@ -1,10 +1,32 @@
package com.ycl.controller.caseHandler;
import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ycl.api.CommonResult;
import com.ycl.controller.BaseController;
import org.springframework.web.bind.annotation.RequestMapping;
import com.ycl.dto.casePool.IllegalBuildingParam;
import com.ycl.dto.casePool.ViolationParam;
import com.ycl.entity.caseHandler.BaseCase;
import com.ycl.entity.caseHandler.BaseCaseDetail;
import com.ycl.entity.caseHandler.DisposeRecord;
import com.ycl.service.caseHandler.IBaseCaseService;
import com.ycl.service.caseHandler.IDisposeRecordService;
import com.ycl.service.caseHandler.IIllegalBuildingService;
import com.ycl.service.caseHandler.IViolationsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.UUID;
/**
@@ -16,7 +38,222 @@
 * @since 2022-09-24
 */
@RestController
@RequestMapping("/base-case")
@RequestMapping("/base_case")
@Api(tags = "案件池")
public class BaseCaseController extends BaseController {
}
    private IBaseCaseService baseCaseService;
    @Autowired
    IViolationsService violationsService;
    @Autowired
    IIllegalBuildingService illegalBuildingService;
    @Autowired
    IDisposeRecordService iDisposeRecordService;
    @Autowired
    public void setBaseCaseService(IBaseCaseService baseCaseService) {
        this.baseCaseService = baseCaseService;
    }
    @ApiOperation(value = "上传市平台")
    @PostMapping("/upload-event")
    public CommonResult uploadEvent(@RequestParam Integer caseId, CommonResult<Object> success) {
        String msg = baseCaseService.uploadEvent(caseId);
        if (StringUtils.isEmpty(msg)) {
            return success;
        } else {
            return CommonResult.failed(msg);
        }
    }
    /**
     * @return com.ycl.api.CommonResult
     * @Description query illegal building and violation
     * @Param [size, current, state, type, resource]
     **/
    @ApiOperation(value = "查询违规违建")
    @GetMapping("/query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "state", value = "处理状态(0误报 1上报 2立案 3派遣 4处置 5核查 6结案7处理中)", dataType = "Integer"),
            @ApiImplicitParam(name = "type", value = "1 违规,2 违建", dataType = "Integer"),
            @ApiImplicitParam(name = "resource", value = "1 视频,2 手动", dataType = "Integer")
    })
    public CommonResult searchViolation(@RequestParam Integer size,
                                        @RequestParam Integer current,
                                        @RequestParam Integer state,
                                        @RequestParam(required = false) Integer type,
                                        @RequestParam(required = false) Integer resource) {
        if (state != null) {
            Page<Object> page = new Page<>();
            page.setCurrent(current);
            page.setSize(size);
            Page<Object> queryList;
            Integer violation = 1;
            Integer illegalBuilding = 2;
            if (type == violation) {
                queryList = baseCaseService.listViolationsPage(page, state, resource);
            } else if (type == illegalBuilding) {
                queryList = baseCaseService.listIllegalBuilding(page, state, resource);
            } else {
                return CommonResult.failed("bad request url");
            }
            return CommonResult.success(queryList);
        }
        return CommonResult.failed("request parameter is null");
    }
    /**
     * @return com.ycl.api.CommonResult
     * @Description delete illegal building or violation
     * @Param [id, type]
     **/
    @ApiOperation(value = "删除违规/违建案件")
    @DeleteMapping("/deletion")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "1 违规,2 违建", dataType = "Integer")
    })
    public CommonResult removeCase(@RequestParam Integer id, @RequestParam Integer type) {
        Integer violationType = 1;
        Integer illegalBuildingType = 2;
        if (id != null) {
            if (type == violationType) {
                return CommonResult.success(violationsService.removeById(id));
            } else if (type == illegalBuildingType) {
                return CommonResult.success(illegalBuildingService.removeById(id));
            }
            return CommonResult.success(baseCaseService.removeById(id));
        }
        return CommonResult.failed("request parameter is null");
    }
    /**
     * @return com.ycl.api.CommonResult
     * @Description delete illegal buildings or violations
     * @Param [ids, type]
     **/
    @ApiOperation(value = "批处理-删除违规/违建案件")
    @DeleteMapping("/batch_deletion")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "1 违规,2 违建", dataType = "Integer")
    })
    public CommonResult removeCases(@RequestParam List<Long> ids, @RequestParam Integer type) {
        Integer violationType = 1;
        Integer illegalBuildingType = 2;
        if (!ids.isEmpty()) {
            CommonResult.success(baseCaseService.removeBatchByIds(ids));
            if (type == violationType) {
                return CommonResult.success(violationsService.removeBatchByIds(ids));
            } else if (type == illegalBuildingType) {
                return CommonResult.success(illegalBuildingService.removeBatchByIds(ids));
            }
        }
        return CommonResult.failed("request parameter is null");
    }
    /**
     * @return com.ycl.api.CommonResult
     * @Description add  violation
     * @Param [violationParam]
     **/
    @ApiOperation(value = "添加违规案件")
    @PostMapping("/addition_violation")
    public CommonResult addViolationCase(@RequestBody @Validated ViolationParam violationParam) {
        Integer violation = 1;
        Integer resource = 2;
        Integer state = 7;
        BaseCase baseCase = new BaseCase();
        BeanUtils.copyProperties(violationParam, baseCase);
        baseCase.setEventSource(resource);
        baseCase.setCategory(violation);
        baseCase.setCode(UUID.randomUUID().toString());
        baseCase.setState(state);
        baseCaseService.save(baseCase);
        return CommonResult.success(baseCaseService.saveViolationCase(violationParam, baseCase.getId()));
    }
    /**
     * @return com.ycl.api.CommonResult
     * @Description add  illegal building
     * @Param [violationParam]
     **/
    @ApiOperation(value = "添加违建案件")
    @PostMapping("/addition_illegal_building")
    public CommonResult addIllegalBuildingCase(@RequestBody @Validated IllegalBuildingParam illegalBuildingParam) {
        Integer illegalBuilding = 2;
        Integer resource = 2;
        Integer state = 7;
        BaseCase baseCase = new BaseCase();
        BeanUtils.copyProperties(illegalBuildingParam, baseCase);
        baseCase.setCategory(illegalBuilding);
        baseCase.setEventSource(resource);
        baseCase.setCode(UUID.randomUUID().toString());
        baseCase.setState(state);
        baseCaseService.save(baseCase);
        return CommonResult.success(baseCaseService.saveIllegalBuildingCase(illegalBuildingParam, baseCase.getId()));
    }
    @ApiOperation(value = "案件详情")
    @GetMapping("/baseCaseDetail/{code}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "事件编号")
    })
    public CommonResult<BaseCaseDetail> baseCaseDetail(@PathVariable(value = "code") String code) {
        return CommonResult.success(baseCaseService.baseCaseDetail(code));
    }
    @ApiOperation(value = "人工路径案件图片展示")
    @GetMapping("/hand_work_case_images")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "01 违规,02 违建", dataType = "Integer")
    })
    public CommonResult queryCaseImages(@RequestParam Integer id, @RequestParam Integer type) {
        return CommonResult.success(baseCaseService.listCaseImages(id, type));
    }
    /**
     * @return com.ycl.api.CommonResult
     * @Description case status update
     * @Param [caseId, status]
     **/
    @ApiOperation(value = "案件状态修改")
    @PutMapping("/case_status_update")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "处理状态(0误报 1上报 2立案 3派遣 4处置 5核查 6结案7处理中8暂不处理)", name = "state")
    })
    public CommonResult updateCaseStatus(@RequestParam Integer caseId, @RequestParam Integer state) {
        return CommonResult.success(baseCaseService
                .update(new LambdaUpdateWrapper<BaseCase>()
                        .eq(BaseCase::getId, caseId)
                        .set(BaseCase::getState, state)));
    }
    /**
     * @return com.ycl.api.CommonResult
     * @Description reset case
     * @Param [caseId]
     **/
    @ApiOperation(value = "暂不处置重新处置")
    @PutMapping("/reset")
    public CommonResult resetCase(@RequestParam Integer caseId) {
        Integer firstNum = 0;
        Integer state = iDisposeRecordService
                .list(new LambdaQueryWrapper<DisposeRecord>()
                        .eq(DisposeRecord::getBaseCaseId, caseId).
                        orderByDesc(DisposeRecord::getCreateTime)).get(firstNum).getState();
        return CommonResult.success(baseCaseService
                .update(new LambdaUpdateWrapper<BaseCase>()
                        .eq(BaseCase::getId, caseId)
                        .set(BaseCase::getState, state)));
    }
    @ApiOperation(value = "结案")
    @PutMapping("/end_case")
    public CommonResult endCase(@RequestParam Integer caseId, @RequestParam String result) {
        baseCaseService.endCase(caseId, result);
        return CommonResult.success("end case success~!");
    }
}