Commit 88ec542a authored by hanbing's avatar hanbing

系统管理-设备管理-接口管理

parent 8cf2af41
...@@ -144,13 +144,6 @@ ...@@ -144,13 +144,6 @@
<groupId>org.glassfish.jersey.media</groupId> <groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId> <artifactId>jersey-media-multipart</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.hikvision.artemis</groupId>
<artifactId>sdk</artifactId>
<version>1.1.7</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/artemis-http-client-1.1.7.jar</systemPath>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -3,7 +3,7 @@ package net.wanji.utc.common.commonentity; ...@@ -3,7 +3,7 @@ package net.wanji.utc.common.commonentity;
import lombok.Data; import lombok.Data;
import net.wanji.utc.common.constant.Constants; import net.wanji.utc.common.constant.Constants;
import net.wanji.utc.common.exception.NoSuchApiException; import net.wanji.utc.common.exception.NoSuchApiException;
import net.wanji.utc.po.ApiInfoPO; import net.wanji.utc.po.ManufacturerApiInfoPO;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
...@@ -23,13 +23,13 @@ public class HttpRequest { ...@@ -23,13 +23,13 @@ public class HttpRequest {
public HttpRequest(String manufacturerAbbr, String apiCode) { public HttpRequest(String manufacturerAbbr, String apiCode) {
// 获取请求地址 // 获取请求地址
ApiInfoPO apiInfoPO = Constants.getManufacturerUrlMap(manufacturerAbbr + ManufacturerApiInfoPO manufacturerApiInfoPO = Constants.getManufacturerUrlMap(manufacturerAbbr +
Constants.SEPARATOR_UNDER_LINE + apiCode); Constants.SEPARATOR_UNDER_LINE + apiCode);
if (apiInfoPO == null) { if (manufacturerApiInfoPO == null) {
throw new NoSuchApiException("没有此接口信息,请在t_manufacturer_api_info表中添加"); throw new NoSuchApiException("没有此接口信息,请在t_manufacturer_api_info表中添加");
} }
url = apiInfoPO.getAddress(); url = manufacturerApiInfoPO.getAddress();
httpMethod = HttpMethod.valueOf(apiInfoPO.getMethod()); httpMethod = HttpMethod.valueOf(manufacturerApiInfoPO.getMethod());
headers = buildHeader(); headers = buildHeader();
} }
......
...@@ -2,9 +2,9 @@ package net.wanji.utc.common.task; ...@@ -2,9 +2,9 @@ package net.wanji.utc.common.task;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.wanji.utc.common.constant.Constants; import net.wanji.utc.common.constant.Constants;
import net.wanji.utc.mapper.ApiInfoMapper; import net.wanji.utc.mapper.ManufacturerApiInfoMapper;
import net.wanji.utc.mapper.ManufacturerInfoMapper; import net.wanji.utc.mapper.ManufacturerInfoMapper;
import net.wanji.utc.po.ApiInfoPO; import net.wanji.utc.po.ManufacturerApiInfoPO;
import net.wanji.utc.po.ManufacturerInfoPO; import net.wanji.utc.po.ManufacturerInfoPO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
...@@ -18,27 +18,27 @@ import java.util.List; ...@@ -18,27 +18,27 @@ import java.util.List;
@EnableAsync @EnableAsync
public class ApiInfoTask { public class ApiInfoTask {
@Autowired @Autowired
ApiInfoMapper apiInfoMapper; ManufacturerApiInfoMapper manufacturerApiInfoMapper;
@Autowired @Autowired
ManufacturerInfoMapper manufacturerInfoMapper; ManufacturerInfoMapper manufacturerInfoMapper;
@Scheduled(fixedRate = 2 * 60 * 1000) @Scheduled(fixedRate = 2 * 60 * 1000)
public void apiInfoRefresh() { public void apiInfoRefresh() {
try { try {
ApiInfoPO apiInfoPO = new ApiInfoPO(); ManufacturerApiInfoPO manufacturerApiInfoPO = new ManufacturerApiInfoPO();
List<ApiInfoPO> apiInfoPOList = apiInfoMapper.selectAll(); List<ManufacturerApiInfoPO> manufacturerApiInfoPOList = manufacturerApiInfoMapper.selectAll();
if (apiInfoPOList== null || apiInfoPOList.isEmpty()) { if (manufacturerApiInfoPOList == null || manufacturerApiInfoPOList.isEmpty()) {
return; return;
} }
// 刷新JVM // 刷新JVM
for (ApiInfoPO infoPO : apiInfoPOList) { for (ManufacturerApiInfoPO infoPO : manufacturerApiInfoPOList) {
Integer manufacturerId = infoPO.getManufacturerId(); Integer manufacturerId = infoPO.getManufacturerId();
ManufacturerInfoPO manufacturerInfoPO = manufacturerInfoMapper.selectById(manufacturerId); ManufacturerInfoPO manufacturerInfoPO = manufacturerInfoMapper.selectById(manufacturerId);
String abbr = manufacturerInfoPO.getNickName(); String abbr = manufacturerInfoPO.getNickName();
String s = abbr + Constants.SEPARATOR_UNDER_LINE + infoPO.getCode(); String s = abbr + Constants.SEPARATOR_UNDER_LINE + infoPO.getCode();
Constants.putManufacturerUrlMap(s, infoPO); Constants.putManufacturerUrlMap(s, infoPO);
} }
log.info("刷新" + apiInfoPOList.size() + "条厂商URL至JVM"); log.info("刷新" + manufacturerApiInfoPOList.size() + "条厂商URL至JVM");
} catch (Exception e) { } catch (Exception e) {
log.error("刷新厂商URL到JVM异常", e); log.error("刷新厂商URL到JVM异常", e);
} }
......
package net.wanji.utc.common.typeenum;
public enum HttpCode {
/** 200请求成功 */
SUCCESS(200),
/** 207频繁操作 */
MULTI_STATUS(207),
/** 400请求参数出错 */
BAD_REQUEST(400),
/** 401没有登录 */
UNAUTHORIZED(401),
/** 402登录失败 */
LOGIN_FAIL(402),
/** 403没有权限 */
FORBIDDEN(403),
/** 404找不到页面 */
NOT_FOUND(404),
/** 405请求方法不能被用于请求相应的资源 */
METHOD_NOT_ALLOWED(405),
/** 406内容特性不满足 */
NOT_ACCEPTABLE(406),
/** token过期 */
TOKEN_EXPIRED(407),
/** 408请求超时 */
REQUEST_TIMEOUT(408),
/** 409发生冲突 */
CONFLICT(409),
/** 410已被删除 */
GONE(410),
/** 411没有定义长度 */
LENGTH_REQUIRED(411),
/** 412条件不满足 */
PRECONDITION_FAILED(412),
/** 413数据太大 */
ENTITY_TOO_LARGE(413),
/** 415不是服务器中所支持的格式 */
UNSUPPORTED_MEDIA_TYPE(415),
/** 421连接数过多 */
TOO_MANY_CONNECTIONS(421),
/** 423已被锁定 */
LOCKED(423),
/** 451法律不允许 */
UNAVAILABLE_LEGAL(451),
/** 500服务器出错 */
INTERNAL_SERVER_ERROR(500),
/** 501不支持当前请求所需要的某个功能 */
NOT_IMPLEMENTED(501),
/** 503服务器升级中,暂时不可用 */
SERVICE_UNAVAILABLE(503),
/** 501获取资源所需要的策略并没有被满足 */
NOT_EXTENDED(510);
private final Integer value;
private HttpCode(Integer value) {
this.value = value;
}
/**
* Return the integer value of this status code.
*/
public Integer value() {
return this.value;
}
@Override
public String toString() {
return this.value.toString();
}
}
\ No newline at end of file
package net.wanji.utc.common.typeenum;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author Kent HAN
* @date 2022/11/24 14:16
*/
@Getter
@AllArgsConstructor
public enum ManufacturerApiInfoTypeEnum {
ONE(1, "静态信息接口"),
TWO(2, "运行信息接口"),
THREE(3, "控制指令接口");
private Integer code;
private String msg;
public static Integer getCodeByMsg(String typeStr) {
for (ManufacturerApiInfoTypeEnum value : values()) {
if (value.getMsg().equals(typeStr)) {
return value.getCode();
}
}
return null;
}
}
package net.wanji.utc.controller;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import net.wanji.utc.entity.JsonViewObject;
import net.wanji.utc.po.ManufacturerApiInfoPO;
import net.wanji.utc.service.systemadmin.ManufacturerApiInfoService;
import net.wanji.utc.vo.systemadmin.DeleteListInVO;
import net.wanji.utc.vo.systemadmin.ManufacturerApiInfoInsertOrUpdateInVO;
import net.wanji.utc.vo.systemadmin.ManufacturerApiInfoListInVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.ws.rs.core.MediaType;
/**
* 系统管理-接口管理
*
* @author Kent HAN
* @date 2022/11/24 8:32
*/
@Api(value = "系统管理-接口管理", description = "系统管理-接口管理")
@RequestMapping("/manufacturerApiInfo")
@RestController
public class ManufacturerApiController {
@Autowired
ManufacturerApiInfoService manufacturerApiInfoService;
@ApiOperation(value = "接口列表", notes = "接口列表", response = ManufacturerApiInfoPO.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/list",
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = ManufacturerApiInfoPO.class),
})
public JsonViewObject list(@RequestBody ManufacturerApiInfoListInVO manufacturerApiInfoListInVO) {
PageInfo<ManufacturerApiInfoPO> manufacturerApiInfoPOPageInfo =
manufacturerApiInfoService.list(manufacturerApiInfoListInVO);
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
return jsonViewObject.success(manufacturerApiInfoPOPageInfo);
}
@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 = "/delete", consumes = MediaType.APPLICATION_JSON)
public JsonViewObject delete(@RequestBody DeleteListInVO inVO) {
manufacturerApiInfoService.delete(inVO);
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
return jsonViewObject.success();
}
}
...@@ -5,14 +5,15 @@ import io.swagger.annotations.Api; ...@@ -5,14 +5,15 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses; import io.swagger.annotations.ApiResponses;
import net.wanji.utc.entity.JsonViewObject;
import net.wanji.utc.po.ManufacturerInfoPO; import net.wanji.utc.po.ManufacturerInfoPO;
import net.wanji.utc.service.systemadmin.ManufacturerService; import net.wanji.utc.service.systemadmin.ManufacturerService;
import net.wanji.utc.vo.systemadmin.ManufacturerDeleteInVO; import net.wanji.utc.vo.systemadmin.DeleteListInVO;
import net.wanji.utc.vo.systemadmin.ManufacturerInsertOrUpdateInVO; import net.wanji.utc.vo.systemadmin.ManufacturerInsertOrUpdateInVO;
import net.wanji.utc.vo.systemadmin.ManufacturerListInVO; import net.wanji.utc.vo.systemadmin.ManufacturerListInVO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -28,7 +29,7 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -28,7 +29,7 @@ import org.springframework.web.bind.annotation.RestController;
@Api(value = "系统管理-厂商管理", description = "系统管理-厂商管理") @Api(value = "系统管理-厂商管理", description = "系统管理-厂商管理")
@RequestMapping("/manufacturer") @RequestMapping("/manufacturer")
@RestController @RestController
public class ManufacturerAdminController { public class ManufacturerController {
@Autowired @Autowired
ManufacturerService manufacturerService; ManufacturerService manufacturerService;
...@@ -39,22 +40,28 @@ public class ManufacturerAdminController { ...@@ -39,22 +40,28 @@ public class ManufacturerAdminController {
@ApiResponses({ @ApiResponses({
@ApiResponse(code = 200, message = "OK", response = ManufacturerInfoPO.class), @ApiResponse(code = 200, message = "OK", response = ManufacturerInfoPO.class),
}) })
public ResponseEntity list(@RequestBody ManufacturerListInVO manufacturerListInVO) { public JsonViewObject list(@RequestBody ManufacturerListInVO manufacturerListInVO) {
PageInfo<ManufacturerInfoPO> manufacturerInfoPOPageInfo = manufacturerService.list(manufacturerListInVO); PageInfo<ManufacturerInfoPO> manufacturerInfoPOPageInfo = manufacturerService.list(manufacturerListInVO);
return ResponseEntity.ok(manufacturerInfoPOPageInfo); JsonViewObject jsonViewObject = JsonViewObject.newInstance();
return jsonViewObject.success(manufacturerInfoPOPageInfo);
} }
@ApiOperation(value = "厂商添加或修改", notes = "厂商添加或修改", consumes = MediaType.APPLICATION_JSON) @ApiOperation(value = "厂商添加或修改", notes = "厂商添加或修改", consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/insertOrUpdate", consumes = MediaType.APPLICATION_JSON) @PostMapping(value = "/insertOrUpdate", consumes = MediaType.APPLICATION_JSON)
public ResponseEntity insertOrUpdate(@RequestBody ManufacturerInsertOrUpdateInVO inVO) { public JsonViewObject insertOrUpdate(@RequestBody ManufacturerInsertOrUpdateInVO inVO) {
manufacturerService.insertOrUpdate(inVO); manufacturerService.insertOrUpdate(inVO);
return ResponseEntity.ok("success"); JsonViewObject jsonViewObject = JsonViewObject.newInstance();
return jsonViewObject.success();
} }
@ApiOperation(value = "厂商删除", notes = "厂商删除", consumes = MediaType.APPLICATION_JSON) @ApiOperation(value = "厂商删除", notes = "厂商删除", consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/delete", consumes = MediaType.APPLICATION_JSON) @PostMapping(value = "/delete", consumes = MediaType.APPLICATION_JSON)
public ResponseEntity delete(@RequestBody ManufacturerDeleteInVO inVO) { public JsonViewObject delete(@RequestBody DeleteListInVO inVO) {
manufacturerService.delete(inVO); manufacturerService.delete(inVO);
return ResponseEntity.ok("success"); JsonViewObject jsonViewObject = JsonViewObject.newInstance();
return jsonViewObject.success();
} }
} }
package net.wanji.utc.entity;
import lombok.Data;
import net.wanji.utc.common.constant.Constants;
import net.wanji.utc.common.typeenum.HttpCode;
import java.io.Serializable;
@Data
public class JsonViewObject implements Serializable {
private Object content;
private String message;
private String status;
private Integer code;
private Long timestamp;
public Object getContent() {
return content;
}
public String getMessage() {
return message;
}
public String getStatus() {
return status;
}
private JsonViewObject() {
}
public static JsonViewObject newInstance() {
return new JsonViewObject();
}
public JsonViewObject success() {
return success((Object) "");
}
public JsonViewObject success(Object content) {
return success(content, "");
}
public JsonViewObject success(String message) {
return success("", message);
}
public JsonViewObject success(Object content, String message) {
return pack(content, message, Constants.JsonView.STATUS_SUCCESS);
}
public JsonViewObject fail() {
return fail("", "");
}
public JsonViewObject fail(Exception e) {
String message = e.getMessage();
int index = message.indexOf(":");
return fail(index == -1 ? message : message.substring(index + 1));
}
public JsonViewObject fail(String errMsg) {
return fail("", errMsg);
}
public JsonViewObject fail(Object content, String message) {
return pack(content, message, Constants.JsonView.STATUS_FAIL);
}
private JsonViewObject pack(Object content, String message, String status) {
this.content = content;
this.message = message;
this.status = status;
//增加服务返回状态码,后期待完善
this.code=(status.equals(Constants.JsonView.STATUS_SUCCESS) ? HttpCode.SUCCESS.value():HttpCode.INTERNAL_SERVER_ERROR.value());
return this;
}
}
\ No newline at end of file
package net.wanji.utc.mapper;
import net.wanji.utc.po.ApiInfoPO;
import java.util.List;
/**
* @author Kent HAN
* @date 2022/11/15 15:31
*/
public interface ApiInfoMapper {
List<ApiInfoPO> selectAll();
}
package net.wanji.utc.mapper;
import net.wanji.utc.po.ManufacturerApiInfoPO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author Kent HAN
* @date 2022/11/15 15:31
*/
public interface ManufacturerApiInfoMapper {
List<ManufacturerApiInfoPO> selectAll();
List<ManufacturerApiInfoPO> selectByOptionals(@Param("name") String name,
@Param("typeCode")Integer typeCode,
@Param("manufacturerId")Integer manufacturerId);
void insertOne(ManufacturerApiInfoPO manufacturerApiInfoPO);
void updateOne(ManufacturerApiInfoPO manufacturerApiInfoPO);
void deleteBatch(@Param("ids") List<Integer> ids);
}
...@@ -25,4 +25,6 @@ public interface ManufacturerInfoMapper { ...@@ -25,4 +25,6 @@ public interface ManufacturerInfoMapper {
void updateOne(ManufacturerInfoPO manufacturerInfoPO); void updateOne(ManufacturerInfoPO manufacturerInfoPO);
void deleteBatch(@Param("ids") List<Integer> ids); void deleteBatch(@Param("ids") List<Integer> ids);
Integer selectIdByName(@Param("manufacturerName") String manufacturerName);
} }
...@@ -10,32 +10,32 @@ import java.util.Date; ...@@ -10,32 +10,32 @@ import java.util.Date;
* @date 2022/11/15 13:41 * @date 2022/11/15 13:41
*/ */
@Data @Data
public class ApiInfoPO { public class ManufacturerApiInfoPO {
/** 接口ID */ /** 接口ID */
@ApiModelProperty(name = "接口ID",notes = "") @ApiModelProperty(value = "接口ID",notes = "")
private Integer id ; private Integer id ;
/** 接口代码 */ /** 接口代码 */
@ApiModelProperty(name = "接口代码",notes = "") @ApiModelProperty(value = "接口代码",notes = "")
private String code ; private String code ;
/** 接口名称 */ /** 接口名称 */
@ApiModelProperty(name = "接口名称",notes = "") @ApiModelProperty(value = "接口名称",notes = "")
private String name ; private String name ;
/** 接口类型:1、静态;2、动态;3、控制 */ /** 接口类型:1、静态;2、动态;3、控制 */
@ApiModelProperty(name = "接口类型:1、静态;2、动态;3、控制",notes = "") @ApiModelProperty(value = "接口类型:1、静态;2、动态;3、控制",notes = "")
private Integer type ; private Integer type ;
/** 请求方式:get、post */ /** 请求方式:get、post */
@ApiModelProperty(name = "请求方式:get、post",notes = "") @ApiModelProperty(value = "请求方式:get、post",notes = "")
private String method ; private String method ;
/** 接口地址 */ /** 接口地址 */
@ApiModelProperty(name = "接口地址",notes = "") @ApiModelProperty(value = "接口地址",notes = "")
private String address ; private String address ;
/** 厂商ID */ /** 厂商ID */
@ApiModelProperty(name = "厂商ID",notes = "") @ApiModelProperty(value = "厂商ID",notes = "")
private Integer manufacturerId ; private Integer manufacturerId ;
/** 创建时间 */ /** 创建时间 */
@ApiModelProperty(name = "创建时间",notes = "") @ApiModelProperty(value = "创建时间",notes = "")
private Date gmtCreate ; private Date gmtCreate ;
/** 修改时间 */ /** 修改时间 */
@ApiModelProperty(name = "修改时间",notes = "") @ApiModelProperty(value = "修改时间",notes = "")
private Date gmtModified ; private Date gmtModified ;
} }
package net.wanji.utc.service.systemadmin;
import com.github.pagehelper.PageInfo;
import net.wanji.utc.po.ManufacturerApiInfoPO;
import net.wanji.utc.vo.systemadmin.DeleteListInVO;
import net.wanji.utc.vo.systemadmin.ManufacturerApiInfoInsertOrUpdateInVO;
import net.wanji.utc.vo.systemadmin.ManufacturerApiInfoListInVO;
/**
* @author Kent HAN
* @date 2022/11/24 13:59
*/
public interface ManufacturerApiInfoService {
PageInfo<ManufacturerApiInfoPO> list(ManufacturerApiInfoListInVO manufacturerApiInfoListInVO);
void insertOrUpdate(ManufacturerApiInfoInsertOrUpdateInVO inVO);
void delete(DeleteListInVO inVO);
}
...@@ -2,7 +2,7 @@ package net.wanji.utc.service.systemadmin; ...@@ -2,7 +2,7 @@ package net.wanji.utc.service.systemadmin;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import net.wanji.utc.po.ManufacturerInfoPO; import net.wanji.utc.po.ManufacturerInfoPO;
import net.wanji.utc.vo.systemadmin.ManufacturerDeleteInVO; import net.wanji.utc.vo.systemadmin.DeleteListInVO;
import net.wanji.utc.vo.systemadmin.ManufacturerInsertOrUpdateInVO; import net.wanji.utc.vo.systemadmin.ManufacturerInsertOrUpdateInVO;
import net.wanji.utc.vo.systemadmin.ManufacturerListInVO; import net.wanji.utc.vo.systemadmin.ManufacturerListInVO;
...@@ -15,5 +15,5 @@ public interface ManufacturerService { ...@@ -15,5 +15,5 @@ public interface ManufacturerService {
void insertOrUpdate(ManufacturerInsertOrUpdateInVO inVO); void insertOrUpdate(ManufacturerInsertOrUpdateInVO inVO);
void delete(ManufacturerDeleteInVO inVO); void delete(DeleteListInVO inVO);
} }
package net.wanji.utc.service.systemadmin.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import net.wanji.utc.common.typeenum.ManufacturerApiInfoTypeEnum;
import net.wanji.utc.mapper.ManufacturerApiInfoMapper;
import net.wanji.utc.mapper.ManufacturerInfoMapper;
import net.wanji.utc.po.ManufacturerApiInfoPO;
import net.wanji.utc.po.ManufacturerInfoPO;
import net.wanji.utc.service.systemadmin.ManufacturerApiInfoService;
import net.wanji.utc.vo.systemadmin.DeleteListInVO;
import net.wanji.utc.vo.systemadmin.ManufacturerApiInfoInsertOrUpdateInVO;
import net.wanji.utc.vo.systemadmin.ManufacturerApiInfoListInVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author Kent HAN
* @date 2022/11/24 14:10
*/
@Service
public class ManufacturerApiInfoServiceImpl implements ManufacturerApiInfoService {
@Autowired
ManufacturerApiInfoMapper manufacturerApiInfoMapper;
@Autowired
ManufacturerInfoMapper manufacturerInfoMapper;
@Override
public PageInfo<ManufacturerApiInfoPO> list(ManufacturerApiInfoListInVO manufacturerApiInfoListInVO) {
Integer pageNum = manufacturerApiInfoListInVO.getPageNum();
Integer pageSize = manufacturerApiInfoListInVO.getPageSize();
String name = manufacturerApiInfoListInVO.getName();
String typeStr = manufacturerApiInfoListInVO.getTypeStr();
Integer typeCode = null;
if (typeStr != null) {
typeCode = ManufacturerApiInfoTypeEnum.getCodeByMsg(typeStr);
}
String manufacturerName = manufacturerApiInfoListInVO.getManufacturerName();
Integer manufacturerId = null;
if (manufacturerName != null) {
manufacturerId = manufacturerInfoMapper.selectIdByName(manufacturerName);
}
PageHelper.startPage(pageNum, pageSize);
List<ManufacturerApiInfoPO> manufacturerApiInfoPOList = manufacturerApiInfoMapper.selectByOptionals(
name, typeCode, manufacturerId);
PageInfo<ManufacturerApiInfoPO> manufacturerApiInfoPOPageInfo = new PageInfo<>(manufacturerApiInfoPOList);
return manufacturerApiInfoPOPageInfo;
}
@Override
public void insertOrUpdate(ManufacturerApiInfoInsertOrUpdateInVO inVO) {
Integer id = inVO.getId();
ManufacturerApiInfoPO manufacturerApiInfoPO = new ManufacturerApiInfoPO();
BeanUtils.copyProperties(inVO, manufacturerApiInfoPO);
String typeStr = inVO.getApiType();
Integer typeCode = ManufacturerApiInfoTypeEnum.getCodeByMsg(typeStr);
String manufacturerName = inVO.getManufacturerName();
Integer manufacturerId = manufacturerInfoMapper.selectIdByName(manufacturerName);
manufacturerApiInfoPO.setType(typeCode);
manufacturerApiInfoPO.setManufacturerId(manufacturerId);
if (id == null || id == 0) {
// 添加
manufacturerApiInfoMapper.insertOne(manufacturerApiInfoPO);
} else {
// 修改
manufacturerApiInfoMapper.updateOne(manufacturerApiInfoPO);
}
}
@Override
public void delete(DeleteListInVO inVO) {
List<Integer> ids = inVO.getIds();
manufacturerApiInfoMapper.deleteBatch(ids);
}
}
...@@ -5,12 +5,11 @@ import com.github.pagehelper.PageInfo; ...@@ -5,12 +5,11 @@ import com.github.pagehelper.PageInfo;
import net.wanji.utc.mapper.ManufacturerInfoMapper; import net.wanji.utc.mapper.ManufacturerInfoMapper;
import net.wanji.utc.po.ManufacturerInfoPO; import net.wanji.utc.po.ManufacturerInfoPO;
import net.wanji.utc.service.systemadmin.ManufacturerService; import net.wanji.utc.service.systemadmin.ManufacturerService;
import net.wanji.utc.vo.systemadmin.ManufacturerDeleteInVO; import net.wanji.utc.vo.systemadmin.DeleteListInVO;
import net.wanji.utc.vo.systemadmin.ManufacturerInsertOrUpdateInVO; import net.wanji.utc.vo.systemadmin.ManufacturerInsertOrUpdateInVO;
import net.wanji.utc.vo.systemadmin.ManufacturerListInVO; import net.wanji.utc.vo.systemadmin.ManufacturerListInVO;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
...@@ -52,7 +51,7 @@ public class ManufacturerServiceImpl implements ManufacturerService { ...@@ -52,7 +51,7 @@ public class ManufacturerServiceImpl implements ManufacturerService {
} }
@Override @Override
public void delete(ManufacturerDeleteInVO inVO) { public void delete(DeleteListInVO inVO) {
List<Integer> ids = inVO.getIds(); List<Integer> ids = inVO.getIds();
manufacturerInfoMapper.deleteBatch(ids); manufacturerInfoMapper.deleteBatch(ids);
} }
......
...@@ -11,9 +11,9 @@ import java.util.List; ...@@ -11,9 +11,9 @@ import java.util.List;
* @date 2022/11/24 10:10 * @date 2022/11/24 10:10
*/ */
@Data @Data
@ApiModel(value = "ManufacturerDeleteInVO", description = "厂商删除输入参数") @ApiModel(value = "DeleteListInVO", description = "厂商或接口删除输入参数")
public class ManufacturerDeleteInVO { public class DeleteListInVO {
/** 厂商ID列表 */ /** 厂商或接口ID列表 */
@ApiModelProperty(value = "厂商ID列表",notes = "") @ApiModelProperty(value = "厂商或接口ID列表",notes = "")
private List<Integer> ids ; private List<Integer> ids ;
} }
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/24 15:20
*/
@Data
@ApiModel(value = "ManufacturerApiInfoInsertOrUpdateInVO", description = "接口新增或修改删除输入参数")
public class ManufacturerApiInfoInsertOrUpdateInVO {
/** 接口ID */
@ApiModelProperty(value = "接口ID。不传ID为新增,传ID为修改",notes = "")
private Integer id ;
/** 接口代码 */
@ApiModelProperty(required = true, value = "接口代码",notes = "")
private String code ;
/** 接口名称 */
@ApiModelProperty(required = true, value = "接口名称",notes = "")
private String name ;
/** 接口类型 */
@ApiModelProperty(required = true, value = "接口类型",notes = "")
private String apiType ;
/** 请求方式:get、post */
@ApiModelProperty(required = true, value = "请求方式:get、post",notes = "")
private String method ;
/** 接口地址 */
@ApiModelProperty(required = true, value = "接口地址",notes = "")
private String address ;
/** 厂商ID */
@ApiModelProperty(required = true, value = "接口厂商",notes = "")
private String manufacturerName ;
}
package net.wanji.utc.vo.systemadmin;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author Kent HAN
* @date 2022/11/24 14:05
*/
@Data
@ApiModel(value = "ManufacturerApiInfoListInVO", description = "查询接口列表输入参数")
public class ManufacturerApiInfoListInVO {
@ApiModelProperty(required = true, value = "页号")
Integer pageNum;
@ApiModelProperty(required = true, value = "每页记录数")
Integer pageSize;
@ApiModelProperty( value = "接口名称")
String name;
@ApiModelProperty( value = "接口类型")
String typeStr;
@ApiModelProperty( value = "接口厂商")
String manufacturerName;
}
<?xml version="1.0" encoding="UTF-8"?> <?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"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="net.wanji.utc.mapper.ApiInfoMapper"> <mapper namespace="net.wanji.utc.mapper.ManufacturerApiInfoMapper">
<resultMap type="net.wanji.utc.po.ApiInfoPO" id="BaseResultMap"> <resultMap type="net.wanji.utc.po.ManufacturerApiInfoPO" id="BaseResultMap">
<result property="id" column="id"/> <result property="id" column="id"/>
<result property="code" column="code"/> <result property="code" column="code"/>
<result property="name" column="name"/> <result property="name" column="name"/>
...@@ -13,9 +13,63 @@ ...@@ -13,9 +13,63 @@
<result property="gmtModified" column="gmt_modified"/> <result property="gmtModified" column="gmt_modified"/>
</resultMap> </resultMap>
<insert id="insertOne">
insert into t_manufacturer_api_info(code,name,type,method,address,manufacturer_id)
values (#{code},#{name},#{type},#{method},#{address},#{manufacturerId})
</insert>
<update id="updateOne">
update t_manufacturer_api_info
<set>
<if test="code != null and code != ''">
code = #{code},
</if>
<if test="name != null and name != ''">
name = #{name},
</if>
<if test="type != null and type != 0">
type = #{type},
</if>
<if test="method != null and method != ''">
method = #{method},
</if>
<if test="address != null and address != ''">
address = #{address},
</if>
<if test="manufacturerId != null and manufacturerId != 0">
manufacturer_id = #{manufacturerId},
</if>
</set>
where id = #{id}
</update>
<delete id="deleteBatch">
delete from t_manufacturer_api_info
where id in
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</delete>
<select id="selectAll" resultMap="BaseResultMap"> <select id="selectAll" resultMap="BaseResultMap">
select select
id,code,name,type,method,address,manufacturer_id,gmt_create,gmt_modified id,code,name,type,method,address,manufacturer_id,gmt_create,gmt_modified
from t_manufacturer_api_info from t_manufacturer_api_info
</select> </select>
<select id="selectByOptionals" resultMap="BaseResultMap">
select id,code,name,type,method,address,manufacturer_id,gmt_create,gmt_modified
from t_manufacturer_api_info
<where>
<if test="name != null and name != ''">
AND name LIKE CONCAT('%',#{name},'%')
</if>
<if test="typeCode != null and typeCode != 0">
AND type = #{typeCode}
</if>
<if test="manufacturerId != null and manufacturerId != 0">
AND manufacturer_id = #{manufacturerId}
</if>
</where>
</select>
</mapper> </mapper>
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<result property="gmtCreate" column="gmt_create"/> <result property="gmtCreate" column="gmt_create"/>
<result property="gmtModified" column="gmt_modified"/> <result property="gmtModified" column="gmt_modified"/>
</resultMap> </resultMap>
<insert id="insertOne"> <insert id="insertOne">
insert into t_manufacturer_info(code,name,nick_name,address,maintenance_unit) insert into t_manufacturer_info(code,name,nick_name,address,maintenance_unit)
values (#{code},#{name},#{nickName},#{address},#{maintenanceUnit}) values (#{code},#{name},#{nickName},#{address},#{maintenanceUnit})
...@@ -75,4 +76,9 @@ ...@@ -75,4 +76,9 @@
</where> </where>
order by id order by id
</select> </select>
<select id="selectIdByName" resultType="java.lang.Integer">
select id from t_manufacturer_info
where name = #{manufacturerName}
</select>
</mapper> </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