Update IndexImgController.java

cyj
pbvfus8to 8 months ago
parent 30892c41db
commit 641c9fe7a6

@ -29,42 +29,64 @@ import java.util.Date;
import java.util.Objects;
/**
* IndexImg
*
*
*
* @author lgh on 2018/11/26.
*/
@RestController
@RequestMapping("/admin/indexImg")
public class IndexImgController {
// 注入IndexImgService用于处理与首页图片相关的业务逻辑例如图片信息的查询、保存、更新、删除等操作。
@Autowired
private IndexImgService indexImgService;
// 注入ProductService用于获取商品相关信息在涉及首页图片与商品关联的业务逻辑中会用到比如校验商品状态等情况。
@Autowired
private ProductService productService;
/**
*
* IndexImgPageParam
* IndexImgService
* @PreAuthorize"admin:indexImg:page"访
*
* @param indexImg IndexImg
* @param page
* @return ServerResponseEntity
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('admin:indexImg:page')")
public ServerResponseEntity<IPage<IndexImg>> page(IndexImg indexImg, PageParam<IndexImg> page) {
// 使用IndexImgService的page方法进行分页查询传入分页参数和LambdaQueryWrapper构建的查询条件
// 根据传入的indexImg对象的状态是否不为空来决定是否添加状态筛选条件同时按照顺序排序。
IPage<IndexImg> indexImgPage = indexImgService.page(page,
new LambdaQueryWrapper<IndexImg>()
.eq(indexImg.getStatus() != null, IndexImg::getStatus, indexImg.getStatus())
.orderByAsc(IndexImg::getSeq));
.eq(indexImg.getStatus()!= null, IndexImg::getStatus, indexImg.getStatus())
.orderByAsc(IndexImg::getSeq));
return ServerResponseEntity.success(indexImgPage);
}
/**
*
* IDIDID
* IndexImgService
*
* @PreAuthorize"admin:indexImg:info"访
*
* @param imgId
* @return ServerResponseEntity
*/
@GetMapping("/info/{imgId}")
@PreAuthorize("@pms.hasPermission('admin:indexImg:info')")
public ServerResponseEntity<IndexImg> info(@PathVariable("imgId") Long imgId) {
Long shopId = SecurityUtils.getSysUser().getShopId();
// 通过IndexImgService根据店铺ID和图片ID查询对应的首页图片对象使用LambdaQueryWrapper构建查询条件。
IndexImg indexImg = indexImgService.getOne(new LambdaQueryWrapper<IndexImg>().eq(IndexImg::getShopId, shopId).eq(IndexImg::getImgId, imgId));
if (Objects.nonNull(indexImg.getRelation())) {
// 若图片存在关联商品通过relation属性判断则通过ProductService根据商品ID获取商品对象。
Product product = productService.getProductByProdId(indexImg.getRelation());
// 将商品的图片和商品名称设置到首页图片对象的相应属性中,方便前端展示关联商品的相关信息。
indexImg.setPic(product.getPic());
indexImg.setProdName(product.getProdName());
}
@ -72,7 +94,13 @@ public class IndexImgController {
}
/**
*
* @ValidIndexImg
* IDIDcheckProdStatus
* IndexImgServicesave
* @PreAuthorize"admin:indexImg:save"访
*
* @param indexImg
* @return ServerResponseEntityVoid
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('admin:indexImg:save')")
@ -87,7 +115,13 @@ public class IndexImgController {
}
/**
*
* @ValidIndexImg
* checkProdStatusIndexImgServicesaveOrUpdate
*
* @PreAuthorize"admin:indexImg:update"访
*
* @param indexImg
* @return ServerResponseEntityVoid
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('admin:indexImg:update')")
@ -99,7 +133,12 @@ public class IndexImgController {
}
/**
*
* IDIndexImgServicedeleteIndexImgByIds
* ID
* @PreAuthorize"admin:indexImg:delete"访
*
* @param ids ID
* @return ServerResponseEntityVoid
*/
@DeleteMapping
@PreAuthorize("@pms.hasPermission('admin:indexImg:delete')")
@ -109,6 +148,13 @@ public class IndexImgController {
return ServerResponseEntity.success();
}
/**
* 0
* IDID
* 1
*
* @param indexImg ID
*/
private void checkProdStatus(IndexImg indexImg) {
if (!Objects.equals(indexImg.getType(), 0)) {
return;
@ -124,4 +170,4 @@ public class IndexImgController {
throw new YamiShopBindException("该商品未上架,请选择别的商品");
}
}
}
}
Loading…
Cancel
Save