From 831ebfca185add5d4cad2d82efc2e3cb05a3c890 Mon Sep 17 00:00:00 2001 From: chenc Date: Sun, 30 Jul 2023 23:00:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=97=E9=93=BA=E7=AE=A1=E7=90=86=20init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/common/constant/ShopConstant.java | 19 +++ .../main/java/cc/hiver/core/dao/UserDao.java | 4 + .../cc/hiver/core/service/UserService.java | 10 ++ .../core/serviceimpl/UserServiceImpl.java | 5 + .../app/controller/admin/ShopController.java | 109 ++++++++++++++++++ .../main/java/cc/hiver/app/dao/ShopDao.java | 37 ++++++ .../main/java/cc/hiver/app/entity/Shop.java | 77 +++++++++++++ .../cc/hiver/app/service/ShopService.java | 43 +++++++ .../app/serviceimpl/ShopServiceImpl.java | 78 +++++++++++++ .../controller/manage/UserController.java | 11 ++ 10 files changed, 393 insertions(+) create mode 100644 hiver-core/src/main/java/cc/hiver/core/common/constant/ShopConstant.java create mode 100644 hiver-modules/hiver-app/src/main/java/cc/hiver/app/controller/admin/ShopController.java create mode 100644 hiver-modules/hiver-app/src/main/java/cc/hiver/app/dao/ShopDao.java create mode 100644 hiver-modules/hiver-app/src/main/java/cc/hiver/app/entity/Shop.java create mode 100644 hiver-modules/hiver-app/src/main/java/cc/hiver/app/service/ShopService.java create mode 100644 hiver-modules/hiver-app/src/main/java/cc/hiver/app/serviceimpl/ShopServiceImpl.java diff --git a/hiver-core/src/main/java/cc/hiver/core/common/constant/ShopConstant.java b/hiver-core/src/main/java/cc/hiver/core/common/constant/ShopConstant.java new file mode 100644 index 00000000..1039e895 --- /dev/null +++ b/hiver-core/src/main/java/cc/hiver/core/common/constant/ShopConstant.java @@ -0,0 +1,19 @@ +package cc.hiver.core.common.constant; + +/** + * 店铺常量 + * + * @author cc + */ +public interface ShopConstant { + + /** + * 用户正常状态 + */ + Integer SHOP_STATUS_NORMAL = 1; + /** + * 用户禁用状态 + */ + Integer SHOP_STATUS_LOCK = 0; + +} diff --git a/hiver-core/src/main/java/cc/hiver/core/dao/UserDao.java b/hiver-core/src/main/java/cc/hiver/core/dao/UserDao.java index f3ff568e..cda5acd2 100644 --- a/hiver-core/src/main/java/cc/hiver/core/dao/UserDao.java +++ b/hiver-core/src/main/java/cc/hiver/core/dao/UserDao.java @@ -4,6 +4,7 @@ import cc.hiver.core.base.HiverBaseDao; import cc.hiver.core.entity.User; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import java.util.List; @@ -64,4 +65,7 @@ public interface UserDao extends HiverBaseDao { @Modifying @Query("update User u set u.departmentTitle=?2 where u.departmentId=?1") void updateDepartmentTitle(String departmentId, String departmentTitle); + + @Query(value = "select * from t_user where id in (select user_id from t_user_role where role_id = (select id from t_role where name = ? ))",nativeQuery = true) + List findByRoleName( String roleName); } diff --git a/hiver-core/src/main/java/cc/hiver/core/service/UserService.java b/hiver-core/src/main/java/cc/hiver/core/service/UserService.java index 484ad4e1..9353bef2 100644 --- a/hiver-core/src/main/java/cc/hiver/core/service/UserService.java +++ b/hiver-core/src/main/java/cc/hiver/core/service/UserService.java @@ -7,6 +7,8 @@ import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.Cacheable; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import java.util.List; @@ -75,4 +77,12 @@ public interface UserService extends HiverBaseService { * @param departmentTitle */ void updateDepartmentTitle(String departmentId, String departmentTitle); + + /** + * 通过角色名搜索 + * + * @param roleName + * @return + */ + List findByRoleName(@Param("roleName") String roleName); } diff --git a/hiver-core/src/main/java/cc/hiver/core/serviceimpl/UserServiceImpl.java b/hiver-core/src/main/java/cc/hiver/core/serviceimpl/UserServiceImpl.java index f08bd7df..265cba4b 100644 --- a/hiver-core/src/main/java/cc/hiver/core/serviceimpl/UserServiceImpl.java +++ b/hiver-core/src/main/java/cc/hiver/core/serviceimpl/UserServiceImpl.java @@ -177,4 +177,9 @@ public class UserServiceImpl implements UserService { public void updateDepartmentTitle(String departmentId, String departmentTitle) { userDao.updateDepartmentTitle(departmentId, departmentTitle); } + + @Override + public List findByRoleName(String roleName) { + return userDao.findByRoleName(roleName); + } } diff --git a/hiver-modules/hiver-app/src/main/java/cc/hiver/app/controller/admin/ShopController.java b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/controller/admin/ShopController.java new file mode 100644 index 00000000..7d0d802f --- /dev/null +++ b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/controller/admin/ShopController.java @@ -0,0 +1,109 @@ +/* +Copyright [2022] [https://hiver.cc] + +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 cc.hiver.app.controller.admin; + +import cc.hiver.app.entity.Shop; +import cc.hiver.app.service.ShopService; +import cc.hiver.core.common.constant.ShopConstant; +import cc.hiver.core.common.utils.PageUtil; +import cc.hiver.core.common.utils.ResultUtil; +import cc.hiver.core.common.vo.PageVo; +import cc.hiver.core.common.vo.Result; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * @author cc + */ +@Slf4j +@RestController +@Api(tags = "店铺管理接口") +@RequestMapping(value = "/hiver/app/shop/") +public class ShopController { + @Autowired + private ShopService shopService; + + @RequestMapping(value = "/getAll", method = RequestMethod.GET) + @ApiOperation(value = "获取全部数据") + public Result> getAll() { + List list = shopService.getAll(); + return new ResultUtil>().setData(list); + } + + @RequestMapping(value = "/add", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "添加") + public Result add(Shop shop) { + if (shopService.findByShopName(shop.getShopName()) != null) { + return ResultUtil.error("店铺名称已经存在"); + } + shopService.save(shop); + return ResultUtil.success("添加成功"); + } + + @RequestMapping(value = "/edit", method = RequestMethod.PUT) + @ResponseBody + @ApiOperation(value = "编辑") + public Result edit(Shop shop) { + shopService.update(shop); + return ResultUtil.success("编辑成功"); + } + + @RequestMapping(value = "/delByIds", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "通过id删除") + public Result delAllByIds(@RequestParam String[] ids) { + for (String id : ids) { + Shop shop = shopService.get(id); + shopService.delete(id); + } + return ResultUtil.success("删除成功"); + } + + @RequestMapping(value = "/getByCondition", method = RequestMethod.GET) + @ApiOperation(value = "多条件分页获取公司列表") + public Result> getByCondition(Shop shop, + PageVo pageVo) { + Page page = shopService.findByCondition(shop, PageUtil.initPage(pageVo)); + return new ResultUtil>().setData(page); + } + + @RequestMapping(value = "/enable", method = RequestMethod.POST) + @ApiOperation(value = "启用店铺") + public Result enable(@RequestParam String id) { + Shop shop = shopService.get(id); + shop.setStatus(ShopConstant.SHOP_STATUS_NORMAL); + shopService.update(shop); + + return ResultUtil.success("操作成功"); + } + + @RequestMapping(value = "/disable", method = RequestMethod.POST) + @ApiOperation(value = "关闭店铺") + public Result disable(@RequestParam String id) { + Shop shop = shopService.get(id); + shop.setStatus(ShopConstant.SHOP_STATUS_LOCK); + shopService.update(shop); + + return ResultUtil.success("操作成功"); + } +} diff --git a/hiver-modules/hiver-app/src/main/java/cc/hiver/app/dao/ShopDao.java b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/dao/ShopDao.java new file mode 100644 index 00000000..41ffd6b9 --- /dev/null +++ b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/dao/ShopDao.java @@ -0,0 +1,37 @@ +/* +Copyright [2022] [https://hiver.cc] + +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 cc.hiver.app.dao; + +import cc.hiver.app.entity.Shop; +import cc.hiver.core.base.HiverBaseDao; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.lang.Nullable; + +/** + * @author cc + */ +public interface ShopDao extends HiverBaseDao { + /** + * 通过公司名称获得记录 + * + * @param shopName + * @return + */ + Shop findByShopName(String shopName); + +} diff --git a/hiver-modules/hiver-app/src/main/java/cc/hiver/app/entity/Shop.java b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/entity/Shop.java new file mode 100644 index 00000000..654f5350 --- /dev/null +++ b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/entity/Shop.java @@ -0,0 +1,77 @@ +/* +Copyright [2022] [https://hiver.cc] + +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 cc.hiver.app.entity; + +import cc.hiver.core.base.HiverBaseEntity; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import javax.persistence.Entity; +import javax.persistence.Table; + +/** + * 店铺实体类 + * + * @author cc + */ +@Data +@Entity +@DynamicInsert +@DynamicUpdate +@Table(name = "t_shop") +@TableName("t_shop") +@ApiModel(value = "店铺信息") +public class Shop extends HiverBaseEntity { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "店铺名称") + private String shopName; + + @ApiModelProperty(value = "店主id") + private String shopOwnerId; + + @ApiModelProperty(value = "店长id") + private String shopMangerId; + + @ApiModelProperty(value = "区域") + private String shopArea; + + @ApiModelProperty(value = "地址") + private String shopAddress; + + @ApiModelProperty(value = "年费") + private String yearFee; + + @ApiModelProperty(value = "充值时间") + private String chargeTime; + + @ApiModelProperty(value = "起始日") + private String startTime; + + @ApiModelProperty(value = "截止日") + private String endTime; + + @ApiModelProperty(value = "状态") + private int status; + + @ApiModelProperty(value = "备注") + private String remark; + +} diff --git a/hiver-modules/hiver-app/src/main/java/cc/hiver/app/service/ShopService.java b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/service/ShopService.java new file mode 100644 index 00000000..78ae1657 --- /dev/null +++ b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/service/ShopService.java @@ -0,0 +1,43 @@ +/* +Copyright [2022] [https://hiver.cc] + +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 cc.hiver.app.service; + +import cc.hiver.app.entity.Shop; +import cc.hiver.core.base.HiverBaseService; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +/** + * @author cc + */ +public interface ShopService extends HiverBaseService { + /** + * 多条件获取 + * + * @param shop + * @param pageable + * @return + */ + Page findByCondition(Shop shop, Pageable pageable); + + /** + * 通过公司名称获得记录 + * + * @param shopName + * @return + */ + Shop findByShopName(String shopName); +} diff --git a/hiver-modules/hiver-app/src/main/java/cc/hiver/app/serviceimpl/ShopServiceImpl.java b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/serviceimpl/ShopServiceImpl.java new file mode 100644 index 00000000..7097b5ae --- /dev/null +++ b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/serviceimpl/ShopServiceImpl.java @@ -0,0 +1,78 @@ +/* +Copyright [2022] [https://hiver.cc] + +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 cc.hiver.app.serviceimpl; + +import cc.hiver.app.dao.ShopDao; +import cc.hiver.app.entity.Shop; +import cc.hiver.app.service.ShopService; +import cc.hiver.core.base.HiverBaseDao; +import cn.hutool.core.util.StrUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.lang.Nullable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.criteria.*; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Yazhi Li + */ +@Slf4j +@Service +@Transactional +public class ShopServiceImpl implements ShopService { + @Autowired + private ShopDao shopDao; + + @Override + public HiverBaseDao getRepository() { + return shopDao; + } + + @Override + public Page findByCondition(Shop Shop, Pageable pageable) { + return shopDao.findAll(new Specification() { + @Nullable + @Override + public Predicate toPredicate(Root root, CriteriaQuery cq, CriteriaBuilder cb) { + Path ShopNameField = root.get("shopName"); + + List list = new ArrayList<>(); + + if (StrUtil.isNotBlank(Shop.getShopName())) { + list.add(cb.like(ShopNameField, '%' + Shop.getShopName() + '%')); + } + + + + Predicate[] arr = new Predicate[list.size()]; + cq.where(list.toArray(arr)); + return null; + } + }, pageable); + } + + @Override + public Shop findByShopName(String ShopName) { + return shopDao.findByShopName(ShopName); + } +} diff --git a/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/UserController.java b/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/UserController.java index 66f21464..939ce64d 100644 --- a/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/UserController.java +++ b/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/UserController.java @@ -207,6 +207,17 @@ public class UserController { return new ResultUtil>().setData(list); } + @RequestMapping(value = "/getByRoleName/{roleName}", method = RequestMethod.GET) + @ApiOperation(value = "根据角色查询用户列表") + public Result> getByRoleName(@PathVariable String roleName) { + List list = userService.findByRoleName(roleName); + list.forEach(u -> { + entityManager.detach(u); + u.setPassword(null); + }); + return new ResultUtil>().setData(list); + } + @RequestMapping(value = "/searchByName/{username}", method = RequestMethod.GET) @ApiOperation(value = "通过用户名搜索用户") public Result> searchByName(@PathVariable String username) throws UnsupportedEncodingException {