diff --git a/hsweb-web-bean/src/main/java/org/hsweb/web/bean/po/plan/QueryPlan.java b/hsweb-web-bean/src/main/java/org/hsweb/web/bean/po/plan/QueryPlan.java new file mode 100644 index 000000000..223e69841 --- /dev/null +++ b/hsweb-web-bean/src/main/java/org/hsweb/web/bean/po/plan/QueryPlan.java @@ -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 { + //方案名称 + @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; + } +} \ No newline at end of file diff --git a/hsweb-web-controller/src/main/java/org/hsweb/web/controller/plan/QueryPlanController.java b/hsweb-web-controller/src/main/java/org/hsweb/web/controller/plan/QueryPlanController.java new file mode 100644 index 000000000..4cd910f7a --- /dev/null +++ b/hsweb-web-controller/src/main/java/org/hsweb/web/controller/plan/QueryPlanController.java @@ -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 { + + @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("方案不存在"); + } +} diff --git a/hsweb-web-dao-impl-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/plan/QueryPlanMapper.xml b/hsweb-web-dao-impl-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/plan/QueryPlanMapper.xml new file mode 100644 index 000000000..67b781536 --- /dev/null +++ b/hsweb-web-dao-impl-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/plan/QueryPlanMapper.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hsweb-web-dao-impl-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/plan/QueryPlanMapper.xml b/hsweb-web-dao-impl-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/plan/QueryPlanMapper.xml new file mode 100644 index 000000000..67b781536 --- /dev/null +++ b/hsweb-web-dao-impl-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/plan/QueryPlanMapper.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hsweb-web-dao-interface/src/main/java/org/hsweb/web/dao/plan/QueryPlanMapper.java b/hsweb-web-dao-interface/src/main/java/org/hsweb/web/dao/plan/QueryPlanMapper.java new file mode 100644 index 000000000..1e9b86c5f --- /dev/null +++ b/hsweb-web-dao-interface/src/main/java/org/hsweb/web/dao/plan/QueryPlanMapper.java @@ -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 { + +} diff --git a/hsweb-web-service-impl-common/src/main/java/org/hsweb/web/service/impl/plan/QueryPlanServiceImpl.java b/hsweb-web-service-impl-common/src/main/java/org/hsweb/web/service/impl/plan/QueryPlanServiceImpl.java new file mode 100644 index 000000000..d81374b0d --- /dev/null +++ b/hsweb-web-service-impl-common/src/main/java/org/hsweb/web/service/impl/plan/QueryPlanServiceImpl.java @@ -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 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")); + } +} diff --git a/hsweb-web-service-interface/src/main/java/org/hsweb/web/service/plan/QueryPlanService.java b/hsweb-web-service-interface/src/main/java/org/hsweb/web/service/plan/QueryPlanService.java new file mode 100644 index 000000000..ae75d356a --- /dev/null +++ b/hsweb-web-service-interface/src/main/java/org/hsweb/web/service/plan/QueryPlanService.java @@ -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 { + +}