feat: 增加i2同步数据需要的配置接口
parent
4c5b28218b
commit
8e6c706e02
@ -0,0 +1,75 @@
|
|||||||
|
package com.xydl.cac.controller;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.I2syncConfig;
|
||||||
|
import com.xydl.cac.entity.ModevType;
|
||||||
|
import com.xydl.cac.exception.BusinessException;
|
||||||
|
import com.xydl.cac.model.Response;
|
||||||
|
import com.xydl.cac.service.I2syncService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@Api(tags = {"I2同步数据相关接口"})
|
||||||
|
@RequestMapping("i2sync")
|
||||||
|
@Slf4j
|
||||||
|
public class I2syncController extends BasicController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
I2syncService service;
|
||||||
|
|
||||||
|
@GetMapping("listFieldConfig")
|
||||||
|
@ApiOperation("查询字段映射")
|
||||||
|
public Response<List<ModevType>> listFieldConfig() {
|
||||||
|
List<ModevType> result = service.listFieldConfig();
|
||||||
|
return Response.success(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("updateFieldConfig")
|
||||||
|
@ApiOperation("修改字段映射")
|
||||||
|
public Response<String> updateFieldConfig(@Validated @RequestBody ModevType item) throws Exception {
|
||||||
|
if (CollectionUtils.isEmpty(item.getI2syncFields())) {
|
||||||
|
throw new BusinessException("i2syncFields不能为空!");
|
||||||
|
}
|
||||||
|
service.updateFieldConfig(item);
|
||||||
|
return Response.success("OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("delFieldConfig")
|
||||||
|
@ApiOperation("删除字段映射")
|
||||||
|
public Response<String> delFieldConfig(@Validated @RequestBody ModevType item) throws Exception {
|
||||||
|
service.delFieldConfig(item.getTablename());
|
||||||
|
return Response.success("OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("listConfig")
|
||||||
|
@ApiOperation("查询导出类型配置")
|
||||||
|
public Response<List<I2syncConfig>> listConfig() {
|
||||||
|
List<I2syncConfig> result = service.listConfig();
|
||||||
|
return Response.success(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("addConfig")
|
||||||
|
@ApiOperation("新增导出类型配置")
|
||||||
|
public Response<String> addConfig(@Validated @RequestBody I2syncConfig item) throws Exception {
|
||||||
|
service.addConfig(item);
|
||||||
|
return Response.success("OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("delConfig")
|
||||||
|
@ApiOperation("删除导出类型配置")
|
||||||
|
public Response<String> delConfig(@Validated @RequestBody I2syncConfig item) throws Exception {
|
||||||
|
if (item.getId() == null) {
|
||||||
|
throw new BusinessException("id不能为空!");
|
||||||
|
}
|
||||||
|
service.delConfig(item.getId());
|
||||||
|
return Response.success("OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.xydl.cac.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Transient;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@Table(name = "i2sync_config")
|
||||||
|
@ApiModel("i2导出类型配置")
|
||||||
|
public class I2syncConfig {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
@NotNull(message = "modevtypeId不能为空")
|
||||||
|
private Integer modevtypeId;
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@ApiModelProperty("类型名称")
|
||||||
|
@Transient
|
||||||
|
private String typeName;
|
||||||
|
@ApiModelProperty("对应的表名")
|
||||||
|
@Transient
|
||||||
|
private String tableName;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.xydl.cac.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@Table(name = "i2sync_field")
|
||||||
|
@ApiModel("i2导出字段映射配置")
|
||||||
|
public class I2syncField {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
private String tableName;
|
||||||
|
private String fieldName;
|
||||||
|
private String destFieldName;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.xydl.cac.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@Table(name = "i2sync_record")
|
||||||
|
@ApiModel("i2导出记录")
|
||||||
|
public class I2syncRecord {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
private Integer modevtypeId;
|
||||||
|
private Integer eqmid;
|
||||||
|
private Date lastDTime;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.xydl.cac.repository;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.I2syncConfig;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface I2syncConfigRepository extends JpaRepository<I2syncConfig, Integer>, JpaSpecificationExecutor<I2syncConfig> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.xydl.cac.repository;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.I2syncField;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface I2syncFieldRepository extends JpaRepository<I2syncField, Integer>, JpaSpecificationExecutor<I2syncField> {
|
||||||
|
|
||||||
|
List<I2syncField> findByTableName(String tablename);
|
||||||
|
|
||||||
|
void deleteByTableName(String tablename);
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.xydl.cac.repository;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.I2syncRecord;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface I2syncRecordRepository extends JpaRepository<I2syncRecord, Integer>, JpaSpecificationExecutor<I2syncRecord> {
|
||||||
|
|
||||||
|
List<I2syncRecord> findByModevtypeId(Integer modevtypeId);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.xydl.cac.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.I2syncConfig;
|
||||||
|
import com.xydl.cac.entity.ModevType;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface I2syncService {
|
||||||
|
|
||||||
|
List<ModevType> listFieldConfig();
|
||||||
|
|
||||||
|
void updateFieldConfig(ModevType item);
|
||||||
|
|
||||||
|
void delFieldConfig(String tablename);
|
||||||
|
|
||||||
|
List<I2syncConfig> listConfig();
|
||||||
|
|
||||||
|
void addConfig(I2syncConfig item);
|
||||||
|
|
||||||
|
void delConfig(Integer id);
|
||||||
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
package com.xydl.cac.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.excel.util.StringUtils;
|
||||||
|
import com.xydl.cac.entity.*;
|
||||||
|
import com.xydl.cac.repository.*;
|
||||||
|
import com.xydl.cac.service.I2syncService;
|
||||||
|
import com.xydl.cac.service.ModevTypeService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class I2syncServiceImpl implements I2syncService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ModevTypeRepository modevTypeRepository;
|
||||||
|
@Resource
|
||||||
|
ModevTypeService modevTypeService;
|
||||||
|
@Resource
|
||||||
|
I2syncFieldRepository syncFieldRepository;
|
||||||
|
@Resource
|
||||||
|
I2syncConfigRepository configRepository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ModevType> listFieldConfig() {
|
||||||
|
List<ModevType> result = new ArrayList<>();
|
||||||
|
List<ModevType> typeList = modevTypeRepository.findAll();
|
||||||
|
for (ModevType item : typeList) {
|
||||||
|
if (StringUtils.isNotBlank(item.getTablename())) {
|
||||||
|
List<I2syncField> fieldList = syncFieldRepository.findByTableName(item.getTablename());
|
||||||
|
if (!CollectionUtils.isEmpty(fieldList)) {
|
||||||
|
item.setI2syncFields(fieldList);
|
||||||
|
result.add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateFieldConfig(ModevType item) {
|
||||||
|
syncFieldRepository.deleteByTableName(item.getTablename());
|
||||||
|
for (I2syncField field : item.getI2syncFields()) {
|
||||||
|
field.setTableName(item.getTablename());
|
||||||
|
field.setId(null);
|
||||||
|
syncFieldRepository.save(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delFieldConfig(String tablename) {
|
||||||
|
syncFieldRepository.deleteByTableName(tablename);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<I2syncConfig> listConfig() {
|
||||||
|
List<I2syncConfig> list = configRepository.findAll();
|
||||||
|
this.fillModeType(list);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillModeType(List<I2syncConfig> list) {
|
||||||
|
List<ModevType> modevTypeList = modevTypeService.listAll();
|
||||||
|
if (!CollectionUtils.isEmpty(list)) {
|
||||||
|
for (I2syncConfig item : list) {
|
||||||
|
for (ModevType type : modevTypeList) {
|
||||||
|
if (type.getId().equals(item.getModevtypeId())) {
|
||||||
|
item.setTypeName(type.getMc());
|
||||||
|
item.setTableName(type.getTablename());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addConfig(I2syncConfig item) {
|
||||||
|
item.setId(null);
|
||||||
|
item.setCreateTime(new Date());
|
||||||
|
configRepository.save(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delConfig(Integer id) {
|
||||||
|
configRepository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue