Newer
Older
huludao / src / main / java / com / newfiber / api / pc / controller / zhz / MeetAlertManagerController.java
package com.newfiber.api.pc.controller.zhz;

import cn.hutool.core.util.IdUtil;
import com.newfiber.api.core.annotation.SysLog;
import com.newfiber.api.core.commons.*;
import com.newfiber.api.pc.dto.MeetAlertDTO;
import com.newfiber.api.pc.dto.MeetAlertSerchDTO;
import com.newfiber.api.pc.dto.ReturnSupDTO;
import com.newfiber.api.pc.model.meet.MeetAlertMedia;
import com.newfiber.api.pc.model.meet.MeetAlter;
import com.newfiber.api.pc.model.vo.AlertTypeVo;
import com.newfiber.api.pc.service.HouseSiteSuppliesService;
import com.newfiber.api.pc.service.MeetAlterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.Calendar;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author:zhz
 * @CreateDate:2020/11/27 13:57
 * @Description:
 */
@RestController
@RequestMapping("/meet/alert/")
@Api(value = "MeetAlertManagerController",tags = "警情管理控制层")
public class MeetAlertManagerController {

    @Value("${xnFile.pic}")
    private String filePic;

    @Value("${nginx.pic}")
    private String nginxPic;
    @Autowired
    private MeetAlterService meetAlterService;
    @Autowired
    private HouseSiteSuppliesService houseSiteSuppliesService;
    /**  年份 */
    private AtomicInteger year =  new AtomicInteger(Calendar.getInstance().get(Calendar.YEAR));
    /** 月份 */
    private AtomicInteger month = new AtomicInteger(Calendar.getInstance().get(Calendar.MONTH) +1 );



    @PostMapping("/queryPage")
    @ApiOperation("查询与自己相关的警情-管理员能查所有")
    @SysLog(actionType = "4",value = "查询与自己相关的警情-管理员能查所有")
    public ResultObj<PageResultObject<MeetAlter>> queryPage(@RequestBody PageRequestObject<MeetAlertSerchDTO> pageObject, HttpServletRequest request){
        String useNo = request.getHeader("userNo");
        String token = request.getHeader("token");
        return new ResultObj<PageResultObject<MeetAlter>>(ResultCode.OK,meetAlterService.queryPage(pageObject,useNo,token));
    }


    @PostMapping("/queryAlertByTypeId")
    @ApiOperation("根据警情类别来查询多个警情数据-用于警情统计中点击查看详情")
    @SysLog(actionType = "4",value = "根据警情类别来查询多个警情数据-用于警情统计中点击查看详情")
    public ResultObj<PageResultObject<MeetAlter>> queryAlertByTypeId(@RequestBody PageRequestObject<Integer> pageRequestObject){
        return new ResultObj<PageResultObject<MeetAlter>>(ResultCode.OK,meetAlterService.queryAlertByTypeId(pageRequestObject));
    }

    @PostMapping("/selectAlertType")
    @ApiOperation("查询已有警情中的所有类别")
    @SysLog(actionType = "4",value = "查询已有警情中的所有类别")
    public ResultObj<List<AlertTypeVo>>  selectAlertType(){
        return new ResultObj<List<AlertTypeVo>>(ResultCode.OK,meetAlterService.selectAlertType());
    }



    @PostMapping("/view")
    @ApiOperation("根据警情编号查看详细信息")
    @SysLog(actionType = "4",value = "根据警情编号查看详细信息")
    public ResultObj<MeetAlter> viewDetail(@RequestParam("aId")Integer aId){
        return new ResultObj<MeetAlter>(ResultCode.OK,meetAlterService.viewDetail(aId));
    }


    @PostMapping("/add")
    @ApiOperation("手动添加警情")
    @SysLog(actionType = "1",value = "手动添加警情")
    public ResultObj manualAddAlert(@RequestBody MeetAlertDTO meetAlertDTO, HttpServletRequest request){
        String userNo = request.getHeader("userNo");
        meetAlterService.addAlert(meetAlertDTO,userNo);
        return new ResultObj(ResultCode.OK);
    }

    @PostMapping("/overAlert")
    @ApiOperation("结束警情")
    @SysLog(actionType = "3",value = "结束警情")
    public ResultObj overAlert(@RequestBody MeetAlertMedia meetAlertMedia,HttpServletRequest request){
        if(StringUtils.isEmpty(meetAlertMedia.getAlertId())){
            throw new CustomException(ResultCode.PARAM_NULL);
        }
        if(meetAlterService.selectById(meetAlertMedia.getAlertId()).getIsReturnSup().equals(0)){
            return ResultObj.error("该警情未归还物资,请先归还物资后在结束警情!");
        }
        meetAlterService.overAlert(meetAlertMedia,request);
        return ResultObj.ok("结束了警情");
    }

    @PostMapping("/returnSupplies")
    @ApiOperation("归还物资操作")
    @SysLog(value = "归还物资操作",actionType = "3")
    public ResultObj returnSupllies(@RequestBody ReturnSupDTO dto){
        return new ResultObj(ResultCode.OK,houseSiteSuppliesService.returnSupplies(dto.getAlertId(),dto.getSiteDataOperationDTO()));
    }


    @PostMapping("/uploadPic")
    @ApiOperation("上传图片-返回图片路径")
    @SysLog(actionType = "1",value = "上传图片-返回图片路径")
    public ResultObj<String> addPic(@RequestParam("file") MultipartFile file) throws Exception{
        String extension = FilenameUtils.getExtension(file.getOriginalFilename());
        String filePath = year.get() + File.separator + month.get() + File.separator + IdUtil.simpleUUID() + "." + extension;
        File newFile = new File(filePic,filePath);
        if(!newFile.getParentFile().exists()){
            newFile.mkdirs();
        }
        file.transferTo(newFile);
        return new ResultObj<String>(ResultCode.OK,nginxPic + filePath);

    }

    @PostMapping("/deletePic")
    @ApiOperation("删除已添加的图片")
    @SysLog(actionType = "2",value = "删除已添加的图片")
    public ResultObj deletePic(@RequestParam("filePath") String filePath){
        File newFile = new File(filePic , filePath);
        if(newFile.exists()){
            newFile.delete();
            return ResultObj.ok("删除文件成功");
        }
        return ResultObj.error();
    }


    public String getFilePic() {
        return filePic;
    }

    public void setFilePic(String filePic) {
        this.filePic = filePic;
    }

    public String getNginxPic() {
        return nginxPic;
    }

    public void setNginxPic(String nginxPic) {
        this.nginxPic = nginxPic;
    }
}