Commit bfc0baad authored by H2T's avatar H2T

警情修改记录时更新源数据

parent 5fc2edf6
......@@ -52,6 +52,9 @@ public class AlertFormRecordDto extends BaseDto {
@ApiModelProperty(value = "被困时间")
private Date trappedTime;
@ApiModelProperty(value = "更新时间")
private Date updateTime;
@ApiModelProperty(value = "事件描述")
private String description;
......
......@@ -82,6 +82,12 @@ public class AlertFormRecord extends BaseEntity {
private Date trappedTime;
/**
* 更新时间
*/
@TableField("update_time")
private Date updateTime;
/**
* 事件描述
*/
@TableField("description")
......
......@@ -4,12 +4,12 @@
<select id="getRecordByCalledId"
resultType="com.yeejoin.amos.boot.module.elevator.api.entity.AlertFormRecord">
SELECT *
SELECT afr.*
FROM tz_alert_form_record afr
WHERE afr.is_delete = 0
<if test="TzCarcylRegDto!=null and TzCarcylRegDto!='' ">
AND afr.alert_called_id = #{alertCalledId}
</if>
ORDER BY afr.rec_date
ORDER BY afr.update_time desc
</select>
</mapper>
......@@ -7,7 +7,10 @@ import com.yeejoin.amos.boot.module.elevator.api.service.IAlertFormRecordService
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
......@@ -30,7 +33,7 @@ public class AlertFormRecordController {
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@PostMapping(value = "/saveRecord")
@ApiOperation(httpMethod = "POST", value = "新增警情接警填报记录", notes = "新增警情接警填报记录")
public ResponseModel<Object> saveMobile(@RequestBody Map<String, AlertFormRecordDto> map) {
public ResponseModel<Object> saveRecord(@RequestBody Map<String, AlertFormRecordDto> map) {
if (ObjectUtil.isNotEmpty(map.get("oldData")) && ObjectUtil.isNotEmpty(map.get("newData"))) {
return ResponseHelper.buildResponse(iAlertFormRecordService.saveAlertFormRecord(map));
......@@ -43,8 +46,8 @@ public class AlertFormRecordController {
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@PostMapping(value = "/recordByCalledId")
@ApiOperation(httpMethod = "POST", value = "根据警情id查询修改记录", notes = "根据警情id查询修改记录")
public ResponseModel<Object> saveMobile(@RequestParam("alertCalledId") String alertCalledId) {
return ResponseHelper.buildResponse(iAlertFormRecordService.allAlertFormRecordByCalledId(Long.valueOf(alertCalledId)));
public ResponseModel<Object> recordByCalledId(@RequestBody Map<String, String> map) {
return ResponseHelper.buildResponse(iAlertFormRecordService.allAlertFormRecordByCalledId(Long.valueOf(map.get("alertCalledId"))));
}
}
package com.yeejoin.amos.boot.module.elevator.flc.biz.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.common.biz.utils.CommonResponseUtil;
import com.yeejoin.amos.boot.module.elevator.api.dto.AlertFormRecordDto;
import com.yeejoin.amos.boot.module.elevator.api.entity.AlertFormRecord;
import com.yeejoin.amos.boot.module.elevator.api.entity.AlertFormValue;
import com.yeejoin.amos.boot.module.elevator.api.mapper.AlertFormRecordMapper;
import com.yeejoin.amos.boot.module.elevator.api.service.IAlertFormRecordService;
import com.yeejoin.amos.boot.module.elevator.biz.service.impl.AlertFormValueServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -13,6 +19,9 @@ import org.typroject.tyboot.core.rdbms.service.BaseService;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.lang.reflect.Field;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -26,7 +35,30 @@ import java.util.Map;
public class AlertFormRecordServiceImpl extends BaseService<AlertFormRecordDto, AlertFormRecord, AlertFormRecordMapper> implements IAlertFormRecordService {
@Autowired
RedisUtils redisUtils;
@Autowired
private AlertFormRecordMapper alertFormRecordMapper;
@Autowired
private AlertFormValueServiceImpl iAlertFormValueService;
/**
* 驼峰转下划线
*
* @param str
* @return
*/
public static String convertToUnderline(String str) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (Character.isUpperCase(c)) {
sb.append("_").append(Character.toLowerCase(c));
} else {
sb.append(c);
}
}
return sb.toString();
}
/**
* 保存警情修改记录
......@@ -41,15 +73,42 @@ public class AlertFormRecordServiceImpl extends BaseService<AlertFormRecordDto,
AlertFormRecordDto oldData = map.get("oldData");
AlertFormRecordDto newData = map.get("newData");
List<AlertFormRecord> recordByCalledId = alertFormRecordMapper.getRecordByCalledId(newData.getAlertCalledId());
AlertFormRecord record = new AlertFormRecord();
AlertFormRecord oldRecord = new AlertFormRecord();
//第一次修改,保存旧记录
if (recordByCalledId.isEmpty()) {
BeanUtils.copyProperties(oldData, record);
record.setRecDate(oldData.getTrappedTime());
alertFormRecordMapper.insert(record);
BeanUtils.copyProperties(oldData, oldRecord);
oldRecord.setUpdateTime(oldData.getTrappedTime());
alertFormRecordMapper.insert(oldRecord);
}
AlertFormRecord record = new AlertFormRecord();
BeanUtils.copyProperties(newData, record);
record.setUpdateTime(new Date());
alertFormRecordMapper.insert(record);
// 更新警情基本信息
Long alertCalled = record.getAlertCalledId();
LambdaQueryWrapper<AlertFormValue> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AlertFormValue::getAlertCalledId, alertCalled);
// 警情动态表单数据
List<AlertFormValue> list = iAlertFormValueService.list(queryWrapper);
HashMap<String, Object> listMap = new HashMap<>();
list.forEach(x -> listMap.put(x.getFieldCode(), x.getFieldValue()));
for (Field field : record.getClass().getDeclaredFields()) {
field.setAccessible(true); // 设置为可访问,以访问私有属性
String fieldName = convertToUnderline(field.getName());
Object value = field.get(record);
try {
if (listMap.containsKey(fieldName)) {
LambdaUpdateWrapper<AlertFormValue> wrapper = new LambdaUpdateWrapper<>();
wrapper.eq(AlertFormValue::getAlertCalledId, alertCalled);
wrapper.eq(AlertFormValue::getFieldCode, fieldName);
wrapper.set(AlertFormValue::getFieldValue, value);
iAlertFormValueService.update(wrapper);
}
} catch (Exception e) {
e.printStackTrace();
}
}
redisUtils.del(RedisKey.TZS_ALERTCALLED_ID + alertCalled);
return ResponseHelper.buildResponse("保存警情记录成功");
} catch (Exception e) {
log.error(e.getMessage(), e);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment