10 changed files with 393 additions and 0 deletions
@ -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; |
|||
|
|||
} |
|||
@ -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("操作成功"); |
|||
} |
|||
} |
|||
@ -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); |
|||
|
|||
} |
|||
@ -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; |
|||
|
|||
} |
|||
@ -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); |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue