Commit d75e3b3f by 向延琳

增加唯一性校验

1 parent d6bf9868
......@@ -3,6 +3,9 @@ package cn.com.glsx.stdinterface.modules.mapper;
import cn.com.glsx.stdinterface.modules.entity.DeviceJourney;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
/**
* 新e盾|里程表
......@@ -12,4 +15,12 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface DeviceJourneyMapper extends CommonBaseMapper<DeviceJourney> {
/**
* 根据开始时间和sn查找
* @param sn 设备号
* @param beginTime 开始时间
* @return 设备行程信息
*/
DeviceJourney selectBySnAndBeginTime(@Param("sn")String sn, @Param("beginTime")Date beginTime);
}
\ No newline at end of file
......@@ -48,6 +48,12 @@ public class JourneyService {
if (Objects.isNull(deviceJourneyDTO)) {
return;
}
DeviceJourney journey = deviceJourneyMapper.selectBySnAndBeginTime(deviceJourneyDTO.getSn(), deviceJourneyDTO.getBeginTime());
if(Objects.nonNull(journey)) {
log.warn("该设备同样的开始时间行程数据已经存在" +
"sn: " + deviceJourneyDTO.getSn() + "beginTime:" + deviceJourneyDTO.getBeginTime());
return;
}
//从车辆信息中获取创建人信息
Vehicle vehicle = getVehicleBySn(deviceJourneyDTO.getSn());
if (Objects.isNull(vehicle)) {
......
......@@ -26,4 +26,15 @@
id, sn, vd_id, begin_time, end_time, begin_address, end_address, mileage, del_flag,
created_date, created_by, updated_date, updated_by
</sql>
<select id="selectBySnAndBeginTime" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_device_journey
<where>
and sn = #{sn}
and begin_time = #{beginTime}
</where>
limit 1
</select>
</mapper>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!