|
|
@@ -31,8 +31,8 @@ import java.util.List;
|
|
|
@AllArgsConstructor
|
|
|
public class MerchantClassificationController extends BaseController {
|
|
|
private MerchantClassificationService merchantClassificationService;
|
|
|
- private MerchantClassificationRepo merchantClassificationRepo;
|
|
|
- private MerchantService merchantService;
|
|
|
+ private MerchantClassificationRepo merchantClassificationRepo;
|
|
|
+ private MerchantService merchantService;
|
|
|
|
|
|
//@PreAuthorize("hasRole('ADMIN')")
|
|
|
@PostMapping("/save")
|
|
|
@@ -40,9 +40,11 @@ public class MerchantClassificationController extends BaseController {
|
|
|
public MerchantClassification save(@RequestBody MerchantClassification record) {
|
|
|
//修改
|
|
|
if (record.getId() != null) {
|
|
|
- MerchantClassification orig = merchantClassificationRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
|
|
|
+ MerchantClassification orig = merchantClassificationRepo.findById(record.getId())
|
|
|
+ .orElseThrow(new BusinessException("无记录"));
|
|
|
ObjUtils.merge(orig, record);
|
|
|
- MerchantClassification byName = merchantClassificationRepo.findByMerchantIdAndName(orig.getMerchantId(), orig.getName());
|
|
|
+ MerchantClassification byName = merchantClassificationRepo.findByMerchantIdAndName(orig.getMerchantId(), orig
|
|
|
+ .getName());
|
|
|
if (ObjectUtil.isNotNull(byName)) {
|
|
|
if (!byName.getId().equals(orig.getId())) {
|
|
|
throw new BusinessException("该分类已存在");
|
|
|
@@ -50,9 +52,9 @@ public class MerchantClassificationController extends BaseController {
|
|
|
}
|
|
|
return merchantClassificationRepo.save(orig);
|
|
|
}
|
|
|
- MerchantClassification add = merchantClassificationService.add(SecurityUtils.getAuthenticatedUser().getId(), record);
|
|
|
//添加
|
|
|
- return add;
|
|
|
+ return merchantClassificationService.add(SecurityUtils.getAuthenticatedUser()
|
|
|
+ .getId(), record);
|
|
|
//return merchantClassificationRepo.save(record);
|
|
|
}
|
|
|
|
|
|
@@ -70,7 +72,8 @@ public class MerchantClassificationController extends BaseController {
|
|
|
|
|
|
@PostMapping("/del/{id}")
|
|
|
public void del(@PathVariable Long id) {
|
|
|
- MerchantClassification classification = merchantClassificationRepo.findById(id).orElseThrow(new BusinessException("无分类"));
|
|
|
+ MerchantClassification classification = merchantClassificationRepo.findById(id)
|
|
|
+ .orElseThrow(new BusinessException("无分类"));
|
|
|
if (StrUtil.isNotBlank(classification.getGoodsIds())) {
|
|
|
throw new BusinessException("该分类下有商品,暂无法删除");
|
|
|
}
|
|
|
@@ -87,7 +90,10 @@ public class MerchantClassificationController extends BaseController {
|
|
|
@GetMapping("/my")
|
|
|
@ApiOperation("商户下的分类名称")
|
|
|
public List<MerchantClassification> my() {
|
|
|
- List<MerchantClassification> merchantClassifications = merchantClassificationRepo.findAllByMerchantId(merchantService.findMerchantId(SecurityUtils.getAuthenticatedUser().getId()));
|
|
|
+ List<MerchantClassification> merchantClassifications
|
|
|
+ = merchantClassificationRepo
|
|
|
+ .findAllByMerchantId(merchantService.findMerchantId(SecurityUtils.getAuthenticatedUser()
|
|
|
+ .getId()));
|
|
|
merchantClassifications.sort(Comparator.comparing(MerchantClassification::getSort));
|
|
|
return merchantClassifications;
|
|
|
}
|
|
|
@@ -116,5 +122,14 @@ public class MerchantClassificationController extends BaseController {
|
|
|
return merchantClassificationService.showGoods(classificationId);
|
|
|
}
|
|
|
|
|
|
+ @GetMapping("/list")
|
|
|
+ @ApiOperation("商户下的分类列表")
|
|
|
+ public List<MerchantClassification> list(Long merchantId) {
|
|
|
+ List<MerchantClassification> merchantClassifications
|
|
|
+ = merchantClassificationRepo.findAllByMerchantIdAndIsShowTrueAndIsOpenTrue(merchantId);
|
|
|
+ merchantClassifications.sort(Comparator.comparing(MerchantClassification::getSort));
|
|
|
+ return merchantClassifications;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|