测试完成
parent
69a359ded8
commit
eb37f788a7
|
@ -1,7 +1,6 @@
|
|||
package com.zcloud.controller.accident;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.zcloud.controller.base.BaseController;
|
||||
|
@ -56,7 +55,7 @@ public class AccidentRecordsController extends BaseController {
|
|||
*/
|
||||
@ResponseBody
|
||||
@RequestMapping("/{id}")
|
||||
public Map<String, Object> getById(@PathVariable("id") Long id) {
|
||||
public Map<String, Object> getById(@PathVariable("id") String id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("result", "success");
|
||||
result.put("info", accidentRecordsService.getById(Optional.of(id).orElseThrow(() -> new RuntimeException("id不能为空"))));
|
||||
|
@ -109,7 +108,7 @@ public class AccidentRecordsController extends BaseController {
|
|||
if (StrUtil.isEmpty(values)) {
|
||||
throw new RuntimeException("id不能为空");
|
||||
}
|
||||
List<Long> ids = Arrays.stream(values.split(",")).map(Convert::toLong).filter(ObjectUtil::isNotEmpty)
|
||||
List<String> ids = Arrays.stream(values.split(",")).filter(ObjectUtil::isNotEmpty)
|
||||
.collect(Collectors.toList());
|
||||
accidentRecordsService.delete(ids);
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
|
|
@ -21,7 +21,7 @@ public class AccidentRecords implements Serializable {
|
|||
* 主键ID
|
||||
*/
|
||||
@NotNull(message = "主键ID不能为null")
|
||||
private Long id;
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 事故案号
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package com.zcloud.entity.accident.dto;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.zcloud.entity.accident.ExcelValue;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class AccidentRecordsExcel implements Serializable {
|
||||
|
@ -38,11 +40,11 @@ public class AccidentRecordsExcel implements Serializable {
|
|||
@ExcelValue(value = "事故级别")
|
||||
private String incidentLevel;
|
||||
|
||||
/**
|
||||
* 事故性质
|
||||
*/
|
||||
@ExcelValue(value = "事故性质")
|
||||
private String incidentNature;
|
||||
// /**
|
||||
// * 事故性质
|
||||
// */
|
||||
// @ExcelValue(value = "事故性质")
|
||||
// private String incidentNature;
|
||||
|
||||
/**
|
||||
* 事故发生地点
|
||||
|
@ -121,4 +123,13 @@ public class AccidentRecordsExcel implements Serializable {
|
|||
*/
|
||||
@ExcelValue(value = "报出日期")
|
||||
private String reportDate;
|
||||
|
||||
|
||||
public void setIncidentDate(Date incidentDate) {
|
||||
this.incidentDate = DateUtil.format(incidentDate, "yyyy年MM月dd日HH时mm分ss秒");
|
||||
}
|
||||
|
||||
public void setReportDate(Date reportDate) {
|
||||
this.reportDate = DateUtil.format(reportDate, "yyyy年MM月dd日HH时mm分ss秒");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public interface AccidentRecordsMapper {
|
|||
* @param id id
|
||||
* @return 结果
|
||||
*/
|
||||
PageData getById(Long id);
|
||||
PageData getById(String id);
|
||||
|
||||
/**
|
||||
* 新增
|
||||
|
@ -49,7 +49,7 @@ public interface AccidentRecordsMapper {
|
|||
* @param ids 主键数组
|
||||
* @return 受影响的行数
|
||||
*/
|
||||
int delete(@Param("ids") List<Long> ids);
|
||||
int delete(@Param("ids") List<String> ids);
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
|
|
|
@ -24,7 +24,7 @@ public interface AccidentRecordsService {
|
|||
* @param id 主键
|
||||
* @return 查询结果
|
||||
*/
|
||||
PageData getById(Long id);
|
||||
PageData getById(String id);
|
||||
|
||||
/**
|
||||
* 新增
|
||||
|
@ -45,7 +45,7 @@ public interface AccidentRecordsService {
|
|||
*
|
||||
* @param ids 主键数组
|
||||
*/
|
||||
void delete(List<Long> ids);
|
||||
void delete(List<String> ids);
|
||||
|
||||
/**
|
||||
* 导出Excel
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package com.zcloud.service.accident.impl;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
|
@ -12,17 +15,17 @@ import com.zcloud.entity.accident.dto.AccidentRecordsExcel;
|
|||
import com.zcloud.mapper.datasource.accident.AccidentRecordsMapper;
|
||||
import com.zcloud.service.accident.AccidentRecordsService;
|
||||
import com.zcloud.service.bus.ImgFilesService;
|
||||
import com.zcloud.util.*;
|
||||
import com.zcloud.util.Const;
|
||||
import com.zcloud.util.Jurisdiction;
|
||||
import com.zcloud.util.Smb;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -49,17 +52,22 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public PageData getById(Long id) {
|
||||
public PageData getById(String id) {
|
||||
return accidentRecordsMapper.getById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void save(AccidentRecords accidentRecords) {
|
||||
accidentRecords.setId(IdUtil.getSnowflake(1, 1).nextId());
|
||||
accidentRecords.setId(IdUtil.fastSimpleUUID());
|
||||
accidentRecords.setCreatedBy(Jurisdiction.getUsername());
|
||||
Date date = Date.from(LocalDateTime.now().toInstant(ZoneOffset.of("+08:00")));
|
||||
accidentRecords.setCreatedTime(date);
|
||||
Date date = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat(DatePattern.NORM_DATETIME_PATTERN);
|
||||
// 设置成东八区时间
|
||||
dateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
|
||||
|
||||
DateUtil.parse(dateFormat.format(date), DatePattern.NORM_DATETIME_PATTERN);
|
||||
|
||||
accidentRecords.setIsDeleted(0);
|
||||
String corpinfoId = StrUtil.isEmpty(accidentRecords.getCorpinfoId()) ? Jurisdiction.getCORPINFO_ID() : accidentRecords.getCorpinfoId();
|
||||
accidentRecords.setCorpinfoId(corpinfoId);
|
||||
|
@ -70,8 +78,7 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService {
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(AccidentRecords accidentRecords) {
|
||||
accidentRecords.setUpdatedBy(Jurisdiction.getUsername());
|
||||
Date date = Date.from(LocalDateTime.now().toInstant(ZoneOffset.of("+08:00")));
|
||||
accidentRecords.setUpdatedTime(date);
|
||||
accidentRecords.setUpdatedTime(new Date());
|
||||
String corpinfoId = StrUtil.isEmpty(accidentRecords.getCorpinfoId()) ? Jurisdiction.getCORPINFO_ID() : accidentRecords.getCorpinfoId();
|
||||
accidentRecords.setCorpinfoId(corpinfoId);
|
||||
Assert.isTrue(accidentRecordsMapper.updateById(accidentRecords) == 1, "更新事故记录失败");
|
||||
|
@ -79,7 +86,7 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService {
|
|||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(List<Long> ids) {
|
||||
public void delete(List<String> ids) {
|
||||
Assert.isTrue(accidentRecordsMapper.delete(ids) == ids.size(), "删除事故记录失败");
|
||||
}
|
||||
|
||||
|
@ -152,13 +159,13 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService {
|
|||
|
||||
@Override
|
||||
public String importPhotos(MultipartFile file) {
|
||||
String fileName = UuidUtil.get32UUID() + "." + FilenameUtils.getExtension(file.getOriginalFilename());
|
||||
String fileName = IdUtil.fastSimpleUUID() + "." + FileUtil.extName(file.getOriginalFilename());
|
||||
PageData pd = new PageData();
|
||||
pd.put("IMGFILES_ID", UuidUtil.get32UUID());
|
||||
pd.put("FOREIGN_KEY", UuidUtil.get32UUID());
|
||||
pd.put("IMGFILES_ID", IdUtil.fastSimpleUUID());
|
||||
pd.put("FOREIGN_KEY", IdUtil.fastSimpleUUID());
|
||||
pd.put("TYPE", 117);
|
||||
try {
|
||||
String path = Const.FILEPATHFILE + UuidUtil.get32UUID() + "/" + DateUtil.getDays();
|
||||
String path = Const.FILEPATHFILE + IdUtil.fastSimpleUUID() + "/" + DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN);
|
||||
Smb.sshSftp(file, fileName, path);
|
||||
pd.put("FILEPATH", path + "/" + fileName);
|
||||
imgFilesService.save(pd);
|
||||
|
|
|
@ -3,143 +3,143 @@
|
|||
<mapper namespace="com.zcloud.mapper.datasource.accident.AccidentRecordsMapper">
|
||||
|
||||
<select id="listPage" parameterType="com.zcloud.entity.Page" resultType="pd">
|
||||
select cast(accident_id AS CHAR) as id, CORP_NAME as companyName, location, date_format(incident_date,'%Y-%m-%d %H:%I:%s') as 'incidentDate', incident_name as 'incidentName'
|
||||
from accident_records as ar
|
||||
left join bus_corp_info as bci on ar.corpinfo_id = bci.CORPINFO_ID
|
||||
select ACCIDENT_ID as id, CORP_NAME as companyName, LOCATION as 'location', INCIDENT_DATE as 'incidentDate', INCIDENT_NAME as 'incidentName'
|
||||
from bus_accident as ar
|
||||
left join bus_corp_info as bci on ar.CORPINFO_ID = bci.CORPINFO_ID
|
||||
<where>
|
||||
<if test="pd.corpInfoId != null and pd.corpInfoId != ''">
|
||||
and ar.corpinfo_id = #{pd.corpInfoId}
|
||||
and ar.CORPINFO_ID = #{pd.corpInfoId}
|
||||
</if>
|
||||
<if test="pd.incidentName != null and pd.incidentName != ''">
|
||||
and incident_name like concat('%', #{pd.incidentName}, '%')
|
||||
and INCIDENT_NAME like concat('%', #{pd.incidentName}, '%')
|
||||
</if>
|
||||
<if test="pd.startTime != null and pd.startTime != '' and pd.endTime != null and pd.startTime != ''">
|
||||
and incident_date between #{pd.startTime} and #{pd.endTime}
|
||||
and INCIDENT_DATE between #{pd.startTime} and #{pd.endTime}
|
||||
</if>
|
||||
<if test="pd.location != null and pd.location != ''">
|
||||
and location like concat('%', #{pd.location}, '%')
|
||||
and LOCATION like concat('%', #{pd.location}, '%')
|
||||
</if>
|
||||
<if test="pd.incidentLevel != null and pd.incidentLevel != ''">
|
||||
and incident_level like concat('%', #{pd.incidentLevel}, '%')
|
||||
and INCIDENT_LEVEL = #{pd.incidentLevel}
|
||||
</if>
|
||||
<if test="pd.incidentType != null and pd.incidentLevel != ''">
|
||||
and incident_type = #{pd.incidentType}
|
||||
<if test="pd.incidentType != null and pd.incidentType != ''">
|
||||
and INCIDENT_TYPE = #{pd.incidentType}
|
||||
</if>
|
||||
<if test="1 == 1">
|
||||
and is_deleted = 0
|
||||
and IS_DELETED = 0
|
||||
</if>
|
||||
</where>
|
||||
order by incident_date desc , companyName
|
||||
order by INCIDENT_DATE desc , companyName
|
||||
</select>
|
||||
|
||||
<select id="getById" resultType="com.zcloud.entity.PageData">
|
||||
select cast(accident_id AS CHAR) as id,
|
||||
incident_number as incidentNumber,
|
||||
incident_name as incidentName,
|
||||
incident_type as incidentType,
|
||||
incident_level as incidentLevel,
|
||||
select ACCIDENT_ID as id,
|
||||
INCIDENT_NUMBER as incidentNumber,
|
||||
INCIDENT_NAME as incidentName,
|
||||
INCIDENT_TYPE as incidentType,
|
||||
INCIDENT_LEVEL as incidentLevel,
|
||||
CORP_NAME as companyName,
|
||||
incident_nature as incidentNature,
|
||||
`location` as location,
|
||||
incident_date as incidentDate,
|
||||
direct_loss as directLoss,
|
||||
injured as injured,
|
||||
fatalities as fatalities,
|
||||
seriously_injured as seriouslyInjured,
|
||||
cause as cause,
|
||||
summary as summary,
|
||||
photos as photos,
|
||||
analysis as analysis,
|
||||
suggestions as suggestions,
|
||||
measures as measures,
|
||||
ar.creator as creator,
|
||||
report_date as reportDate
|
||||
from accident_records as ar
|
||||
INCIDENT_NATURE as incidentNature,
|
||||
LOCATION as location,
|
||||
INCIDENT_DATE as incidentDate,
|
||||
DIRECT_LOSS as directLoss,
|
||||
INJURED as injured,
|
||||
FATALITIES as fatalities,
|
||||
SERIOUSLY_INJURED as seriouslyInjured,
|
||||
CAUSE as cause,
|
||||
SUMMARY as summary,
|
||||
PHOTOS as photos,
|
||||
ANALYSIS as analysis,
|
||||
SUGGESTIONS as suggestions,
|
||||
MEASURES as measures,
|
||||
ar.CREATOR as creator,
|
||||
REPORT_DATE as reportDate
|
||||
from bus_accident as ar
|
||||
left join bus_corp_info as bci on ar.corpinfo_id = bci.CORPINFO_ID
|
||||
where ar.accident_id = #{id}
|
||||
and ar.is_deleted = 0;
|
||||
where ar.ACCIDENT_ID = #{id}
|
||||
and ar.IS_DELETED = 0;
|
||||
</select>
|
||||
|
||||
<insert id="save" parameterType="com.zcloud.entity.accident.AccidentRecords">
|
||||
insert into accident_records
|
||||
insert into bus_accident
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">
|
||||
accident_id,
|
||||
ACCIDENT_ID,
|
||||
</if>
|
||||
<if test="incidentNumber != null">
|
||||
incident_number,
|
||||
INCIDENT_NUMBER,
|
||||
</if>
|
||||
<if test="incidentName != null">
|
||||
incident_name,
|
||||
INCIDENT_NAME,
|
||||
</if>
|
||||
<if test="incidentType != null">
|
||||
incident_type,
|
||||
INCIDENT_TYPE,
|
||||
</if>
|
||||
<if test="corpinfoId != null">
|
||||
corpinfo_id,
|
||||
CORPINFO_ID,
|
||||
</if>
|
||||
<if test="incidentLevel != null">
|
||||
incident_level,
|
||||
INCIDENT_LEVEL,
|
||||
</if>
|
||||
<if test="incidentNature != null">
|
||||
incident_nature,
|
||||
INCIDENT_NATURE,
|
||||
</if>
|
||||
<if test="location != null">
|
||||
location,
|
||||
LOCATION,
|
||||
</if>
|
||||
<if test="incidentDate != null">
|
||||
incident_date,
|
||||
INCIDENT_DATE,
|
||||
</if>
|
||||
<if test="directLoss != null">
|
||||
direct_loss,
|
||||
DIRECT_LOSS,
|
||||
</if>
|
||||
<if test="injured != null">
|
||||
injured,
|
||||
INJURED,
|
||||
</if>
|
||||
<if test="fatalities != null">
|
||||
fatalities,
|
||||
FATALITIES,
|
||||
</if>
|
||||
<if test="seriouslyInjured != null">
|
||||
seriously_injured,
|
||||
SERIOUSLY_INJURED,
|
||||
</if>
|
||||
<if test="cause != null">
|
||||
cause,
|
||||
CAUSE,
|
||||
</if>
|
||||
<if test="summary != null">
|
||||
summary,
|
||||
SUMMARY,
|
||||
</if>
|
||||
<if test="photos != null">
|
||||
photos,
|
||||
PHOTOS,
|
||||
</if>
|
||||
<if test="analysis != null">
|
||||
analysis,
|
||||
ANALYSIS,
|
||||
</if>
|
||||
<if test="suggestions != null">
|
||||
suggestions,
|
||||
SUGGESTIONS,
|
||||
</if>
|
||||
<if test="measures != null">
|
||||
measures,
|
||||
MEASURES,
|
||||
</if>
|
||||
<if test="creator != null">
|
||||
creator,
|
||||
CREATOR,
|
||||
</if>
|
||||
<if test="reportDate != null">
|
||||
report_date,
|
||||
REPORT_DATE,
|
||||
</if>
|
||||
<if test="createdBy != null">
|
||||
created_by,
|
||||
CREATED_BY,
|
||||
</if>
|
||||
<if test="createdTime != null">
|
||||
created_time,
|
||||
CREATED_TIME,
|
||||
</if>
|
||||
<if test="updatedBy != null">
|
||||
updated_by,
|
||||
UPDATED_BY,
|
||||
</if>
|
||||
<if test="updatedTime != null">
|
||||
updated_time,
|
||||
UPDATED_TIME,
|
||||
</if>
|
||||
<if test="isDeleted != null">
|
||||
is_deleted
|
||||
IS_DELETED
|
||||
</if>
|
||||
</trim>
|
||||
values
|
||||
|
@ -226,7 +226,7 @@
|
|||
</insert>
|
||||
|
||||
<update id="updateById" parameterType="com.zcloud.entity.accident.AccidentRecords">
|
||||
UPDATE accident_records
|
||||
UPDATE bus_accident
|
||||
<set>
|
||||
<if test="incidentNumber != null">incident_number = #{incidentNumber},</if>
|
||||
<if test="incidentName != null">incident_name = #{incidentName},</if>
|
||||
|
@ -258,7 +258,7 @@
|
|||
</update>
|
||||
|
||||
<update id="delete">
|
||||
update accident_records
|
||||
update bus_accident
|
||||
set is_deleted = 1
|
||||
where
|
||||
accident_id IN
|
||||
|
@ -268,32 +268,31 @@
|
|||
</update>
|
||||
|
||||
<select id="listExcel" resultType="com.zcloud.entity.accident.dto.AccidentRecordsExcel" parameterType="pd">
|
||||
select incident_number as incidentNumber,
|
||||
incident_name as incidentName,
|
||||
select incident_number as incidentNumber,
|
||||
incident_name as incidentName,
|
||||
(select NAME
|
||||
from sys_dictionaries
|
||||
where PARENT_ID = '8d4140a900184b60836ad1a6490fd510'
|
||||
and BIANMA = incident_type) as 'incidentType',
|
||||
and BIANMA = incident_type) as 'incidentType',
|
||||
(select NAME
|
||||
from sys_dictionaries
|
||||
where PARENT_ID = 'b61a1edc59c0430c8741c5f51aa26c3c'
|
||||
and BIANMA = incident_level) as 'incidentLevel',
|
||||
CORP_NAME as 'companyName',
|
||||
incident_nature as incidentNature,
|
||||
`location` as location,
|
||||
date_format(incident_date, '%Y年%m月%d日%H时%I分%s秒') as 'incidentDate',
|
||||
direct_loss as directLoss,
|
||||
and BIANMA = incident_level) as 'incidentLevel',
|
||||
CORP_NAME as 'companyName',
|
||||
`location` as location,
|
||||
incident_date as 'incidentDate',
|
||||
direct_loss as directLoss,
|
||||
injured,
|
||||
fatalities,
|
||||
seriously_injured as seriouslyInjured,
|
||||
seriously_injured as seriouslyInjured,
|
||||
cause,
|
||||
summary,
|
||||
analysis,
|
||||
suggestions,
|
||||
measures,
|
||||
ar.creator as creator,
|
||||
date_format(report_date, '%Y年%m月%d日%H时%I分%s秒') as 'reportDate'
|
||||
from accident_records as ar
|
||||
ar.creator as creator,
|
||||
report_date as 'reportDate'
|
||||
from bus_accident as ar
|
||||
left join bus_corp_info as bci on ar.corpinfo_id = bci.CORPINFO_ID
|
||||
<where>
|
||||
<if test="pd.corpInfoId != null and pd.corpInfoId != ''">
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.zcloud.service.accident.service;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.zcloud.entity.Page;
|
||||
import com.zcloud.entity.PageData;
|
||||
import com.zcloud.entity.accident.AccidentRecords;
|
||||
|
@ -63,25 +62,12 @@ public class AccidentRecordsServiceTest {
|
|||
|
||||
@Test
|
||||
public void testGetById() {
|
||||
Long id = 1L;
|
||||
PageData expectedPageData = new PageData();
|
||||
when(accidentRecordsMapper.getById(id)).thenReturn(expectedPageData);
|
||||
|
||||
PageData resultPageData = accidentRecordsService.getById(id);
|
||||
|
||||
assertEquals(expectedPageData, resultPageData);
|
||||
verify(accidentRecordsMapper, times(1)).getById(id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSave() {
|
||||
AccidentRecords accidentRecords = new AccidentRecords();
|
||||
accidentRecords.setId(IdUtil.getSnowflake(1, 1).nextId());
|
||||
accidentRecords.setCreatedBy("测试");
|
||||
accidentRecords.setCreatedTime(new Date());
|
||||
accidentRecords.setIsDeleted(0);
|
||||
|
||||
accidentRecordsService.save(accidentRecords);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue