添加了修改火情状态的代码模块

This commit is contained in:
XinYi Song 2022-02-24 16:11:24 +08:00
parent 4bd6d424e7
commit 97dd89a938
2 changed files with 34 additions and 3 deletions

View File

@ -2,16 +2,16 @@ package com.xkrs.controller;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.dao.EquipmentDao;
import com.xkrs.dao.FireDao;
import com.xkrs.model.entity.Fire;
import com.xkrs.service.FireService;
import com.xkrs.util.Query;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -31,6 +31,9 @@ public class FireController {
@Resource
private EquipmentDao equipmentDao;
@Resource
private FireDao fireDao;
Locale locale = LocaleContextHolder.getLocale();
/**
@ -93,4 +96,24 @@ public class FireController {
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,maps,locale);
}
/**
* 修改火点状态
* @param map
* @return
*/
@Transactional(rollbackOn = Exception.class)
@PostMapping("/updateFireState")
public String updateFireState(@RequestBody Map map){
String alarmCode = (String) map.get("alarmCode");
Fire byAlarmCode = fireDao.findByAlarmCode(alarmCode);
if(byAlarmCode != null){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"火情编码错误,请检查!",locale);
}
if("1".equals(byAlarmCode.getFireState())){
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"该火情已处理!",locale);
}
fireDao.updateFireState(alarmCode);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"修改成功!",locale);
}
}

View File

@ -45,4 +45,12 @@ public interface FireDao extends JpaRepository<Fire,Long>, JpaSpecificationExecu
*/
@Query(value = "select * from fire order by alarm_date desc limit 300",nativeQuery = true)
List<Fire> findThreeHundredData();
/**
* 修改火点状态
* @param alarmDate
*/
@Modifying(clearAutomatically=true)
@Query(value = "update fire set fire_state = '1' where alarm_code = ?",nativeQuery = true)
void updateFireState(String alarmDate);
}