Commit cf43a81f authored by hanbing's avatar hanbing

系统管理-设备管理-信号机管理-添加或删除

parent 6f54e94d
package net.wanji.utc.common.exception;
/**
* @author Kent HAN
* @date 2022/11/15 13:57
*/
public class IpPortException extends RuntimeException{
public IpPortException(String message) {
super(message);
}
public IpPortException(String message, Exception e) {
super(message,e);
}
}
package net.wanji.utc.common.exception;
/**
* @author Kent HAN
* @date 2022/11/15 13:57
*/
public class PortFormatException extends RuntimeException{
public PortFormatException(String message) {
super(message);
}
public PortFormatException(String message, Exception e) {
super(message,e);
}
}
......@@ -45,15 +45,15 @@ public class CrossInfoController {
return jsonViewObject.success(crossInfoListOutVOPageInfo);
}
// @ApiOperation(value = "接口添加或修改", notes = "接口添加或修改", consumes = MediaType.APPLICATION_JSON)
// @PostMapping(value = "/insertOrUpdate", consumes = MediaType.APPLICATION_JSON)
// public JsonViewObject insertOrUpdate(@RequestBody ManufacturerApiInfoInsertOrUpdateInVO inVO) {
// manufacturerApiInfoService.insertOrUpdate(inVO);
// JsonViewObject jsonViewObject = JsonViewObject.newInstance();
//
// return jsonViewObject.success();
// }
//
@ApiOperation(value = "信号机添加或修改", notes = "信号机添加或修改", consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/insertOrUpdate", consumes = MediaType.APPLICATION_JSON)
public JsonViewObject insertOrUpdate(@RequestBody CrossInfoInsertOrUpdateInVO inVO) {
crossInfoService.insertOrUpdate(inVO);
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
return jsonViewObject.success();
}
// @ApiOperation(value = "接口删除", notes = "接口删除", consumes = MediaType.APPLICATION_JSON)
// @PostMapping(value = "/delete", consumes = MediaType.APPLICATION_JSON)
// public JsonViewObject delete(@RequestBody DeleteListInVO inVO) {
......
......@@ -26,4 +26,8 @@ public interface CrossInfoMapper {
List<CrossInfoPO> selectByOptionals(@Param("crossName") String crossName,
@Param("manufacturerId") Integer manufacturerId);
void insertOne(CrossInfoPO crossInfoPO);
void updateOne(CrossInfoPO crossInfoPO);
}
package net.wanji.utc.service.systemadmin;
import com.github.pagehelper.PageInfo;
import net.wanji.utc.vo.systemadmin.CrossInfoInsertOrUpdateInVO;
import net.wanji.utc.vo.systemadmin.CrossInfoListInVO;
import net.wanji.utc.vo.systemadmin.CrossInfoListOutVO;
......@@ -10,4 +11,6 @@ import net.wanji.utc.vo.systemadmin.CrossInfoListOutVO;
*/
public interface CrossInfoService {
PageInfo<CrossInfoListOutVO> list(CrossInfoListInVO crossInfoListInVO);
void insertOrUpdate(CrossInfoInsertOrUpdateInVO inVO);
}
package net.wanji.utc.service.systemadmin.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import net.wanji.utc.common.exception.IpPortException;
import net.wanji.utc.common.exception.PortFormatException;
import net.wanji.utc.mapper.CrossInfoMapper;
import net.wanji.utc.mapper.ManufacturerInfoMapper;
import net.wanji.utc.po.CrossInfoPO;
import net.wanji.utc.po.ManufacturerInfoPO;
import net.wanji.utc.service.systemadmin.CrossInfoService;
import net.wanji.utc.util.PageUtils;
import net.wanji.utc.vo.systemadmin.CrossInfoInsertOrUpdateInVO;
import net.wanji.utc.vo.systemadmin.CrossInfoListInVO;
import net.wanji.utc.vo.systemadmin.CrossInfoListOutVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
......@@ -58,4 +63,46 @@ public class CrossInfoServiceImpl implements CrossInfoService {
return crossInfoListOutVOPageInfo;
}
@Override
public void insertOrUpdate(CrossInfoInsertOrUpdateInVO inVO) {
CrossInfoPO crossInfoPO = new CrossInfoPO();
BeanUtils.copyProperties(inVO, crossInfoPO);
// IP和端口
String ipPort = inVO.getIpPort();
String[] split = ipPort.split(":");
if (split.length != 2) {
throw new IpPortException("IP/端口格式错误,正确格式为 192.168.1.23:8080");
}
String portStr = split[1];
Integer port = null;
try {
port = Integer.parseInt(portStr);
} catch (NumberFormatException e){
throw new PortFormatException("端口必须为数字");
}
crossInfoPO.setIp(split[0]);
crossInfoPO.setPort(port);
// 厂商ID
String manufacturerNick = inVO.getManufacturerNick();
Integer manufacturerId = manufacturerInfoMapper.selectIdByNick(manufacturerNick);
crossInfoPO.setManufacturerId(manufacturerId);
// 安装时间
String installTimeStr = inVO.getInstallTime();
Date installTime = DateUtil.parse(installTimeStr);
crossInfoPO.setInstallTime(installTime);
String id = inVO.getId();
if (id == null || "".equals(id)) {
// 添加
crossInfoPO.setId(IdUtil.simpleUUID());
crossInfoMapper.insertOne(crossInfoPO);
} else {
// 修改
crossInfoMapper.updateOne(crossInfoPO);
}
}
}
......@@ -56,7 +56,6 @@ public class ManufacturerApiInfoServiceImpl implements ManufacturerApiInfoServic
@Override
public void insertOrUpdate(ManufacturerApiInfoInsertOrUpdateInVO inVO) {
Integer id = inVO.getId();
ManufacturerApiInfoPO manufacturerApiInfoPO = new ManufacturerApiInfoPO();
BeanUtils.copyProperties(inVO, manufacturerApiInfoPO);
String typeStr = inVO.getApiType();
......@@ -65,6 +64,8 @@ public class ManufacturerApiInfoServiceImpl implements ManufacturerApiInfoServic
Integer manufacturerId = manufacturerInfoMapper.selectIdByNick(manufacturerName);
manufacturerApiInfoPO.setType(typeCode);
manufacturerApiInfoPO.setManufacturerId(manufacturerId);
Integer id = inVO.getId();
if (id == null || id == 0) {
// 添加
manufacturerApiInfoMapper.insertOne(manufacturerApiInfoPO);
......
package net.wanji.utc.vo.systemadmin;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author Kent HAN
* @date 2022/11/25 10:21
*/
@Data
@ApiModel(value = "CrossInfoInsertOrUpdateInVO", description = "信号机新增或修改输入参数")
public class CrossInfoInsertOrUpdateInVO {
@ApiModelProperty(value = "路口ID。不传ID为新增,传ID为修改",notes = "")
private String id ;
/** 信号机编号 */
@ApiModelProperty(required = true, value = "信号机编号",notes = "")
private String code ;
/** 路口名称 */
@ApiModelProperty(required = true, value = "路口名称",notes = "")
private String name ;
/** 信号机IP/端口 */
@ApiModelProperty(required = true, value = "信号机IP/端口",notes = "")
private String ipPort ;
/** 厂商名称 */
@ApiModelProperty(required = true, value = "厂商名称",notes = "")
private String manufacturerNick ;
/** 信号机版本 */
@ApiModelProperty(required = true, value = "信号机版本",notes = "")
private String version ;
/** 信号机型号 */
@ApiModelProperty(required = true, value = "信号机型号",notes = "")
private String model ;
/** 安装时间 */
@ApiModelProperty(required = true, value = "安装时间,格式 2022-11-18 10:11:47",notes = "")
private String installTime ;
/** 安装位置 */
@ApiModelProperty(required = true, value = "安装位置",notes = "")
private String location ;
}
......@@ -4,14 +4,12 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author Kent HAN
* @date 2022/11/24 15:20
*/
@Data
@ApiModel(value = "ManufacturerApiInfoInsertOrUpdateInVO", description = "接口新增或修改删除输入参数")
@ApiModel(value = "ManufacturerApiInfoInsertOrUpdateInVO", description = "接口新增或修改输入参数")
public class ManufacturerApiInfoInsertOrUpdateInVO {
/** 接口ID */
@ApiModelProperty(value = "接口ID。不传ID为新增,传ID为修改",notes = "")
......
......@@ -25,6 +25,45 @@
</foreach>
</insert>
<insert id="insertOne">
insert into t_cross_info(id, name,code,manufacturer_id,ip,port,location,version,model,install_time)
values (#{id},#{name},#{code},#{manufacturerId},#{ip},#{port},#{location},#{version},#{model},#{installTime})
</insert>
<update id="updateOne">
update t_cross_info
<set>
<if test="name != null and name != ''">
name = #{name},
</if>
<if test="code != null and code != ''">
code = #{code},
</if>
<if test="manufacturerId != null and manufacturerId != ''">
manufacturer_id = #{manufacturerId},
</if>
<if test="ip != null and ip != ''">
ip = #{ip},
</if>
<if test="port != null and port != ''">
port = #{port},
</if>
<if test="location != null and location != ''">
location = #{location},
</if>
<if test="version != null and version != ''">
version = #{version},
</if>
<if test="model != null and model != ''">
model = #{model},
</if>
<if test="installTime != null">
install_time = #{installTime},
</if>
</set>
where id = #{id}
</update>
<select id="selectByPrimaryKey" resultMap="BaseResultMap">
select
id,name,code,manufacturer_id,ip,port,location,version,model,install_time,gmt_create,gmt_modified
......
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