修复对象转换问题
parent
e932aacc86
commit
415bfd3086
|
@ -1,6 +1,7 @@
|
||||||
package com.zcloud.controller.accident;
|
package com.zcloud.controller.accident;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.zcloud.controller.base.BaseController;
|
import com.zcloud.controller.base.BaseController;
|
||||||
|
@ -71,8 +72,11 @@ public class AccidentRecordsController extends BaseController {
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@RequestMapping("/save")
|
@RequestMapping("/save")
|
||||||
public Map<String, Object> save(HttpServletRequest request) {
|
public Map<String, Object> save(HttpServletRequest request) {
|
||||||
AccidentRecords accidentRecords = BeanUtil.mapToBean(new PageData(request), AccidentRecords.class, true);
|
PageData pageData = new PageData(request);
|
||||||
accidentRecordsService.save(accidentRecords);
|
if (CollUtil.isEmpty(pageData)){
|
||||||
|
throw new RuntimeException("参数不能为空");
|
||||||
|
}
|
||||||
|
accidentRecordsService.save(pageData);
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
result.put("result", "success");
|
result.put("result", "success");
|
||||||
return result;
|
return result;
|
||||||
|
@ -88,9 +92,13 @@ public class AccidentRecordsController extends BaseController {
|
||||||
@RequestMapping("/update")
|
@RequestMapping("/update")
|
||||||
public Map<String, Object> update(HttpServletRequest request) {
|
public Map<String, Object> update(HttpServletRequest request) {
|
||||||
PageData pageData = new PageData(request);
|
PageData pageData = new PageData(request);
|
||||||
AccidentRecords accidentRecords = BeanUtil.mapToBean(pageData, AccidentRecords.class, true);
|
if (CollUtil.isEmpty(pageData)){
|
||||||
accidentRecords.setId(Optional.of(accidentRecords.getId()).orElseThrow(() -> new RuntimeException("id不能为空")));
|
throw new RuntimeException("参数不能为空");
|
||||||
accidentRecordsService.update(accidentRecords);
|
}
|
||||||
|
if (pageData.get("id") != null) {
|
||||||
|
throw new RuntimeException("id不能为空");
|
||||||
|
}
|
||||||
|
accidentRecordsService.update(pageData);
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
result.put("result", "success");
|
result.put("result", "success");
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.zcloud.service.accident;
|
||||||
|
|
||||||
import com.zcloud.entity.Page;
|
import com.zcloud.entity.Page;
|
||||||
import com.zcloud.entity.PageData;
|
import com.zcloud.entity.PageData;
|
||||||
import com.zcloud.entity.accident.AccidentRecords;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -29,16 +28,16 @@ public interface AccidentRecordsService {
|
||||||
/**
|
/**
|
||||||
* 新增
|
* 新增
|
||||||
*
|
*
|
||||||
* @param accidentRecords 要保存的实体
|
* @param pageData 要保存的实体
|
||||||
*/
|
*/
|
||||||
void save(AccidentRecords accidentRecords);
|
void save(PageData pageData);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改
|
* 修改
|
||||||
*
|
*
|
||||||
* @param bean 要修改的实体
|
* @param bean 要修改的实体
|
||||||
*/
|
*/
|
||||||
void update(AccidentRecords bean);
|
void update(PageData pageData);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除
|
* 删除
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.zcloud.service.accident.impl;
|
package com.zcloud.service.accident.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.date.DatePattern;
|
import cn.hutool.core.date.DatePattern;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
@ -58,7 +59,8 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void save(AccidentRecords accidentRecords) {
|
public void save(PageData pageData) {
|
||||||
|
AccidentRecords accidentRecords = new AccidentRecords();
|
||||||
accidentRecords.setId(IdUtil.fastSimpleUUID());
|
accidentRecords.setId(IdUtil.fastSimpleUUID());
|
||||||
accidentRecords.setCreatedBy(Jurisdiction.getUsername());
|
accidentRecords.setCreatedBy(Jurisdiction.getUsername());
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
|
@ -71,12 +73,45 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService {
|
||||||
accidentRecords.setIsDeleted(0);
|
accidentRecords.setIsDeleted(0);
|
||||||
String corpinfoId = StrUtil.isEmpty(accidentRecords.getCorpinfoId()) ? Jurisdiction.getCORPINFO_ID() : accidentRecords.getCorpinfoId();
|
String corpinfoId = StrUtil.isEmpty(accidentRecords.getCorpinfoId()) ? Jurisdiction.getCORPINFO_ID() : accidentRecords.getCorpinfoId();
|
||||||
accidentRecords.setCorpinfoId(corpinfoId);
|
accidentRecords.setCorpinfoId(corpinfoId);
|
||||||
|
accidentRecords.setIncidentNumber(pageData.getString("incidentNumber"));
|
||||||
|
accidentRecords.setIncidentName(pageData.getString("incidentName"));
|
||||||
|
accidentRecords.setIncidentType(pageData.getString("incidentType"));
|
||||||
|
accidentRecords.setIncidentLevel(pageData.getString("incidentLevel"));
|
||||||
|
accidentRecords.setLocation(pageData.getString("location"));
|
||||||
|
accidentRecords.setIncidentDate(DateUtil.parse(pageData.getString("incidentDate"), DatePattern.UTC_MS_PATTERN));
|
||||||
|
accidentRecords.setDirectLoss(Convert.toInt(pageData.get("directLoss")));
|
||||||
|
accidentRecords.setInjured(Convert.toInt(pageData.get("injured")));
|
||||||
|
accidentRecords.setSeriouslyInjured(Convert.toInt(pageData.get("seriouslyInjured")));
|
||||||
|
accidentRecords.setCause(pageData.getString("cause"));
|
||||||
|
accidentRecords.setSummary(pageData.getString("summary"));
|
||||||
|
accidentRecords.setAnalysis(pageData.getString("analysis"));
|
||||||
|
accidentRecords.setSuggestions(pageData.getString("suggestions"));
|
||||||
|
accidentRecords.setMeasures(pageData.getString("measures"));
|
||||||
|
accidentRecords.setCreator(pageData.getString("creator"));
|
||||||
|
accidentRecords.setReportDate(DateUtil.parse(pageData.getString("reportDate"), DatePattern.UTC_MS_PATTERN));
|
||||||
Assert.isTrue(accidentRecordsMapper.save(accidentRecords) == 1, "新增事故记录失败");
|
Assert.isTrue(accidentRecordsMapper.save(accidentRecords) == 1, "新增事故记录失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void update(AccidentRecords accidentRecords) {
|
public void update(PageData pageData) {
|
||||||
|
AccidentRecords accidentRecords = new AccidentRecords();
|
||||||
|
accidentRecords.setIncidentNumber(pageData.getString("incidentNumber"));
|
||||||
|
accidentRecords.setIncidentName(pageData.getString("incidentName"));
|
||||||
|
accidentRecords.setIncidentType(pageData.getString("incidentType"));
|
||||||
|
accidentRecords.setIncidentLevel(pageData.getString("incidentLevel"));
|
||||||
|
accidentRecords.setLocation(pageData.getString("location"));
|
||||||
|
accidentRecords.setIncidentDate(DateUtil.parse(pageData.getString("incidentDate"), DatePattern.UTC_MS_PATTERN));
|
||||||
|
accidentRecords.setDirectLoss(Convert.toInt(pageData.get("directLoss")));
|
||||||
|
accidentRecords.setInjured(Convert.toInt(pageData.get("injured")));
|
||||||
|
accidentRecords.setSeriouslyInjured(Convert.toInt(pageData.get("seriouslyInjured")));
|
||||||
|
accidentRecords.setCause(pageData.getString("cause"));
|
||||||
|
accidentRecords.setSummary(pageData.getString("summary"));
|
||||||
|
accidentRecords.setAnalysis(pageData.getString("analysis"));
|
||||||
|
accidentRecords.setSuggestions(pageData.getString("suggestions"));
|
||||||
|
accidentRecords.setMeasures(pageData.getString("measures"));
|
||||||
|
accidentRecords.setCreator(pageData.getString("creator"));
|
||||||
|
accidentRecords.setReportDate(DateUtil.parse(pageData.getString("reportDate"), DatePattern.UTC_MS_PATTERN));
|
||||||
accidentRecords.setUpdatedBy(Jurisdiction.getUsername());
|
accidentRecords.setUpdatedBy(Jurisdiction.getUsername());
|
||||||
accidentRecords.setUpdatedTime(new Date());
|
accidentRecords.setUpdatedTime(new Date());
|
||||||
String corpinfoId = StrUtil.isEmpty(accidentRecords.getCorpinfoId()) ? Jurisdiction.getCORPINFO_ID() : accidentRecords.getCorpinfoId();
|
String corpinfoId = StrUtil.isEmpty(accidentRecords.getCorpinfoId()) ? Jurisdiction.getCORPINFO_ID() : accidentRecords.getCorpinfoId();
|
||||||
|
|
Loading…
Reference in New Issue