Browse Source

数据源中表及数据源表字段对应表的维护接口

wangxingwang 6 years ago
parent
commit
43af445f62

+ 97 - 0
src/main/java/com/yihu/quota/controller/DataSourcesTableController.java

@ -0,0 +1,97 @@
package com.yihu.quota.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.quota.model.source.DataSourcesTable;
import com.yihu.quota.model.source.DataSourcesTableField;
import com.yihu.quota.service.source.DataSourcesTableFieldService;
import com.yihu.quota.service.source.DataSourcesTableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.net.URLDecoder;
import java.util.List;
/**
 * Created by wxw on 2018/9/10.
 *
 * @author wxw.
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "DataSourcesTableController", description = "OLAP-数据源中表", tags = {"OLAP-数据源中表"})
public class DataSourcesTableController {
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private DataSourcesTableService dataSourcesService;
    @Autowired
    private DataSourcesTableFieldService dataSourcesFieldService;
    @RequestMapping(value = "/olap/searchDataSources", method = RequestMethod.GET)
    @ApiOperation(value = "根据查询条件查询,具有分页功能;filters='id=1'")
    public Envelop searchDataSources(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+type")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) int size,
            @ApiParam(name = "page", value = "页码", defaultValue = "1")
            @RequestParam(value = "page", required = false) int page) throws Exception {
        Envelop envelop = new Envelop();
        List<DataSourcesTable> search = dataSourcesService.search(fields, filters, sorts, page, size);
        if (null != search && search.size() > 0) {
            for (DataSourcesTable table : search) {
                List<DataSourcesTableField> list = dataSourcesFieldService.search("tableId=" + table.getId());
                if (null != list && list.size() > 0) {
                    table.setDataSourcesTableFields(list);
                }
            }
        }
        envelop.setSuccessFlg(true);
        envelop.setDetailModelList(search);
        return envelop;
    }
    @RequestMapping(value = "/olap/saveOrUpdateDataSources", method = RequestMethod.POST)
    @ApiOperation(value = "添加或修改操作")
    public Envelop saveOrUpdateDataSources(
            @ApiParam(name = "model", value = "json数据模型", defaultValue = "")
            @RequestParam String model) throws Exception {
        Envelop envelop = new Envelop();
        DataSourcesTable dataSourcesTable = objectMapper.readValue(URLDecoder.decode(model, "UTF-8"), DataSourcesTable.class);
        if (null == dataSourcesTable.getId()) {
            // 新增
            dataSourcesService.save(dataSourcesTable);
        } else {
            // 修改
            dataSourcesService.save(dataSourcesTable);
        }
        envelop.setSuccessFlg(true);
        return envelop;
    }
    @RequestMapping(value = "/olap/deleteDataSourceById", method = RequestMethod.DELETE)
    @ApiOperation(value = "根据id删除")
    public Envelop deleteDataSourceById(
            @ApiParam(name = "id", value = "编号", defaultValue = "")
            @RequestParam(value = "id") Integer id) throws Exception {
        Envelop envelop = new Envelop();
        dataSourcesService.deleteById(id);
        envelop.setSuccessFlg(true);
        return envelop;
    }
}

+ 83 - 0
src/main/java/com/yihu/quota/controller/DataSourcesTableFieldController.java

@ -0,0 +1,83 @@
package com.yihu.quota.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.quota.model.source.DataSourcesTableField;
import com.yihu.quota.service.source.DataSourcesTableFieldService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.net.URLDecoder;
import java.util.List;
/**
 * Created by wxw on 2018/9/10.
 *
 * @author wxw.
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "DataSourcesTableFieldController", description = "OLAP-数据源表字段对应表", tags = {"OLAP-数据源表字段对应表"})
public class DataSourcesTableFieldController {
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private DataSourcesTableFieldService dataSourcesFieldService;
    @RequestMapping(value = "/olap/searchDSField", method = RequestMethod.GET)
    @ApiOperation(value = "根据查询条件查询,具有分页功能;filters='id=1'")
    public Envelop searchDSField(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+tableId")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) int size,
            @ApiParam(name = "page", value = "页码", defaultValue = "1")
            @RequestParam(value = "page", required = false) int page) throws Exception {
        Envelop envelop = new Envelop();
        List<DataSourcesTableField> search = dataSourcesFieldService.search(fields, filters, sorts, page, size);
        envelop.setSuccessFlg(true);
        envelop.setDetailModelList(search);
        return envelop;
    }
    @RequestMapping(value = "/olap/saveOrUpdateDSField", method = RequestMethod.POST)
    @ApiOperation(value = "添加或修改操作")
    public Envelop saveOrUpdateDSField(
            @ApiParam(name = "model", value = "json数据模型", defaultValue = "")
            @RequestParam String model) throws Exception {
        Envelop envelop = new Envelop();
        DataSourcesTableField dimensionMember = objectMapper.readValue(URLDecoder.decode(model, "UTF-8"), DataSourcesTableField.class);
        if (null == dimensionMember.getId()) {
            // 新增
            dataSourcesFieldService.save(dimensionMember);
        } else {
            dataSourcesFieldService.save(dimensionMember);
        }
        envelop.setSuccessFlg(true);
        return envelop;
    }
    @RequestMapping(value = "/olap/deleteDSFieldById", method = RequestMethod.DELETE)
    @ApiOperation(value = "根据id删除")
    public Envelop deleteOlapDMById(
            @ApiParam(name = "id", value = "编号", defaultValue = "")
            @RequestParam(value = "id") Integer id) throws Exception {
        Envelop envelop = new Envelop();
        dataSourcesFieldService.delete(id);
        envelop.setSuccessFlg(true);
        return envelop;
    }
}

+ 12 - 0
src/main/java/com/yihu/quota/dao/source/DataSourcesTableDao.java

@ -0,0 +1,12 @@
package com.yihu.quota.dao.source;
import com.yihu.quota.model.source.DataSourcesTable;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by wxw on 2018/9/10.
 *
 * @author wxw.
 */
public interface DataSourcesTableDao extends PagingAndSortingRepository<DataSourcesTable, Integer> {
}

+ 21 - 0
src/main/java/com/yihu/quota/dao/source/DataSourcesTableFieldDao.java

@ -0,0 +1,21 @@
package com.yihu.quota.dao.source;
import com.yihu.quota.model.source.DataSourcesTableField;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
/**
 * Created by wxw on 2018/9/10.
 *
 * @author wxw.
 */
public interface DataSourcesTableFieldDao extends PagingAndSortingRepository<DataSourcesTableField, Integer> {
    @Modifying
    @Transactional
    @Query("delete from DataSourcesTableField where tableId = :tableId")
    void deleteByTableId(@Param("tableId") Integer tableId);
}

+ 76 - 0
src/main/java/com/yihu/quota/model/source/DataSourcesTable.java

@ -0,0 +1,76 @@
package com.yihu.quota.model.source;
import javax.persistence.*;
import java.util.List;
/**
 * Created by wxw on 2018/9/10.
 *
 * @author wxw.
 */
@Entity
@Table(name = "olap_data_sources_table")
public class DataSourcesTable {
    private Integer id;
    private Integer type;
    private String tableNmae;
    private String note;
    private String primaryKeyName;
    // 临时字段
    private List<DataSourcesTableField> dataSourcesTableFields;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public Integer getType() {
        return type;
    }
    public void setType(Integer type) {
        this.type = type;
    }
    @Column(name = "table_name")
    public String getTableNmae() {
        return tableNmae;
    }
    public void setTableNmae(String tableNmae) {
        this.tableNmae = tableNmae;
    }
    public String getNote() {
        return note;
    }
    public void setNote(String note) {
        this.note = note;
    }
    @Column(name = "primary_key_name")
    public String getPrimaryKeyName() {
        return primaryKeyName;
    }
    public void setPrimaryKeyName(String primaryKeyName) {
        this.primaryKeyName = primaryKeyName;
    }
    @Transient
    public List<DataSourcesTableField> getDataSourcesTableFields() {
        return dataSourcesTableFields;
    }
    public void setDataSourcesTableFields(List<DataSourcesTableField> dataSourcesTableFields) {
        this.dataSourcesTableFields = dataSourcesTableFields;
    }
}

+ 64 - 0
src/main/java/com/yihu/quota/model/source/DataSourcesTableField.java

@ -0,0 +1,64 @@
package com.yihu.quota.model.source;
import javax.persistence.*;
/**
 * Created by wxw on 2018/9/10.
 *
 * @author wxw.
 */
@Entity
@Table(name = "olap_data_sources_table_field")
public class DataSourcesTableField {
    private Integer id;
    private Integer tableId;
    private String fieldName;
    private String fieldType;
    private String note;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    @Column(name = "table_id")
    public Integer getTableId() {
        return tableId;
    }
    public void setTableId(Integer tableId) {
        this.tableId = tableId;
    }
    @Column(name = "field_name")
    public String getFieldName() {
        return fieldName;
    }
    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }
    @Column(name = "field_type")
    public String getFieldType() {
        return fieldType;
    }
    public void setFieldType(String fieldType) {
        this.fieldType = fieldType;
    }
    public String getNote() {
        return note;
    }
    public void setNote(String note) {
        this.note = note;
    }
}

+ 15 - 0
src/main/java/com/yihu/quota/service/source/DataSourcesTableFieldService.java

@ -0,0 +1,15 @@
package com.yihu.quota.service.source;
import com.yihu.ehr.query.BaseJpaService;
import com.yihu.quota.dao.source.DataSourcesTableFieldDao;
import com.yihu.quota.model.source.DataSourcesTableField;
import org.springframework.stereotype.Service;
/**
 * Created by wxw on 2018/9/10.
 *
 * @author wxw.
 */
@Service
public class DataSourcesTableFieldService extends BaseJpaService<DataSourcesTableField, DataSourcesTableFieldDao> {
}

+ 29 - 0
src/main/java/com/yihu/quota/service/source/DataSourcesTableService.java

@ -0,0 +1,29 @@
package com.yihu.quota.service.source;
import com.yihu.ehr.query.BaseJpaService;
import com.yihu.quota.dao.source.DataSourcesTableDao;
import com.yihu.quota.dao.source.DataSourcesTableFieldDao;
import com.yihu.quota.model.source.DataSourcesTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * Created by wxw on 2018/9/10.
 *
 * @author wxw.
 */
@Service
public class DataSourcesTableService extends BaseJpaService<DataSourcesTable, DataSourcesTableDao> {
    @Autowired
    private DataSourcesTableDao dataSourcesTableDao;
    @Autowired
    private DataSourcesTableFieldDao dataSourcesTableFieldDao;
    public void deleteById(Integer id) {
        dataSourcesTableDao.delete(id);
        // 删除属于该数据源表对应的字段对应表
        dataSourcesTableFieldDao.deleteByTableId(id);
    }
}