package com.oying.modules.pc.store.rest; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.copier.CopyOptions; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ObjectUtil; import com.oying.exception.BadRequestException; import com.oying.modules.pc.store.domain.Store; import com.oying.modules.pc.store.domain.dto.*; import com.oying.modules.pc.store.domain.enums.StoreStatusEnum; import com.oying.modules.pc.store.service.*; import com.oying.modules.pc.store.view.StoreMerchantView; import com.oying.modules.pc.store.view.StoreSimpleView; import com.oying.utils.R; import com.oying.utils.SecurityUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; /** * 店铺 * * @author lzp * @date 2025-04-22 */ @Api(tags = "店铺(商户端)") @RestController @RequiredArgsConstructor @RequestMapping("/api/pc/merchant/store") public class StoreMerchantController { private final StoreService storeService; private final StoreCreateService storeCreateService; private final StoreQualificationService storeQualificationService; private final StoreQueryService storeQueryService; private final StoreMerchantService storeMerchantService; @GetMapping(value = "/list") @ApiOperation("查询所有店铺") //@PreAuthorize("@el.check('merchant:store:list')") public ResponseEntity getList() { List stores = Optional.ofNullable(storeService.getUserStores(SecurityUtils.getCurrentUserId())).orElse(ListUtil.empty()); return ResponseEntity.ok(R.success(stores)); } @GetMapping(value = "/simple-list") @ApiOperation("查询所有店铺") //@PreAuthorize("@el.check('merchant:store:list')") public ResponseEntity getSimpleStores() { List stores = Optional.ofNullable(storeService.getUserStores(SecurityUtils.getCurrentUserId())).orElse(ListUtil.empty()); List storeViewList = stores.stream().map(i -> { StoreSimpleView view = new StoreSimpleView(); BeanUtil.copyProperties(i, view, CopyOptions.create().setIgnoreNullValue(true)); return view; }).collect(Collectors.toList()); return ResponseEntity.ok(R.success(storeViewList)); } @GetMapping(value = "/{storeId}") @ApiOperation("查询店铺") //@PreAuthorize("@el.check('merchant:store:getById')") public ResponseEntity getStoreById(@PathVariable Long storeId) { Store store = storeService.getById(storeId); StoreMerchantView view = new StoreMerchantView(); BeanUtils.copyProperties(store, view); return ResponseEntity.ok(R.success(view)); } @GetMapping(value = "/{storeId}/details") @ApiOperation("查询店铺") //@PreAuthorize("@el.check('merchant:store:getById')") public ResponseEntity getStoreDetailsById(@PathVariable Long storeId) { Store store = storeService.getById(storeId); if (ObjUtil.isNotEmpty(store)) { store.setQualifications(storeQualificationService.getByStoreId(storeId)); } return ResponseEntity.ok(R.success(store)); } @PostMapping @ApiOperation("创建店铺") //@PreAuthorize("@el.check('merchant:store:create')") public ResponseEntity create(@RequestBody StoreCreateRequest request) { return ResponseEntity.status(HttpStatus.CREATED).body(storeMerchantService.createStore(request)); } @PostMapping(value = "/{storeId}/audit/submit") @ApiOperation("提交审核") //@PreAuthorize("@el.check('merchant:store:create')") public ResponseEntity submitAudit(@PathVariable Long storeId) { storeMerchantService.submitStoreAudit(storeId); return ResponseEntity.noContent().build(); } /** * 修改店铺信息 */ @PutMapping(value = "/{storeId}") @ApiOperation("修改店铺") //@PreAuthorize("@el.check('merchant:store:update')" + // " and @storeMerchantOwnershipService.check(#storeId)") public ResponseEntity update(@PathVariable("storeId") Long storeId, @RequestBody StoreUpdateRequest request) { request.setStoreId(ObjectUtil.defaultIfNull(request.getStoreId(), storeId)); storeMerchantService.updateStore(request); return ResponseEntity.noContent().build(); } /** * 修改店铺LOGO */ @PatchMapping(value = "/{storeId}/logo") @ApiOperation("修改店铺LOGO") //@PreAuthorize("@el.check('merchant:store:list')" + // " and @storeMerchantOwnershipService.check(#storeId)") public ResponseEntity updateLogo(@PathVariable("storeId") Long storeId, @Validated(value = StoreFieldUpdateRequest.UpdateStoreLogoImageGroup.class) @RequestBody StoreFieldUpdateRequest request) { Long logeImageId = Optional.ofNullable(request.getLogoImageId()).orElse(Long.getLong(request.getLogoImageUploadId())); storeService.updateLogo(storeId, logeImageId, request.getVersion()); return ResponseEntity.noContent().build(); } /** * 修改店铺名称 */ @PatchMapping(value = "/{storeId}/name") @ApiOperation("修改店铺名称") //@PreAuthorize("@el.check('merchant:store:name')" + // " and @storeMerchantOwnershipService.check(#storeId)") public ResponseEntity updateName(@PathVariable("storeId") Long storeId, @Validated(value = StoreFieldUpdateRequest.UpdateStoreNameGroup.class) @RequestBody StoreFieldUpdateRequest request) { StoreUpdateRequest updateRequest = new StoreUpdateRequest(); updateRequest.setStoreId(storeId); updateRequest.setStoreName(request.getStoreName()); storeMerchantService.updateStore(updateRequest); //storeMerchantService.saveRevisionStore(request, StoreRevisionTypeEnum.NAME_UPDATE); return ResponseEntity.noContent().build(); } /** * 修改店铺简介 */ @PatchMapping(value = "/{storeId}/description") @ApiOperation("修改店铺简介") //@PreAuthorize("@el.check('merchant:store:description')" + // " and @storeMerchantOwnershipService.check(#storeId)") public ResponseEntity updateDescription(@PathVariable("storeId") Long storeId, @Validated(value = StoreFieldUpdateRequest.UpdateStoreDescriptionGroup.class) @RequestBody StoreFieldUpdateRequest request) { storeService.updateDescription(storeId, request.getDescription(), request.getVersion()); return ResponseEntity.noContent().build(); } /** * 修改店铺联系电话 */ @PatchMapping(value = "/{storeId}/contactPhone") @ApiOperation("修改店铺联系电话") /*@PreAuthorize("@el.check('merchant:store:list')" + " and @storeMerchantOwnershipService.check(#storeId)")*/ public ResponseEntity updateContactPhone(@PathVariable("storeId") Long storeId, @Validated(value = StoreFieldUpdateRequest.UpdateStoreContactPhoneGroup.class) @RequestBody StoreFieldUpdateRequest request) { storeService.updateContactPhone(storeId, request.getContactPhone(), request.getVersion()); return ResponseEntity.noContent().build(); } /** * 修改店铺地址 */ @PatchMapping(value = "/{storeId}/address") @ApiOperation("修改店铺地址") /*@PreAuthorize("@el.check('merchant:store:address')" + " and @storeMerchantOwnershipService.check(#storeId)")*/ public ResponseEntity updateAddress(@PathVariable("storeId") Long storeId, @Validated(value = StoreFieldUpdateRequest.UpdateStoreAddressGroup.class) @RequestBody StoreFieldUpdateRequest request) { storeService.updateAddress(storeId, request.getAddress(), request.getVersion()); return ResponseEntity.noContent().build(); } /** * 修改店铺坐标 */ @PatchMapping(value = "/{storeId}/location") @ApiOperation("修改店铺坐标") /*@PreAuthorize("@el.check('merchant:store:location')" + " and @storeMerchantOwnershipService.check(#storeId)")*/ public ResponseEntity updateLocation(@PathVariable("storeId") Long storeId, @Validated(value = StoreFieldUpdateRequest.UpdateStoreLocationGroup.class) @RequestBody StoreFieldUpdateRequest request) { storeService.updateLocation(storeId, request.getLongitude(), request.getLatitude(), request.getVersion()); return ResponseEntity.noContent().build(); } /** * 修改店铺配送范围 */ @PatchMapping(value = "/{storeId}/radius") @ApiOperation("修改店铺配送范围") /*@PreAuthorize("@el.check('merchant:store:radius')" + " and @storeMerchantOwnershipService.check(#storeId)")*/ public ResponseEntity updateRadius(@PathVariable("storeId") Long storeId, @Validated(value = StoreFieldUpdateRequest.UpdateStoreRadiusGroup.class) @RequestBody StoreFieldUpdateRequest request) { storeService.updateRadius(storeId, request.getRadius(), request.getVersion()); return ResponseEntity.noContent().build(); } /** * 修改店铺绑定的经营类目 */ @PatchMapping(value = "/{storeId}/platformCategory") @ApiOperation("修改店铺绑定的经营类目") /*@PreAuthorize("@el.check('merchant:store:platformCategory')" + " and @storeMerchantOwnershipService.check(#storeId)")*/ public ResponseEntity updatePlatformCategory(@PathVariable("storeId") Long storeId, @Validated(value = StoreFieldUpdateRequest.UpdateStorePlatformCategoryGroup.class) @RequestBody StoreFieldUpdateRequest request) { storeService.updatePlatformCategory(storeId, request.getPlatformCategoryId(), request.getVersion()); return ResponseEntity.noContent().build(); } /** * 修改店铺营业时间 */ @PatchMapping(value = "/{storeId}/businessHours") @ApiOperation("修改店铺营业时间") /*@PreAuthorize("@el.check('merchant:store:businessHours')" + " and @storeMerchantOwnershipService.check(#storeId)")*/ public ResponseEntity updateBusinessHours(@PathVariable("storeId") Long storeId, @Validated(value = StoreFieldUpdateRequest.UpdateStoreBusinessHoursGroup.class) @RequestBody StoreFieldUpdateRequest request) { storeService.updateBusinessHours(storeId, request.getOpenTime(), request.getCloseTime(), request.getVersion()); return ResponseEntity.noContent().build(); } /** * 修改起送金额 */ @PatchMapping(value = "/{storeId}/deliveryMinimum") @ApiOperation("修改起送金额") /*@PreAuthorize("@el.check('merchant:store:deliveryMinimum')" + " and @storeMerchantOwnershipService.check(#storeId)")*/ public ResponseEntity updateDeliveryMinimum(@PathVariable("storeId") Long storeId, @Validated(value = StoreFieldUpdateRequest.UpdateStoreDeliveryMinimumGroup.class) @RequestBody StoreFieldUpdateRequest request) { storeService.updateDeliveryMinimum(storeId, request.getDeliveryMinimum(), request.getVersion()); return ResponseEntity.noContent().build(); } /** * 修改配送费用 */ @PatchMapping(value = "/{storeId}/deliveryFee") @ApiOperation("修改配送费用") /*@PreAuthorize("@el.check('merchant:store:deliveryFee')" + " and @storeMerchantOwnershipService.check(#storeId)")*/ public ResponseEntity updateDeliveryFee(@PathVariable("storeId") Long storeId, @Validated(value = StoreFieldUpdateRequest.UpdateStoreDeliveryFeeGroup.class) @RequestBody StoreFieldUpdateRequest request) { storeService.updateDeliveryFee(storeId, request.getDeliveryFee(), request.getVersion()); return ResponseEntity.noContent().build(); } /** * 修改状态 */ @PatchMapping(value = "/{storeId}/businessStatus") @ApiOperation("修改营业状态") /*@PreAuthorize("@el.check('merchant:store:businessStatus')" + " and @storeMerchantOwnershipService.check(#storeId)")*/ public ResponseEntity businessStatus(@PathVariable("storeId") Long storeId, @Validated(value = StoreFieldUpdateRequest.UpdateStoreBusinessStatusGroup.class) @RequestBody StoreFieldUpdateRequest request) { //storeService.updateStatus(storeId, request.getBusinessStatus(), request.getVersion()); Store store = new Store(); store.setStoreId(storeId); store.setStatus(request.getBusinessStatus()); store.setBusinessStatus(request.getBusinessStatus()); Set statusEnumSet = CollectionUtil.newHashSet(StoreStatusEnum.OPEN.getValue(), StoreStatusEnum.CLOSED.getValue()); if (!statusEnumSet.contains(request.getBusinessStatus())) { throw new BadRequestException("状态错误"); } storeMerchantService.updateBusinessStatus(store); return ResponseEntity.noContent().build(); } }