package com.template.controller;
import cn.hutool.poi.excel.ExcelUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.template.annotation.DESRespondSecret;
import com.template.api.SmartWarningControllerAPI;
import com.template.common.result.ResponseStatusEnum;
import com.template.common.utils.*;
import com.template.model.dto.OperationWarningDto;
import com.template.model.dto.WarningDeletePushDto;
import com.template.model.dto.WarningSavePushDto;
import com.template.model.dto.WarningUserDto;
import com.template.model.pojo.SmartDepartment;
import com.template.model.pojo.SmartUser;
import com.template.model.pojo.SmartWarning;
import com.template.model.result.CommonResult;
import com.template.model.result.PageUtils;
import com.template.model.vo.BehaviourListVo;
import com.template.model.vo.DepartmentTreeVo;
import com.template.model.vo.UserVo;
import com.template.services.SmartDepartmentService;
import com.template.services.SmartUserService;
import com.template.services.SmartWarningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.yaml.snakeyaml.events.Event;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
*
* 前端控制器
*
*
* @author ceshi
* @since 2023-12-04
*/
@RestController
//返回参数加密注解
@DESRespondSecret
public class SmartWarningController implements SmartWarningControllerAPI {
@Autowired
private SmartWarningService smartWarningService;
@Autowired
private SmartDepartmentService smartDepartmentService;
@Autowired
private SmartUserService smartUserService;
/**
* 新增预警信息
*
* @param smartApply 预警信息数据
* @param bindingResult
* @return
*/
@Override
@DESRespondSecret(validated = true)
public CommonResult insertSmartWarning(SmartWarning smartApply, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
String st = paramUtils.getParamError(bindingResult);
return CommonResult.fail(st);
}
int result = smartWarningService.insertSmartWarning(smartApply);
return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
}
/**
* 更新预警信息
*
* @param sa 预警信息数据
* @param bindingResult
* @return
*/
@Override
@DESRespondSecret(validated = true)
public CommonResult updateSmartWarningById(SmartWarning sa, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
String st = paramUtils.getParamError(bindingResult);
return CommonResult.fail(st);
}
int result = smartWarningService.updateSmartWarning(sa);
return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
}
/**
* 预警信息分页数据查询
*
* @param currentPage 当前页数
* @param pageCount 一页数据条数
* @param name 查询名称
* @return
*/
@Override
@DESRespondSecret(validated = true)
public CommonResult queryPageSmartWarning(int currentPage, int pageCount,String startTime,String endTime, String name, String state) {
PageUtils result = smartWarningService.queryPageSmartWarningMange(currentPage, pageCount,startTime,endTime, name, state);
return CommonResult.ok(result);
}
@Override
@DESRespondSecret(validated = true)
public CommonResult deleteSmartWarningById(int id) {
SmartWarning data = smartWarningService.getSmartById(id);
if (data == null) {
return CommonResult.fail("当前数据不存在,删除失败!");
}
int result = smartWarningService.deleteSmartWarningById(id);
return result > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
}
@Override
@DESRespondSecret(validated = true)
public CommonResult operation(OperationWarningDto operationWarningDto) {
Integer id = operationWarningDto.getId();
if (ObjectUtils.isEmpty(id)) {
return CommonResult.fail("缺少id");
}
String remark = operationWarningDto.getRemark();
SmartWarning smartById = smartWarningService.getSmartById(id);
smartById.setStatu(1);
smartById.setRemark(remark);
int result = smartWarningService.updateSmartWarning(smartById);
return result > 0 ? CommonResult.ok("操作成功") : CommonResult.fail("操作失败");
}
@Override
@DESRespondSecret(validated = false)
public void excelSmartWarning(HttpServletResponse response,String startTime,String endTime,String location, String state) {
// 表头数据
// List