Skip to content

Commit

Permalink
indexCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
wjinliang committed Apr 9, 2018
1 parent 0f616dc commit 8619d88
Show file tree
Hide file tree
Showing 8 changed files with 306 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.topie.zhongkexie.core.api;

import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
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.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.topie.zhongkexie.common.utils.PageConvertUtil;
import com.topie.zhongkexie.common.utils.ResponseUtil;
import com.topie.zhongkexie.common.utils.Result;
import com.topie.zhongkexie.core.service.IScoreIndexCollectionService;
import com.topie.zhongkexie.core.service.IScorePaperService;
import com.topie.zhongkexie.database.core.model.ScoreIndexCollection;

/**
* Created by wangJL on 2018/3/30.
*/
@Controller
@RequestMapping("/api/core/scoreIndexCollection")
public class ScoreIndexCollectionController {

@Autowired
private IScoreIndexCollectionService iScoreIndexCollectionService;
@Autowired
private IScorePaperService paperService;

@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public Result list(ScoreIndexCollection scoreIndexCollection,
@RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
@RequestParam(value = "pageSize", required = false, defaultValue = "15") int pageSize) {
PageInfo<ScoreIndexCollection> pageInfo = iScoreIndexCollectionService.selectByFilterAndPage(scoreIndexCollection, pageNum, pageSize);
return ResponseUtil.success(PageConvertUtil.grid(pageInfo));
}

@RequestMapping(value = "/insert", method = RequestMethod.POST)
@ResponseBody
public Result insert(ScoreIndexCollection scoreIndexCollection) {
scoreIndexCollection.setContentJson(paperService.getContentJson(scoreIndexCollection.getPaperId(), scoreIndexCollection.getIndexCollection(), null).toJSONString());
int result = iScoreIndexCollectionService.saveNotNull(scoreIndexCollection);
return result > 0 ? ResponseUtil.success() : ResponseUtil.error();
}

@RequestMapping(value = "/update", method = RequestMethod.POST)
@ResponseBody
public Result update(ScoreIndexCollection scoreIndexCollection) {
scoreIndexCollection.setContentJson(paperService.getContentJson(scoreIndexCollection.getPaperId(), scoreIndexCollection.getIndexCollection(), null).toJSONString());
iScoreIndexCollectionService.updateNotNull(scoreIndexCollection);
return ResponseUtil.success();
}

@RequestMapping(value = "/load/{id}", method = RequestMethod.GET)
@ResponseBody
public Result load(@PathVariable(value = "id") Integer id) {
ScoreIndexCollection scoreIndexCollection = iScoreIndexCollectionService.selectByKey(id);
return ResponseUtil.success(scoreIndexCollection);
}

@RequestMapping(value = "/delete", method = RequestMethod.GET)
@ResponseBody
public Result delete(@RequestParam(value = "id") Integer id) {
iScoreIndexCollectionService.delete(id);
return ResponseUtil.success();
}

@RequestMapping("getSelectedNodesId")
@ResponseBody
public Result getSelectedNodesId(Integer paperId,@RequestParam(required=false,value="id") Integer id){
Set set = this.iScoreIndexCollectionService.getSelectedNodesId(paperId,id);
return ResponseUtil.success(set);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.topie.zhongkexie.core.service;

import java.util.List;
import java.util.Set;

import com.github.pagehelper.PageInfo;
import com.topie.zhongkexie.common.baseservice.IService;
import com.topie.zhongkexie.database.core.model.ScoreIndexCollection;

public interface IScoreIndexCollectionService extends IService<ScoreIndexCollection>{

PageInfo<ScoreIndexCollection> selectByFilterAndPage(
ScoreIndexCollection scoreIndexCollection, int pageNum, int pageSize);

List selectByFilter(ScoreIndexCollection scoreIndexCollection);

Set getSelectedNodesId(Integer paperId, Integer id);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.topie.zhongkexie.core.service.impl;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;
import tk.mybatis.mapper.util.StringUtil;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.topie.zhongkexie.common.baseservice.impl.BaseService;
import com.topie.zhongkexie.core.service.IScoreIndexCollectionService;
import com.topie.zhongkexie.database.core.model.ScoreIndexCollection;

@Service
public class ScoreIndexCollectionServiceImpl extends BaseService<ScoreIndexCollection> implements IScoreIndexCollectionService {

@Override
public List<ScoreIndexCollection> selectByFilter(ScoreIndexCollection dict) {
Example ex = new Example(ScoreIndexCollection.class);
Criteria c = ex.createCriteria();
if(StringUtils.isNotEmpty(dict.getName()))c.andLike("name", "%"+dict.getName()+"%");
if(dict.getPaperId()!=null)c.andEqualTo("paperId", dict.getPaperId());
return getMapper().selectByExample(ex);
}

@Override
public PageInfo<ScoreIndexCollection> selectByFilterAndPage(ScoreIndexCollection dict, int pageNum,
int pageSize) {
PageHelper.startPage(pageNum, pageSize);
List<ScoreIndexCollection> list = selectByFilter(dict);
return new PageInfo<ScoreIndexCollection>(list);
}

@Override
public Set getSelectedNodesId(Integer paperId, Integer id) {
Example ex = new Example(ScoreIndexCollection.class);
Criteria c = ex.createCriteria();
c.andEqualTo("paperId", paperId);
if(id!=null){
c.andNotEqualTo("id", id);
}
List<ScoreIndexCollection> list = getMapper().selectByExample(ex);
Set set = new HashSet();
for(ScoreIndexCollection s:list){
String indexs = s.getIndexCollection();
if(StringUtil.isNotEmpty(indexs))
for(String indexid:indexs.split(","))
set.add(indexid);
}
return set;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.topie.zhongkexie.database.core.dao;

import com.topie.zhongkexie.database.core.model.ScoreIndexCollection;
import tk.mybatis.mapper.common.Mapper;

public interface ScoreIndexCollectionMapper extends Mapper<ScoreIndexCollection> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package com.topie.zhongkexie.database.core.model;

import javax.persistence.*;

@Table(name = "d_score_index_collection")
public class ScoreIndexCollection {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

private String name;

@Column(name = "paper_id")
private Integer paperId;

private String description;

@Column(name = "item_collection")
private String itemCollection;

@Column(name = "index_collection")
private String indexCollection;

@Column(name = "content_json")
private String contentJson;

/**
* @return id
*/
public Integer getId() {
return id;
}

/**
* @param id
*/
public void setId(Integer id) {
this.id = id;
}

/**
* @return name
*/
public String getName() {
return name;
}

/**
* @param name
*/
public void setName(String name) {
this.name = name;
}

/**
* @return paper_id
*/
public Integer getPaperId() {
return paperId;
}

/**
* @param paperId
*/
public void setPaperId(Integer paperId) {
this.paperId = paperId;
}

/**
* @return description
*/
public String getDescription() {
return description;
}

/**
* @param description
*/
public void setDescription(String description) {
this.description = description;
}

/**
* @return item_collection
*/
public String getItemCollection() {
return itemCollection;
}

/**
* @param itemCollection
*/
public void setItemCollection(String itemCollection) {
this.itemCollection = itemCollection;
}

/**
* @return index_collection
*/
public String getIndexCollection() {
return indexCollection;
}

/**
* @param indexCollection
*/
public void setIndexCollection(String indexCollection) {
this.indexCollection = indexCollection;
}

/**
* @return content_json
*/
public String getContentJson() {
return contentJson;
}

/**
* @param contentJson
*/
public void setContentJson(String contentJson) {
this.contentJson = contentJson;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/config/spring/spring-mybatis.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<value>classpath*:mapper/core/**/*.xml</value>
</array>
</property>
<property name="typeAliasesPackage" value="com.topie.zhongkexie.database.core.model"/>
<property name="typeAliasesPackage" value="com.topie.zhongkexie.database.*.model"/>
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageHelper">
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/generator/generatorConfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<javaClientGenerator targetPackage="com.topie.zhongkexie.database.core.dao"
targetProject="${targetBasedir}/src/main/java" type="XMLMAPPER"/>

<table tableName="d_dict" domainObjectName="Dict">
<table tableName="d_score_index_collection" domainObjectName="ScoreIndexCollection">
<generatedKey column="id" sqlStatement="Mysql" identity="true"/>
</table>
</context>
Expand Down
16 changes: 16 additions & 0 deletions src/main/resources/mapper/core/ScoreIndexCollectionMapper.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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="com.topie.zhongkexie.database.core.dao.ScoreIndexCollectionMapper" >
<resultMap id="BaseResultMap" type="com.topie.zhongkexie.database.core.model.ScoreIndexCollection" >
<!--
WARNING - @mbggenerated
-->
<id column="id" property="id" jdbcType="INTEGER" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="paper_id" property="paperId" jdbcType="INTEGER" />
<result column="description" property="description" jdbcType="VARCHAR" />
<result column="item_collection" property="itemCollection" jdbcType="VARCHAR" />
<result column="index_collection" property="indexCollection" jdbcType="VARCHAR" />
<result column="content_json" property="contentJson" jdbcType="VARCHAR" />
</resultMap>
</mapper>

0 comments on commit 8619d88

Please sign in to comment.