Browse Source

店铺管理 init

cangku
chenc 3 years ago
parent
commit
831ebfca18
  1. 19
      hiver-core/src/main/java/cc/hiver/core/common/constant/ShopConstant.java
  2. 4
      hiver-core/src/main/java/cc/hiver/core/dao/UserDao.java
  3. 10
      hiver-core/src/main/java/cc/hiver/core/service/UserService.java
  4. 5
      hiver-core/src/main/java/cc/hiver/core/serviceimpl/UserServiceImpl.java
  5. 109
      hiver-modules/hiver-app/src/main/java/cc/hiver/app/controller/admin/ShopController.java
  6. 37
      hiver-modules/hiver-app/src/main/java/cc/hiver/app/dao/ShopDao.java
  7. 77
      hiver-modules/hiver-app/src/main/java/cc/hiver/app/entity/Shop.java
  8. 43
      hiver-modules/hiver-app/src/main/java/cc/hiver/app/service/ShopService.java
  9. 78
      hiver-modules/hiver-app/src/main/java/cc/hiver/app/serviceimpl/ShopServiceImpl.java
  10. 11
      hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/UserController.java

19
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;
}

4
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 cc.hiver.core.entity.User;
import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List; import java.util.List;
@ -64,4 +65,7 @@ public interface UserDao extends HiverBaseDao<User, String> {
@Modifying @Modifying
@Query("update User u set u.departmentTitle=?2 where u.departmentId=?1") @Query("update User u set u.departmentTitle=?2 where u.departmentId=?1")
void updateDepartmentTitle(String departmentId, String departmentTitle); 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<User> findByRoleName( String roleName);
} }

10
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.cache.annotation.Cacheable;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List; import java.util.List;
@ -75,4 +77,12 @@ public interface UserService extends HiverBaseService<User, String> {
* @param departmentTitle * @param departmentTitle
*/ */
void updateDepartmentTitle(String departmentId, String departmentTitle); void updateDepartmentTitle(String departmentId, String departmentTitle);
/**
* 通过角色名搜索
*
* @param roleName
* @return
*/
List<User> findByRoleName(@Param("roleName") String roleName);
} }

5
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) { public void updateDepartmentTitle(String departmentId, String departmentTitle) {
userDao.updateDepartmentTitle(departmentId, departmentTitle); userDao.updateDepartmentTitle(departmentId, departmentTitle);
} }
@Override
public List<User> findByRoleName(String roleName) {
return userDao.findByRoleName(roleName);
}
} }

109
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<List<Shop>> getAll() {
List<Shop> list = shopService.getAll();
return new ResultUtil<List<Shop>>().setData(list);
}
@RequestMapping(value = "/add", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "添加")
public Result<Object> 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<Object> edit(Shop shop) {
shopService.update(shop);
return ResultUtil.success("编辑成功");
}
@RequestMapping(value = "/delByIds", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "通过id删除")
public Result<Object> 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<Page<Shop>> getByCondition(Shop shop,
PageVo pageVo) {
Page<Shop> page = shopService.findByCondition(shop, PageUtil.initPage(pageVo));
return new ResultUtil<Page<Shop>>().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("操作成功");
}
}

37
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<Shop, String> {
/**
* 通过公司名称获得记录
*
* @param shopName
* @return
*/
Shop findByShopName(String shopName);
}

77
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;
}

43
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<Shop, String> {
/**
* 多条件获取
*
* @param shop
* @param pageable
* @return
*/
Page<Shop> findByCondition(Shop shop, Pageable pageable);
/**
* 通过公司名称获得记录
*
* @param shopName
* @return
*/
Shop findByShopName(String shopName);
}

78
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<Shop, String> getRepository() {
return shopDao;
}
@Override
public Page<Shop> findByCondition(Shop Shop, Pageable pageable) {
return shopDao.findAll(new Specification<Shop>() {
@Nullable
@Override
public Predicate toPredicate(Root<Shop> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
Path<String> ShopNameField = root.get("shopName");
List<Predicate> 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);
}
}

11
hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/UserController.java

@ -207,6 +207,17 @@ public class UserController {
return new ResultUtil<List<User>>().setData(list); return new ResultUtil<List<User>>().setData(list);
} }
@RequestMapping(value = "/getByRoleName/{roleName}", method = RequestMethod.GET)
@ApiOperation(value = "根据角色查询用户列表")
public Result<List<User>> getByRoleName(@PathVariable String roleName) {
List<User> list = userService.findByRoleName(roleName);
list.forEach(u -> {
entityManager.detach(u);
u.setPassword(null);
});
return new ResultUtil<List<User>>().setData(list);
}
@RequestMapping(value = "/searchByName/{username}", method = RequestMethod.GET) @RequestMapping(value = "/searchByName/{username}", method = RequestMethod.GET)
@ApiOperation(value = "通过用户名搜索用户") @ApiOperation(value = "通过用户名搜索用户")
public Result<List<User>> searchByName(@PathVariable String username) throws UnsupportedEncodingException { public Result<List<User>> searchByName(@PathVariable String username) throws UnsupportedEncodingException {

Loading…
Cancel
Save