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,26 +31,33 @@ 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
* ServerResponseEntityVoid
*
* @param isDistribution 01
* @return ServerResponseEntityVoid
*/ */
@PutMapping("/isDistribution") @PutMapping("/isDistribution")
public ServerResponseEntity<Void> updateIsDistribution(@RequestParam Integer isDistribution){ public ServerResponseEntity<Void> updateIsDistribution(@RequestParam Integer isDistribution) {
ShopDetail shopDetail=new ShopDetail(); ShopDetail shopDetail = new ShopDetail();
shopDetail.setShopId(SecurityUtils.getSysUser().getShopId()); shopDetail.setShopId(SecurityUtils.getSysUser().getShopId());
shopDetail.setIsDistribution(isDistribution); shopDetail.setIsDistribution(isDistribution);
shopDetailService.updateById(shopDetail); shopDetailService.updateById(shopDetail);
@ -57,47 +65,69 @@ public class ShopDetailController {
shopDetailService.removeShopDetailCacheByShopId(shopDetail.getShopId()); shopDetailService.removeShopDetailCacheByShopId(shopDetail.getShopId());
return ServerResponseEntity.success(); return ServerResponseEntity.success();
} }
/** /**
* *
* SecurityUtilsIDShopDetailServicegetShopDetailByShopId
* ServerResponseEntity
*
* @return ServerResponseEntityShopDetail
*/ */
@GetMapping("/info") @GetMapping("/info")
@PreAuthorize("@pms.hasPermission('shop:shopDetail:info')") @PreAuthorize("@pms.hasPermission('shop:shopDetail:info')")
public ServerResponseEntity<ShopDetail> info(){ public ServerResponseEntity<ShopDetail> info() {
ShopDetail shopDetail = shopDetailService.getShopDetailByShopId(SecurityUtils.getSysUser().getShopId()); ShopDetail shopDetail = shopDetailService.getShopDetailByShopId(SecurityUtils.getSysUser().getShopId());
return ServerResponseEntity.success(shopDetail); 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
* ServerResponseEntity
*
* @param shopId ID
* @return ServerResponseEntityShopDetail
*/ */
@GetMapping("/info/{shopId}") @GetMapping("/info/{shopId}")
@PreAuthorize("@pms.hasPermission('shop:shopDetail:info')") @PreAuthorize("@pms.hasPermission('shop:shopDetail:info')")
public ServerResponseEntity<ShopDetail> info(@PathVariable("shopId") Long shopId){ public ServerResponseEntity<ShopDetail> info(@PathVariable("shopId") Long shopId) {
ShopDetail shopDetail = shopDetailService.getShopDetailByShopId(shopId); ShopDetail shopDetail = shopDetailService.getShopDetailByShopId(shopId);
// 店铺图片 // 店铺图片(此处可根据实际业务需求进一步处理店铺图片相关逻辑,目前只是简单返回店铺详情对象)
return ServerResponseEntity.success(shopDetail); return ServerResponseEntity.success(shopDetail);
} }
/** /**
* *
* ShopDetailParamBeanUtilShopDetail
* new Date()1
* ShopDetailServicesaveServerResponseEntityVoid
*
* @param shopDetailParam
* @return ServerResponseEntityVoid
*/ */
@PostMapping @PostMapping
@PreAuthorize("@pms.hasPermission('shop:shopDetail:save')") @PreAuthorize("@pms.hasPermission('shop:shopDetail:save')")
public ServerResponseEntity<Void> save(@Valid ShopDetailParam shopDetailParam){ public ServerResponseEntity<Void> save(@Valid ShopDetailParam shopDetailParam) {
ShopDetail shopDetail = BeanUtil.copyProperties(shopDetailParam, ShopDetail.class); ShopDetail shopDetail = BeanUtil.copyProperties(shopDetailParam, ShopDetail.class);
shopDetail.setCreateTime(new Date()); shopDetail.setCreateTime(new Date());
shopDetail.setShopStatus(1); shopDetail.setShopStatus(1);
@ -106,34 +136,53 @@ public class ShopDetailController {
} }
/** /**
* *
* ShopDetailServicegetShopDetailByShopIdShopDetailParamIDdaShopDetail
* ShopDetailParamBeanUtilShopDetailnew Date()
* ShopDetailServiceupdateShopDetail
* ServerResponseEntityVoid
*
* @param shopDetailParam
* @return ServerResponseEntityVoid
*/ */
@PutMapping @PutMapping
@PreAuthorize("@pms.hasPermission('shop:shopDetail:update')") @PreAuthorize("@pms.hasPermission('shop:shopDetail:update')")
public ServerResponseEntity<Void> update(@Valid ShopDetailParam shopDetailParam){ public ServerResponseEntity<Void> update(@Valid ShopDetailParam shopDetailParam) {
ShopDetail daShopDetail = shopDetailService.getShopDetailByShopId(shopDetailParam.getShopId()); ShopDetail daShopDetail = shopDetailService.getShopDetailByShopId(shopDetailParam.getShopId());
ShopDetail shopDetail = BeanUtil.copyProperties(shopDetailParam, ShopDetail.class); ShopDetail shopDetail = BeanUtil.copyProperties(shopDetailParam, ShopDetail.class);
shopDetail.setUpdateTime(new Date()); shopDetail.setUpdateTime(new Date());
shopDetailService.updateShopDetail(shopDetail,daShopDetail); shopDetailService.updateShopDetail(shopDetail, daShopDetail);
return ServerResponseEntity.success(); return ServerResponseEntity.success();
} }
/** /**
* * ID
* IDShopDetailServicedeleteShopDetailByShopId
* ServerResponseEntityVoid
*
* @param id ID
* @return ServerResponseEntityVoid
*/ */
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('shop:shopDetail:delete')") @PreAuthorize("@pms.hasPermission('shop:shopDetail:delete')")
public ServerResponseEntity<Void> delete(@PathVariable Long id){ public ServerResponseEntity<Void> delete(@PathVariable Long id) {
shopDetailService.deleteShopDetailByShopId(id); shopDetailService.deleteShopDetailByShopId(id);
return ServerResponseEntity.success(); return ServerResponseEntity.success();
} }
/** /**
* *
* IDshopIdshopStatusShopDetailID
* ShopDetailServiceupdateByIdremoveShopDetailCacheByShopIdID
* ServerResponseEntityVoid
*
* @param shopId ID
* @param shopStatus
* @return ServerResponseEntityVoid
*/ */
@PutMapping("/shopStatus") @PutMapping("/shopStatus")
@PreAuthorize("@pms.hasPermission('shop:shopDetail:shopStatus')") @PreAuthorize("@pms.hasPermission('shop:shopDetail:shopStatus')")
public ServerResponseEntity<Void> shopStatus(@RequestParam Long shopId,@RequestParam Integer shopStatus){ public ServerResponseEntity<Void> shopStatus(@RequestParam Long shopId, @RequestParam Integer shopStatus) {
ShopDetail shopDetail = new ShopDetail(); ShopDetail shopDetail = new ShopDetail();
shopDetail.setShopId(shopId); shopDetail.setShopId(shopId);
shopDetail.setShopStatus(shopStatus); shopDetail.setShopStatus(shopStatus);
@ -143,13 +192,17 @@ public class ShopDetailController {
return ServerResponseEntity.success(); 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());

Loading…
Cancel
Save