Update ShopDetailController.java

cyj
pbvfus8to 8 months ago
parent 74e503e1c9
commit adff03961d

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