Update ShopDetailController.java

cyj
pbvfus8to 8 months ago
parent 74e503e1c9
commit adff03961d

@ -8,6 +8,7 @@
*
*/
// 该类所属的包名,表明其位于管理端控制器相关的包下,用于对店铺详情相关操作进行控制和处理
package com.yami.shop.admin.controller;
import cn.hutool.core.util.StrUtil;
@ -30,131 +31,183 @@ import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* ShopDetailControllerSpring RESTfulShopDetail
*
*
* @author lgh on 2018/08/29.
*/
@RestController
// 定义该控制器类的基础请求路径,所有该类中的接口请求路径都将以此为前缀,表明是与店铺详情相关的操作接口
@RequestMapping("/shop/shopDetail")
public class ShopDetailController {
// 通过Spring的依赖注入机制自动注入ShopDetailService的实例以便调用其提供的与店铺详情相关的业务逻辑方法
@Autowired
private ShopDetailService shopDetailService;
/**
*
*/
@PutMapping("/isDistribution")
public ServerResponseEntity<Void> updateIsDistribution(@RequestParam Integer isDistribution){
ShopDetail shopDetail=new ShopDetail();
shopDetail.setShopId(SecurityUtils.getSysUser().getShopId());
shopDetail.setIsDistribution(isDistribution);
shopDetailService.updateById(shopDetail);
// 更新完成后删除缓存
shopDetailService.removeShopDetailCacheByShopId(shopDetail.getShopId());
return ServerResponseEntity.success();
}
/**
*
*/
@GetMapping("/info")
@PreAuthorize("@pms.hasPermission('shop:shopDetail:info')")
public ServerResponseEntity<ShopDetail> info(){
ShopDetail shopDetail = shopDetailService.getShopDetailByShopId(SecurityUtils.getSysUser().getShopId());
return ServerResponseEntity.success(shopDetail);
}
/**
*
*/
/**
*
* isDistributionShopDetailIDSecurityUtilsID
* ShopDetailServiceupdateByIdremoveShopDetailCacheByShopIdID
* ServerResponseEntityVoid
*
* @param isDistribution 01
* @return ServerResponseEntityVoid
*/
@PutMapping("/isDistribution")
public ServerResponseEntity<Void> updateIsDistribution(@RequestParam Integer isDistribution) {
ShopDetail shopDetail = new ShopDetail();
shopDetail.setShopId(SecurityUtils.getSysUser().getShopId());
shopDetail.setIsDistribution(isDistribution);
shopDetailService.updateById(shopDetail);
// 更新完成后删除缓存
shopDetailService.removeShopDetailCacheByShopId(shopDetail.getShopId());
return ServerResponseEntity.success();
}
/**
*
* SecurityUtilsIDShopDetailServicegetShopDetailByShopId
* ServerResponseEntity
*
* @return ServerResponseEntityShopDetail
*/
@GetMapping("/info")
@PreAuthorize("@pms.hasPermission('shop:shopDetail:info')")
public ServerResponseEntity<ShopDetail> info() {
ShopDetail shopDetail = shopDetailService.getShopDetailByShopId(SecurityUtils.getSysUser().getShopId());
return ServerResponseEntity.success(shopDetail);
}
/**
*
* ShopDetailPageParam
* 使ShopDetailServicepageLambdaQueryWrapper
* IDServerResponseEntity
*
* @param shopDetail
* @param page
* @return ServerResponseEntityIPage<ShopDetail>
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('shop:shopDetail:page')")
public ServerResponseEntity<IPage<ShopDetail>> page(ShopDetail shopDetail,PageParam<ShopDetail> page){
IPage<ShopDetail> shopDetails = shopDetailService.page(page,
new LambdaQueryWrapper<ShopDetail>()
.like(StrUtil.isNotBlank(shopDetail.getShopName()),ShopDetail::getShopName,shopDetail.getShopName())
.orderByDesc(ShopDetail::getShopId));
return ServerResponseEntity.success(shopDetails);
}
/**
*
*/
@GetMapping("/info/{shopId}")
@PreAuthorize("@pms.hasPermission('shop:shopDetail:info')")
public ServerResponseEntity<ShopDetail> info(@PathVariable("shopId") Long shopId){
ShopDetail shopDetail = shopDetailService.getShopDetailByShopId(shopId);
// 店铺图片
return ServerResponseEntity.success(shopDetail);
}
/**
*
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('shop:shopDetail:save')")
public ServerResponseEntity<Void> save(@Valid ShopDetailParam shopDetailParam){
ShopDetail shopDetail = BeanUtil.copyProperties(shopDetailParam, ShopDetail.class);
shopDetail.setCreateTime(new Date());
shopDetail.setShopStatus(1);
shopDetailService.save(shopDetail);
return ServerResponseEntity.success();
}
/**
*
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('shop:shopDetail:update')")
public ServerResponseEntity<Void> update(@Valid ShopDetailParam shopDetailParam){
ShopDetail daShopDetail = shopDetailService.getShopDetailByShopId(shopDetailParam.getShopId());
ShopDetail shopDetail = BeanUtil.copyProperties(shopDetailParam, ShopDetail.class);
shopDetail.setUpdateTime(new Date());
shopDetailService.updateShopDetail(shopDetail,daShopDetail);
return ServerResponseEntity.success();
}
/**
*
*/
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('shop:shopDetail:delete')")
public ServerResponseEntity<Void> delete(@PathVariable Long id){
shopDetailService.deleteShopDetailByShopId(id);
return ServerResponseEntity.success();
}
/**
*
*/
@PutMapping("/shopStatus")
@PreAuthorize("@pms.hasPermission('shop:shopDetail:shopStatus')")
public ServerResponseEntity<Void> shopStatus(@RequestParam Long shopId,@RequestParam Integer shopStatus){
ShopDetail shopDetail = new ShopDetail();
shopDetail.setShopId(shopId);
shopDetail.setShopStatus(shopStatus);
shopDetailService.updateById(shopDetail);
// 更新完成后删除缓存
shopDetailService.removeShopDetailCacheByShopId(shopDetail.getShopId());
return ServerResponseEntity.success();
}
/**
*
*/
@PreAuthorize("@pms.hasPermission('shop:shopDetail:page')")
public ServerResponseEntity<IPage<ShopDetail>> page(ShopDetail shopDetail, PageParam<ShopDetail> page) {
IPage<ShopDetail> shopDetails = shopDetailService.page(page,
new LambdaQueryWrapper<ShopDetail>()
.like(StrUtil.isNotBlank(shopDetail.getShopName()), ShopDetail::getShopName, shopDetail.getShopName())
.orderByDesc(ShopDetail::getShopId));
return ServerResponseEntity.success(shopDetails);
}
/**
* ID
* IDShopDetailServicegetShopDetailByShopId
* ServerResponseEntity
*
* @param shopId ID
* @return ServerResponseEntityShopDetail
*/
@GetMapping("/info/{shopId}")
@PreAuthorize("@pms.hasPermission('shop:shopDetail:info')")
public ServerResponseEntity<ShopDetail> info(@PathVariable("shopId") Long shopId) {
ShopDetail shopDetail = shopDetailService.getShopDetailByShopId(shopId);
// 店铺图片(此处可根据实际业务需求进一步处理店铺图片相关逻辑,目前只是简单返回店铺详情对象)
return ServerResponseEntity.success(shopDetail);
}
/**
*
* ShopDetailParamBeanUtilShopDetail
* new Date()1
* ShopDetailServicesaveServerResponseEntityVoid
*
* @param shopDetailParam
* @return ServerResponseEntityVoid
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('shop:shopDetail:save')")
public ServerResponseEntity<Void> save(@Valid ShopDetailParam shopDetailParam) {
ShopDetail shopDetail = BeanUtil.copyProperties(shopDetailParam, ShopDetail.class);
shopDetail.setCreateTime(new Date());
shopDetail.setShopStatus(1);
shopDetailService.save(shopDetail);
return ServerResponseEntity.success();
}
/**
*
* ShopDetailServicegetShopDetailByShopIdShopDetailParamIDdaShopDetail
* ShopDetailParamBeanUtilShopDetailnew Date()
* ShopDetailServiceupdateShopDetail
* ServerResponseEntityVoid
*
* @param shopDetailParam
* @return ServerResponseEntityVoid
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('shop:shopDetail:update')")
public ServerResponseEntity<Void> update(@Valid ShopDetailParam shopDetailParam) {
ShopDetail daShopDetail = shopDetailService.getShopDetailByShopId(shopDetailParam.getShopId());
ShopDetail shopDetail = BeanUtil.copyProperties(shopDetailParam, ShopDetail.class);
shopDetail.setUpdateTime(new Date());
shopDetailService.updateShopDetail(shopDetail, daShopDetail);
return ServerResponseEntity.success();
}
/**
* ID
* IDShopDetailServicedeleteShopDetailByShopId
* ServerResponseEntityVoid
*
* @param id ID
* @return ServerResponseEntityVoid
*/
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('shop:shopDetail:delete')")
public ServerResponseEntity<Void> delete(@PathVariable Long id) {
shopDetailService.deleteShopDetailByShopId(id);
return ServerResponseEntity.success();
}
/**
*
* IDshopIdshopStatusShopDetailID
* ShopDetailServiceupdateByIdremoveShopDetailCacheByShopIdID
* ServerResponseEntityVoid
*
* @param shopId ID
* @param shopStatus
* @return ServerResponseEntityVoid
*/
@PutMapping("/shopStatus")
@PreAuthorize("@pms.hasPermission('shop:shopDetail:shopStatus')")
public ServerResponseEntity<Void> shopStatus(@RequestParam Long shopId, @RequestParam Integer shopStatus) {
ShopDetail shopDetail = new ShopDetail();
shopDetail.setShopId(shopId);
shopDetail.setShopStatus(shopStatus);
shopDetailService.updateById(shopDetail);
// 更新完成后删除缓存
shopDetailService.removeShopDetailCacheByShopId(shopDetail.getShopId());
return ServerResponseEntity.success();
}
/**
*
* ShopDetailServicelistJava 8Stream
* IDShopDetail
* ServerResponseEntity
*
* @return ServerResponseEntityList<ShopDetail>ShopDetailID
*/
@GetMapping("/listShopName")
public ServerResponseEntity<List<ShopDetail>> listShopName(){
List<ShopDetail> list = shopDetailService.list().stream().map((dbShopDetail) ->{
ShopDetail shopDetail = new ShopDetail();
shopDetail.setShopId(dbShopDetail.getShopId());
shopDetail.setShopName(dbShopDetail.getShopName());
return shopDetail;
}).collect(Collectors.toList());
return ServerResponseEntity.success(list);
}
}
public ServerResponseEntity<List<ShopDetail>> listShopName() {
List<ShopDetail> list = shopDetailService.list().stream().map((dbShopDetail) -> {
ShopDetail shopDetail = new ShopDetail();
shopDetail.setShopId(dbShopDetail.getShopId());
shopDetail.setShopName(dbShopDetail.getShopName());
return shopDetail;
}).collect(Collectors.toList());
return ServerResponseEntity.success(list);
}
}
Loading…
Cancel
Save