新增查询方案管理

This commit is contained in:
zhouhao
2016-08-11 16:47:28 +08:00
parent af04f6abe5
commit fca8ac38e8
7 changed files with 480 additions and 0 deletions

View File

@@ -0,0 +1,137 @@
/*
* Copyright 2015-2016 http://hsweb.me
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hsweb.web.bean.po.plan;
import org.hibernate.validator.constraints.NotBlank;
import org.hsweb.web.bean.po.GenericPo;
/**
* 查询方案
* Created by hsweb-generator Aug 8, 2016 1:24:08 AM
*/
public class QueryPlan extends GenericPo<String> {
//方案名称
@NotBlank(message = "名称不能为空")
private String name;
//方案分类
@NotBlank(message = "类型不能为空")
private String type;
//方案配置
private String config;
//是否共享方案
private boolean sharing;
//创建人ID
@NotBlank(message = "创建人不能为空")
private String creatorId;
//创建日期
private java.util.Date createDate;
/**
* 获取 方案名称
*
* @return String 方案名称
*/
public String getName() {
return this.name;
}
/**
* 设置 方案名称
*/
public void setName(String name) {
this.name = name;
}
/**
* 获取 方案分类
*
* @return String 方案分类
*/
public String getType() {
return this.type;
}
/**
* 设置 方案分类
*/
public void setType(String type) {
this.type = type;
}
/**
* 获取 方案配置
*
* @return String 方案配置
*/
public String getConfig() {
return this.config;
}
/**
* 设置 方案配置
*/
public void setConfig(String config) {
this.config = config;
}
/**
* 获取 是否共享方案
*
* @return boolean 是否共享方案
*/
public boolean isSharing() {
return this.sharing;
}
/**
* 设置 是否共享方案
*/
public void setSharing(boolean sharing) {
this.sharing = sharing;
}
/**
* 获取 创建人ID
*
* @return String 创建人ID
*/
public String getCreatorId() {
return this.creatorId;
}
/**
* 设置 创建人ID
*/
public void setCreatorId(String creatorId) {
this.creatorId = creatorId;
}
/**
* 获取 创建日期
*
* @return java.util.Date 创建日期
*/
public java.util.Date getCreateDate() {
return this.createDate;
}
/**
* 设置 创建日期
*/
public void setCreateDate(java.util.Date createDate) {
this.createDate = createDate;
}
}

View File

@@ -0,0 +1,110 @@
/*
* Copyright 2015-2016 http://hsweb.me
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hsweb.web.controller.plan;
import org.hsweb.web.bean.common.QueryParam;
import org.hsweb.web.bean.po.plan.QueryPlan;
import org.hsweb.web.bean.po.user.User;
import org.hsweb.web.controller.GenericController;
import org.hsweb.web.core.authorize.annotation.Authorize;
import org.hsweb.web.core.exception.NotFoundException;
import org.hsweb.web.core.logger.annotation.AccessLogger;
import org.hsweb.web.core.message.ResponseMessage;
import org.hsweb.web.core.utils.WebUtil;
import org.hsweb.web.service.plan.QueryPlanService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Date;
/**
* 查询方案控制器
* Created by hsweb-generator
*/
@RestController
@RequestMapping(value = "/query-plan")
@AccessLogger("查询方案")
@Authorize(module = "query-plan")
public class QueryPlanController extends GenericController<QueryPlan, String> {
@Resource
private QueryPlanService queryPlanService;
@Override
public QueryPlanService getService() {
return this.queryPlanService;
}
@Override
@Authorize(action = "admin")
public ResponseMessage list(QueryParam param) {
return super.list(param);
}
@RequestMapping(value = "/type/{type}", method = RequestMethod.GET)
@AccessLogger("当前用户对应的类型")
public ResponseMessage byLoginUserAndType(@PathVariable("type") String type) {
User user = WebUtil.getLoginUser();
// where type=#{type} and (create_id=#{user.id} or sharing=1)
QueryParam param = QueryParam.build().noPaging();
param.where("type", type)
.nest("creatorId", user.getId()).or("sharing", 1);
return ResponseMessage.ok(queryPlanService.select(param)).onlyData();
}
@Override
public ResponseMessage add(@RequestBody QueryPlan object) {
User user = WebUtil.getLoginUser();
object.setCreateDate(new Date());
object.setCreatorId(user.getId());
return super.add(object);
}
@Override
public ResponseMessage info(@PathVariable("id") String id) {
QueryPlan plan = queryPlanService.selectByPk(id);
validPlan(plan);
return ResponseMessage.ok(plan);
}
@Override
public ResponseMessage delete(@PathVariable("id") String id) {
QueryPlan plan = queryPlanService.selectByPk(id);
validPlan(plan);
return ResponseMessage.ok(queryPlanService.delete(id));
}
@Override
public ResponseMessage update(@PathVariable("id") String id, @RequestBody QueryPlan object) {
QueryPlan plan = queryPlanService.selectByPk(id);
validPlan(plan);
object.setId(id);
return ResponseMessage.ok(queryPlanService.update(object));
}
@Override
public ResponseMessage update(@RequestBody String json) {
throw new NotFoundException("");
}
void validPlan(QueryPlan plan) {
User user = WebUtil.getLoginUser();
//方案不存在或者方案未共享并且不是由本人创建
if (plan == null || (!plan.isSharing() && !user.getId().equals(plan.getCreatorId())))
throw new NotFoundException("方案不存在");
}
}

View File

@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
~ Copyright 2015-2016 http://hsweb.me
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://www.mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.hsweb.web.dao.plan.QueryPlanMapper">
<resultMap id="QueryPlanResultMap" type="org.hsweb.web.bean.po.plan.QueryPlan">
<id property="id" column="u_id" javaType="string" jdbcType="VARCHAR"/>
<result property="name" column="name" javaType="String" jdbcType="VARCHAR"/>
<result property="type" column="type" javaType="String" jdbcType="VARCHAR"/>
<result property="config" column="config" javaType="String" jdbcType="CLOB"/>
<result property="sharing" column="sharing" javaType="boolean" jdbcType="INTEGER"/>
<result property="creatorId" column="creator_id" javaType="String" jdbcType="VARCHAR"/>
<result property="createDate" column="create_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
</resultMap>
<!--用于动态生成sql所需的配置-->
<sql id="config">
<bind name="resultMapId" value="'QueryPlanResultMap'"/>
<bind name="tableName" value="'s_query_plan'"/>
</sql>
<insert id="insert" parameterType="org.hsweb.web.bean.common.InsertParam" >
<include refid="config"/>
<include refid="BasicMapper.buildInsertSql"/>
</insert>
<delete id="delete" parameterType="org.hsweb.web.bean.common.DeleteParam">
<include refid="config"/>
<include refid="BasicMapper.buildDeleteSql"/>
</delete>
<update id="update" parameterType="org.hsweb.web.bean.common.UpdateParam">
<include refid="config"/>
<include refid="BasicMapper.buildUpdateSql"/>
</update>
<select id="selectByPk" parameterType="string" resultMap="QueryPlanResultMap">
select * from s_query_plan where u_id=#{id}
</select>
<select id="select" parameterType="org.hsweb.web.bean.common.QueryParam" resultMap="QueryPlanResultMap">
<include refid="config"/>
<include refid="BasicMapper.buildSelectSql"/>
</select>
<select id="total" parameterType="org.hsweb.web.bean.common.QueryParam" resultType="int">
<include refid="config"/>
<include refid="BasicMapper.buildTotalSql"/>
</select>
</mapper>

View File

@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
~ Copyright 2015-2016 http://hsweb.me
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://www.mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.hsweb.web.dao.plan.QueryPlanMapper">
<resultMap id="QueryPlanResultMap" type="org.hsweb.web.bean.po.plan.QueryPlan">
<id property="id" column="u_id" javaType="string" jdbcType="VARCHAR"/>
<result property="name" column="name" javaType="String" jdbcType="VARCHAR"/>
<result property="type" column="type" javaType="String" jdbcType="VARCHAR"/>
<result property="config" column="config" javaType="String" jdbcType="CLOB"/>
<result property="sharing" column="sharing" javaType="boolean" jdbcType="INTEGER"/>
<result property="creatorId" column="creator_id" javaType="String" jdbcType="VARCHAR"/>
<result property="createDate" column="create_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
</resultMap>
<!--用于动态生成sql所需的配置-->
<sql id="config">
<bind name="resultMapId" value="'QueryPlanResultMap'"/>
<bind name="tableName" value="'s_query_plan'"/>
</sql>
<insert id="insert" parameterType="org.hsweb.web.bean.common.InsertParam" >
<include refid="config"/>
<include refid="BasicMapper.buildInsertSql"/>
</insert>
<delete id="delete" parameterType="org.hsweb.web.bean.common.DeleteParam">
<include refid="config"/>
<include refid="BasicMapper.buildDeleteSql"/>
</delete>
<update id="update" parameterType="org.hsweb.web.bean.common.UpdateParam">
<include refid="config"/>
<include refid="BasicMapper.buildUpdateSql"/>
</update>
<select id="selectByPk" parameterType="string" resultMap="QueryPlanResultMap">
select * from s_query_plan where u_id=#{id}
</select>
<select id="select" parameterType="org.hsweb.web.bean.common.QueryParam" resultMap="QueryPlanResultMap">
<include refid="config"/>
<include refid="BasicMapper.buildSelectSql"/>
</select>
<select id="total" parameterType="org.hsweb.web.bean.common.QueryParam" resultType="int">
<include refid="config"/>
<include refid="BasicMapper.buildTotalSql"/>
</select>
</mapper>

View File

@@ -0,0 +1,28 @@
/*
* Copyright 2015-2016 http://hsweb.me
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hsweb.web.dao.plan;
import org.hsweb.web.bean.po.plan.QueryPlan;
import org.hsweb.web.dao.GenericMapper;
/**
* 查询方案数据映射接口
* Created by generator
*/
public interface QueryPlanMapper extends GenericMapper<QueryPlan,String> {
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright 2015-2016 http://hsweb.me
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hsweb.web.service.impl.plan;
import org.hsweb.web.bean.common.UpdateParam;
import org.hsweb.web.bean.po.plan.QueryPlan;
import org.hsweb.web.dao.plan.QueryPlanMapper;
import org.hsweb.web.service.impl.AbstractServiceImpl;
import org.hsweb.web.service.plan.QueryPlanService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* 查询方案服务类
* Created by generator
*/
@Service("queryPlanService")
public class QueryPlanServiceImpl extends AbstractServiceImpl<QueryPlan, String> implements QueryPlanService {
@Resource
protected QueryPlanMapper queryPlanMapper;
@Override
protected QueryPlanMapper getMapper() {
return this.queryPlanMapper;
}
@Override
public int update(QueryPlan data) {
return queryPlanMapper.update(UpdateParam.build(data).includes("name", "config", "sharing"));
}
}

View File

@@ -0,0 +1,28 @@
/*
* Copyright 2015-2016 http://hsweb.me
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hsweb.web.service.plan;
import org.hsweb.web.bean.po.plan.QueryPlan;
import org.hsweb.web.service.GenericService;
/**
* 查询方案服务类
* Created by generator
*/
public interface QueryPlanService extends GenericService<QueryPlan, String> {
}