Commit 9ca3a927 authored by wuxiaokai's avatar wuxiaokai

路口管理-修改

parent dbb53753
......@@ -21,8 +21,7 @@ public class MybatisPlusGenerator {
private static final String USERNAME = "root";
private static final String PASSWORD = "Wanji300552";
private static final String[] TABLES = {
"t_base_area_info",
"t_base_cross_info"
"t_base_area_info"
};
private static final String TEMPLATE_PATH = "/templates/mapper.xml.ftl";
private static final String MAPPER_PATH = "signal-web-service/src/main/resources/mapper/";
......
......@@ -7,11 +7,11 @@ import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 区域基础 前端控制器
* 区域基础信息 前端控制器
* </p>
*
* @author wj
* @since 2022-11-28
* @since 2022-12-16
*/
@RestController
@RequestMapping("/t-base-area-info")
......
package net.wanji.web.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
......@@ -12,11 +13,11 @@ import java.util.Date;
/**
* <p>
* 区域基础
* 区域基础信息
* </p>
*
* @author wj
* @since 2022-11-28
* @since 2022-12-16
*/
@Getter
@Setter
......@@ -29,7 +30,7 @@ public class TBaseAreaInfo implements Serializable {
/**
* 主键
*/
@TableId("id")
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/**
......@@ -53,8 +54,8 @@ public class TBaseAreaInfo implements Serializable {
/**
* 父节点
*/
@TableField("parent")
private Integer parent;
@TableField("parent_code")
private Integer parentCode;
/**
* 区域中心点
......
package net.wanji.web.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.web.entity.TBaseAreaInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.web.po.AreaTreePO;
import org.springframework.stereotype.Repository;
......@@ -9,18 +9,17 @@ import java.util.List;
/**
* <p>
* 区域基础 Mapper 接口
* 区域基础信息 Mapper 接口
* </p>
*
* @author wj
* @since 2022-11-28
* @since 2022-12-16
*/
@Repository
public interface TBaseAreaInfoMapper extends BaseMapper<TBaseAreaInfo> {
int deleteByPrimaryKey(Integer id);
@Override
int insert(TBaseAreaInfo record);
int insertSelective(TBaseAreaInfo record);
......@@ -34,5 +33,4 @@ public interface TBaseAreaInfoMapper extends BaseMapper<TBaseAreaInfo> {
int updateByPrimaryKey(TBaseAreaInfo record);
List<AreaTreePO> selectAreaTree();
}
......@@ -8,11 +8,11 @@ import org.springframework.stereotype.Service;
/**
* <p>
* 区域基础 服务实现类
* 区域基础信息 服务实现类
* </p>
*
* @author wj
* @since 2022-11-28
* @since 2022-12-16
*/
@Service
public class TBaseAreaInfoService extends ServiceImpl<TBaseAreaInfoMapper, TBaseAreaInfo> implements IService<TBaseAreaInfo> {
......
......@@ -11,6 +11,7 @@ import net.wanji.web.mapper.TBaseCrossInfoMapper;
import net.wanji.web.po.AreaTreePO;
import net.wanji.web.po.CrossInfoPO;
import net.wanji.web.po.PageResultPO;
import net.wanji.web.util.IdWorker;
import net.wanji.web.vo.BaseCrossInfoVO;
import net.wanji.web.vo.CrossInfoVO;
import org.springframework.beans.BeanUtils;
......@@ -80,7 +81,9 @@ public class TBaseCrossInfoService extends ServiceImpl<TBaseCrossInfoMapper, TBa
* @return {@link Result}<{@link String}>
*/
public Result<String> updateOne(BaseCrossInfoVO crossInfoPO) {
TBaseCrossInfo record = getBaseCrossInfo(crossInfoPO);
TBaseCrossInfo record = new TBaseCrossInfo();
BeanUtils.copyProperties(crossInfoPO, record);
record.setGmtModified(new Date());
int update = crossInfoMapper.updateByPrimaryKeySelective(record);
if (update > 0) {
return Result.success("修改成功");
......@@ -89,9 +92,13 @@ public class TBaseCrossInfoService extends ServiceImpl<TBaseCrossInfoMapper, TBa
}
private TBaseCrossInfo getBaseCrossInfo(BaseCrossInfoVO crossInfoPO) {
if (crossInfoPO.getId() == null || crossInfoPO.getId().trim().equals("")) {
IdWorker idWorker = new IdWorker(0, 0);
crossInfoPO.setId(String.valueOf(idWorker.nextId()));
}
if (crossInfoPO.getAreaCode() == null) {
QueryWrapper<TBaseAreaInfo> queryWrapper = new QueryWrapper<>();
queryWrapper.like("name", crossInfoPO.getAreaName());
queryWrapper.lambda().eq(TBaseAreaInfo::getName, crossInfoPO.getAreaName());
// 查询areaCode
List<TBaseAreaInfo> tBaseAreaInfos = areaInfoMapper.selectList(queryWrapper);
if (tBaseAreaInfos != null && tBaseAreaInfos.size() > 0) {
......@@ -100,18 +107,27 @@ public class TBaseCrossInfoService extends ServiceImpl<TBaseCrossInfoMapper, TBa
}
if (crossInfoPO.getAreaName() == null) {
QueryWrapper<TBaseAreaInfo> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("code", crossInfoPO.getAreaCode());
queryWrapper.lambda().eq(TBaseAreaInfo::getCode, crossInfoPO.getAreaCode());
List<TBaseAreaInfo> tBaseAreaInfos = areaInfoMapper.selectList(queryWrapper);
if (tBaseAreaInfos != null && tBaseAreaInfos.size() > 0) {
crossInfoPO.setAreaName(tBaseAreaInfos.get(0).getName());
}
}
if (crossInfoPO.getIsSend() == null) {
crossInfoPO.setIsSend(1);
}
if (crossInfoPO.getIsSignal() == null) {
crossInfoPO.setIsSignal(1);
}
if (crossInfoPO.getIsStart() == null) {
crossInfoPO.setIsStart(1);
}
if (crossInfoPO.getLocation() == null) {
crossInfoPO.setLocation("null");
}
TBaseCrossInfo record = new TBaseCrossInfo();
BeanUtils.copyProperties(crossInfoPO, record);
record.setGmtModified(new Date());
if (record.getLocation() == null) {
record.setLocation("null");
}
return record;
}
......
package net.wanji.web.util;
import org.springframework.stereotype.Component;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.NetworkInterface;
/**
* <p>名称:IdWorker.java</p>
* <p>描述:分布式自增长ID</p>
* <pre>
* Twitter的 Snowflake JAVA实现方案
* </pre>
* 核心代码为其IdWorker这个类实现,其原理结构如下,我分别用一个0表示一位,用—分割开部分的作用:
* 1||0---0000000000 0000000000 0000000000 0000000000 0 --- 00000 ---00000 ---000000000000
* 在上面的字符串中,第一位为未使用(实际上也可作为long的符号位),接下来的41位为毫秒级时间,
* 然后5位datacenter标识位,5位机器ID(并不算标识符,实际是为线程标识),
* 然后12位该毫秒内的当前毫秒内的计数,加起来刚好64位,为一个Long型。
* 这样的好处是,整体上按照时间自增排序,并且整个分布式系统内不会产生ID碰撞(由datacenter和机器ID作区分),
* 并且效率较高,经测试,snowflake每秒能够产生26万ID左右,完全满足需要。
* <p>
* 64位ID (42(毫秒)+5(机器ID)+5(业务编码)+12(重复累加))
*
* @author Polim
*/
@Component
public class IdWorker {
/**
* 时间起始标记点,作为基准,一般取系统的最近时间(一旦确定不能变动)
*/
private final static long TWEPOCH = 1288834974657L;
/**
* 机器标识位数
*/
private final static long WORKER_ID_BITS = 5L;
/**
* 数据中心标识位数
*/
private final static long DATACENTER_ID_BITS = 5L;
/**
* 机器ID最大值
*/
private final static long MAX_WORKER_ID = ~(-1L << WORKER_ID_BITS);
/**
* 数据中心ID最大值
*/
private final static long MAX_DATACENTER_ID = ~(-1L << DATACENTER_ID_BITS);
/**
* 毫秒内自增位
*/
private final static long SEQUENCE_BITS = 12L;
/**
* 机器ID偏左移12位
*/
private final static long WORKER_ID_SHIFT = SEQUENCE_BITS;
/**
* 数据中心ID左移17位
*/
private final static long DATACENTER_ID_SHIFT = SEQUENCE_BITS + WORKER_ID_BITS;
/**
* 时间毫秒左移22位
*/
private final static long TIMESTAMP_LEFT_SHIFT = SEQUENCE_BITS + WORKER_ID_BITS + DATACENTER_ID_BITS;
private final static long SEQUENCE_MASK = ~(-1L << SEQUENCE_BITS);
/**
* 上次生产id时间戳
*/
private static long lastTimestamp = -1L;
/**
* 0,并发控制
*/
private long sequence = 0L;
private final long workerId;
/**
* 数据标识id部分
*/
private final long datacenterId;
public IdWorker() {
this.datacenterId = getDatacenterId();
this.workerId = getMaxWorkerId(datacenterId);
}
/**
* @param workerId 工作机器ID
* @param datacenterId 序列号
*/
public IdWorker(long workerId, long datacenterId) {
if (workerId > MAX_WORKER_ID || workerId < 0) {
throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", MAX_WORKER_ID));
}
if (datacenterId > MAX_DATACENTER_ID || datacenterId < 0) {
throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", MAX_DATACENTER_ID));
}
this.workerId = workerId;
this.datacenterId = datacenterId;
}
/**
* 获取下一个ID
*/
public synchronized long nextId() {
long timestamp = timeGen();
if (timestamp < lastTimestamp) {
throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
}
if (lastTimestamp == timestamp) {
// 当前毫秒内,则+1
sequence = (sequence + 1) & SEQUENCE_MASK;
if (sequence == 0) {
// 当前毫秒内计数满了,则等待下一秒
timestamp = tilNextMillis(lastTimestamp);
}
} else {
sequence = 0L;
}
lastTimestamp = timestamp;
// ID偏移组合生成最终的ID,并返回ID
return ((timestamp - TWEPOCH) << TIMESTAMP_LEFT_SHIFT)
| (datacenterId << DATACENTER_ID_SHIFT)
| (workerId << WORKER_ID_SHIFT) | sequence;
}
private long tilNextMillis(final long lastTimestamp) {
long timestamp = this.timeGen();
while (timestamp <= lastTimestamp) {
timestamp = this.timeGen();
}
return timestamp;
}
private long timeGen() {
return System.currentTimeMillis();
}
/**
* <p>
* 获取 maxWorkerId
* </p>
*/
protected static long getMaxWorkerId(long datacenterId) {
StringBuilder mpid = new StringBuilder();
mpid.append(datacenterId);
String name = ManagementFactory.getRuntimeMXBean().getName();
if (!name.isEmpty()) {
/*
* GET jvmPid
*/
mpid.append(name.split("@")[0]);
}
/*
* MAC + PID 的 hashcode 获取16个低位
*/
return (mpid.toString().hashCode() & 0xffff) % (IdWorker.MAX_WORKER_ID + 1);
}
/**
* <p>
* 数据标识id部分
* </p>
*/
protected static long getDatacenterId() {
long id = 0L;
try {
InetAddress ip = InetAddress.getLocalHost();
NetworkInterface network = NetworkInterface.getByInetAddress(ip);
if (network == null) {
id = 1L;
} else {
byte[] mac = network.getHardwareAddress();
id = ((0x000000FF & (long) mac[mac.length - 1])
| (0x0000FF00 & (((long) mac[mac.length - 2]) << 8))) >> 6;
id = id % (IdWorker.MAX_DATACENTER_ID + 1);
}
} catch (Exception e) {
System.out.println(" getDatacenterId: " + e.getMessage());
}
return id;
}
public static void main(String[] args) {
IdWorker idWorker = new IdWorker(0, 0);
for (int i = 0; i < 10000; i++) {
long nextId = idWorker.nextId();
System.out.println(nextId);
}
}
}
\ No newline at end of file
......@@ -31,34 +31,35 @@ public class BaseCrossInfoVO {
* 路口名称
*/
@ApiModelProperty(value = "路口名称", required = true)
@NotNull(message = "路口名称不可为空", groups = {Save.class, Update.class})
@NotNull(message = "路口名称不可为空", groups = {Save.class})
private String name;
/**
* 路口类型
*/
@ApiModelProperty(value = "路口类型", required = true)
@NotNull(message = "路口类型不可为空", groups = {Save.class, Update.class})
//@NotNull(message = "路口类型不可为空", groups = {Save.class, Update.class})
private Integer type;
/**
* 路口级别
*/
@ApiModelProperty(value = "路口级别", required = true)
@NotNull(message = "路口级别不可为空", groups = {Save.class, Update.class})
//@NotNull(message = "路口级别不可为空", groups = {Save.class, Update.class})
private Integer level;
/**
* 行政区划代码
*/
@ApiModelProperty(value = "行政区划代码")
@NotNull(message = "行政区划代码不可为空", groups = {Save.class, Update.class})
//@NotNull(message = "行政区划代码不可为空", groups = {Save.class, Update.class})
private Integer areaCode;
/**
* 行政区划名称
*/
@ApiModelProperty(value = "行政区划名称", required = true)
@NotNull(message = "行政区划名称不可为空", groups = {Save.class})
private String areaName;
/**
......@@ -72,27 +73,27 @@ public class BaseCrossInfoVO {
* 是否信控路口:1是;0否
*/
@ApiModelProperty(value = "是否信控路口:1是;0否", required = true)
@NotNull(message = "是否信控路口不可为空", groups = {Save.class, Update.class})
@Max(value = 1, message = "是否信控路口:1是;0否", groups = {Save.class, Update.class})
@Min(value = 0, message = "是否信控路口:1是;0否", groups = {Save.class, Update.class})
//@NotNull(message = "是否信控路口不可为空", groups = {Save.class, Update.class})
//@Max(value = 1, message = "是否信控路口:1是;0否", groups = {Save.class, Update.class})
//@Min(value = 0, message = "是否信控路口:1是;0否", groups = {Save.class, Update.class})
private Integer isSignal;
/**
* 是否启动优化:1是;0否
*/
@ApiModelProperty(value = "是否启动优化:1是;0否", required = true)
@NotNull(message = "是否启动优化不可为空", groups = {Save.class, Update.class})
@Max(value = 1, message = "是否启动优化:1是;0否", groups = {Save.class, Update.class})
@Min(value = 0, message = "是否启动优化:1是;0否", groups = {Save.class, Update.class})
//@NotNull(message = "是否启动优化不可为空", groups = {Save.class, Update.class})
//@Max(value = 1, message = "是否启动优化:1是;0否", groups = {Save.class, Update.class})
//@Min(value = 0, message = "是否启动优化:1是;0否", groups = {Save.class, Update.class})
private Integer isStart;
/**
* 是否下发方案:1是;0否
*/
@ApiModelProperty(value = "是否下发方案:1是;0否", required = true)
@NotNull(message = "是否下发方案不可为空", groups = {Save.class, Update.class})
@Max(value = 1, message = "是否下发方案:1是;0否", groups = {Save.class, Update.class})
@Min(value = 0, message = "是否下发方案:1是;0否", groups = {Save.class, Update.class})
//@NotNull(message = "是否下发方案不可为空", groups = {Save.class, Update.class})
//@Max(value = 1, message = "是否下发方案:1是;0否", groups = {Save.class, Update.class})
//@Min(value = 0, message = "是否下发方案:1是;0否", groups = {Save.class, Update.class})
private Integer isSend;
/**
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="net.wanji.web.mapper.TBaseAreaInfoMapper">
<resultMap id="BaseResultMap" type="net.wanji.web.entity.TBaseAreaInfo">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="code" property="code" jdbcType="INTEGER"/>
<result column="name" property="name" jdbcType="VARCHAR"/>
<result column="type" property="type" jdbcType="TINYINT"/>
<result column="parent" property="parent" jdbcType="INTEGER"/>
<result column="parent_code" property="parentCode" jdbcType="INTEGER"/>
<result column="location" property="location" jdbcType="VARCHAR"/>
<result column="gmt_create" property="gmtCreate" jdbcType="TIMESTAMP"/>
<result column="gmt_modified" property="gmtModified" jdbcType="TIMESTAMP"/>
......@@ -15,7 +15,7 @@
<result column="polylines" property="polylines" jdbcType="LONGVARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
id, code, name, type, parent, location, gmt_create, gmt_modified
id, code, name, type, parent_code, location, gmt_create, gmt_modified
</sql>
<sql id="Blob_Column_List">
polylines
......@@ -35,10 +35,10 @@
</delete>
<insert id="insert" parameterType="net.wanji.web.entity.TBaseAreaInfo">
insert into t_base_area_info (id, code, name,
type, parent, location,
type, parent_code, location,
gmt_create, gmt_modified, polylines)
values (#{id,jdbcType=INTEGER}, #{code,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR},
#{type,jdbcType=TINYINT}, #{parent,jdbcType=INTEGER}, #{location,jdbcType=VARCHAR},
#{type,jdbcType=TINYINT}, #{parentCode,jdbcType=INTEGER}, #{location,jdbcType=VARCHAR},
#{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP}, #{polylines,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective" parameterType="net.wanji.web.entity.TBaseAreaInfo">
......@@ -56,8 +56,8 @@
<if test="type != null">
type,
</if>
<if test="parent != null">
parent,
<if test="parentCode != null">
parent_code,
</if>
<if test="location != null">
location,
......@@ -85,8 +85,8 @@
<if test="type != null">
#{type,jdbcType=TINYINT},
</if>
<if test="parent != null">
#{parent,jdbcType=INTEGER},
<if test="parentCode != null">
#{parentCode,jdbcType=INTEGER},
</if>
<if test="location != null">
#{location,jdbcType=VARCHAR},
......@@ -114,8 +114,8 @@
<if test="type != null">
type = #{type,jdbcType=TINYINT},
</if>
<if test="parent != null">
parent = #{parent,jdbcType=INTEGER},
<if test="parentCode != null">
parent_code = #{parentCode,jdbcType=INTEGER},
</if>
<if test="location != null">
location = #{location,jdbcType=VARCHAR},
......@@ -137,7 +137,7 @@
set code = #{code,jdbcType=INTEGER},
name = #{name,jdbcType=VARCHAR},
type = #{type,jdbcType=TINYINT},
parent = #{parent,jdbcType=INTEGER},
parent_code = #{parentCode,jdbcType=INTEGER},
location = #{location,jdbcType=VARCHAR},
gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
......@@ -149,13 +149,13 @@
set code = #{code,jdbcType=INTEGER},
name = #{name,jdbcType=VARCHAR},
type = #{type,jdbcType=TINYINT},
parent = #{parent,jdbcType=INTEGER},
parent_code = #{parentCode,jdbcType=INTEGER},
location = #{location,jdbcType=VARCHAR},
gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectAreaTree" resultType="net.wanji.web.po.AreaTreePO">
select code areaCode, name areaName, parent parentCode from t_base_area_info
select id, code, name areaName, parent_code parentCode from t_base_area_info
</select>
</mapper>
\ No newline at end of file
</mapper>
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