From f667a9f02c3471a78e2ace4af2d94d7c713a153e Mon Sep 17 00:00:00 2001 From: liuyingfang <1357764963@qq.com> Date: Wed, 28 Feb 2024 18:22:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=94=AF=E4=BB=98=E7=9B=B8?= =?UTF-8?q?=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/payType/domain/PayTypeEnum.java | 31 +++++++++++++++++++ .../modules/payType/domain/TbShopPayType.java | 2 +- .../payType/rest/TbShopPayTypeController.java | 5 --- .../impl/TbShopPayTypeServiceImpl.java | 30 +++++++++++++++--- .../service/impl/TbShopInfoServiceImpl.java | 6 +++- .../domain/TbMerchantThirdApply.java | 1 - .../TbMerchantThirdApplyRepository.java | 17 +++++----- .../rest/TbMerchantThirdApplyController.java | 6 ++-- .../impl/TbMerchantThirdApplyServiceImpl.java | 16 +++++++--- 9 files changed, 86 insertions(+), 28 deletions(-) create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/payType/domain/PayTypeEnum.java diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/payType/domain/PayTypeEnum.java b/eladmin-system/src/main/java/me/zhengjie/modules/payType/domain/PayTypeEnum.java new file mode 100644 index 00000000..285839f6 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/payType/domain/PayTypeEnum.java @@ -0,0 +1,31 @@ +package me.zhengjie.modules.payType.domain; + +import com.alipay.service.schema.util.StringUtil; +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @author lyf + */ +@Getter +@AllArgsConstructor +public enum PayTypeEnum { + CASH("cash","现金"),BANK("bank","银行卡"),SCANCODE("scanCode","扫码支付"), + DEPOSIT("deposit","储值"),ARREARS("arrears","挂单"); + + private String type; + + private String name; + + + + public static String getNameByType(String name) { + PayTypeEnum[] operateTypes = values(); + for (PayTypeEnum ot : operateTypes) { + if (ot.name.equals(name)) { + return ot.getType(); + } + } + return ""; + } +} diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/payType/domain/TbShopPayType.java b/eladmin-system/src/main/java/me/zhengjie/modules/payType/domain/TbShopPayType.java index 3d2250c4..18ece752 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/payType/domain/TbShopPayType.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/payType/domain/TbShopPayType.java @@ -20,7 +20,6 @@ import cn.hutool.core.bean.BeanUtil; import io.swagger.annotations.ApiModelProperty; import cn.hutool.core.bean.copier.CopyOptions; import javax.persistence.*; -import javax.validation.constraints.*; import java.io.Serializable; /** @@ -37,6 +36,7 @@ public class TbShopPayType implements Serializable { @Id @Column(name = "`id`") @ApiModelProperty(value = "自增id") + @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; @Column(name = "`pay_type`") diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/payType/rest/TbShopPayTypeController.java b/eladmin-system/src/main/java/me/zhengjie/modules/payType/rest/TbShopPayTypeController.java index 7cf95517..2cc0ad12 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/payType/rest/TbShopPayTypeController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/payType/rest/TbShopPayTypeController.java @@ -46,7 +46,6 @@ public class TbShopPayTypeController { @Log("导出数据") @ApiOperation("导出数据") @GetMapping(value = "/download") - @PreAuthorize("@el.check('tbShopPayType:list')") public void exportTbShopPayType(HttpServletResponse response, TbShopPayTypeQueryCriteria criteria) throws IOException { tbShopPayTypeService.download(tbShopPayTypeService.queryAll(criteria), response); } @@ -54,7 +53,6 @@ public class TbShopPayTypeController { @GetMapping @Log("查询/merchant/system/paytype") @ApiOperation("查询/merchant/system/paytype") - @PreAuthorize("@el.check('tbShopPayType:list')") public ResponseEntity queryTbShopPayType(TbShopPayTypeQueryCriteria criteria, Pageable pageable){ return new ResponseEntity<>(tbShopPayTypeService.queryAll(criteria,pageable),HttpStatus.OK); } @@ -62,7 +60,6 @@ public class TbShopPayTypeController { @PostMapping @Log("新增/merchant/system/paytype") @ApiOperation("新增/merchant/system/paytype") - @PreAuthorize("@el.check('tbShopPayType:add')") public ResponseEntity createTbShopPayType(@Validated @RequestBody TbShopPayType resources){ return new ResponseEntity<>(tbShopPayTypeService.create(resources),HttpStatus.CREATED); } @@ -70,7 +67,6 @@ public class TbShopPayTypeController { @PutMapping @Log("修改/merchant/system/paytype") @ApiOperation("修改/merchant/system/paytype") - @PreAuthorize("@el.check('tbShopPayType:edit')") public ResponseEntity updateTbShopPayType(@Validated @RequestBody TbShopPayType resources){ tbShopPayTypeService.update(resources); return new ResponseEntity<>(HttpStatus.NO_CONTENT); @@ -79,7 +75,6 @@ public class TbShopPayTypeController { @DeleteMapping @Log("删除/merchant/system/paytype") @ApiOperation("删除/merchant/system/paytype") - @PreAuthorize("@el.check('tbShopPayType:del')") public ResponseEntity deleteTbShopPayType(@RequestBody Integer[] ids) { tbShopPayTypeService.deleteAll(ids); return new ResponseEntity<>(HttpStatus.OK); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/payType/service/impl/TbShopPayTypeServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/payType/service/impl/TbShopPayTypeServiceImpl.java index 868871bb..688f8b56 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/payType/service/impl/TbShopPayTypeServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/payType/service/impl/TbShopPayTypeServiceImpl.java @@ -15,21 +15,25 @@ */ package me.zhengjie.modules.payType.service.impl; +import me.zhengjie.exception.BadRequestException; +import me.zhengjie.modules.payType.domain.PayTypeEnum; +import me.zhengjie.modules.payType.repository.TbShopPayTypeRepository; +import me.zhengjie.modules.payType.service.dto.TbShopPayTypeDto; +import me.zhengjie.modules.payType.service.dto.TbShopPayTypeQueryCriteria; +import me.zhengjie.modules.payType.service.mapstruct.TbShopPayTypeMapper; import me.zhengjie.modules.payType.domain.TbShopPayType; import me.zhengjie.utils.ValidationUtil; import me.zhengjie.utils.FileUtil; import lombok.RequiredArgsConstructor; -import me.zhengjie.modules.payType.repository.TbShopPayTypeRepository; import me.zhengjie.modules.payType.service.TbShopPayTypeService; -import me.zhengjie.modules.payType.service.dto.TbShopPayTypeDto; -import me.zhengjie.modules.payType.service.dto.TbShopPayTypeQueryCriteria; -import me.zhengjie.modules.payType.service.mapstruct.TbShopPayTypeMapper; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import me.zhengjie.utils.PageUtil; import me.zhengjie.utils.QueryHelp; + +import java.time.Instant; import java.util.List; import java.util.Map; import java.io.IOException; @@ -72,13 +76,31 @@ public class TbShopPayTypeServiceImpl implements TbShopPayTypeService { @Override @Transactional(rollbackFor = Exception.class) public TbShopPayTypeDto create(TbShopPayType resources) { + if (resources.getPayName() == null || "".equals(resources.getPayName())){ + throw new BadRequestException("付款方式不能为空"); + } + //类型转换 + String nameByType = PayTypeEnum.getNameByType(resources.getPayName()); + resources.setPayType(nameByType); + resources.setIsRefundable(0); + resources.setIsShowShortcut(1); + resources.setIsSystem(0); + resources.setCreatedAt(Instant.now().toEpochMilli()); + resources.setUpdatedAt(Instant.now().toEpochMilli()); return tbShopPayTypeMapper.toDto(tbShopPayTypeRepository.save(resources)); } @Override @Transactional(rollbackFor = Exception.class) public void update(TbShopPayType resources) { + if (resources.getPayName() == null || "".equals(resources.getPayName())){ + throw new BadRequestException("付款方式不能为空"); + } TbShopPayType tbShopPayType = tbShopPayTypeRepository.findById(resources.getId()).orElseGet(TbShopPayType::new); + //类型转换 + String nameByType = PayTypeEnum.getNameByType(resources.getPayName()); + resources.setPayType(nameByType); + resources.setUpdatedAt(Instant.now().toEpochMilli()); ValidationUtil.isNull( tbShopPayType.getId(),"TbShopPayType","id",resources.getId()); tbShopPayType.copy(resources); tbShopPayTypeRepository.save(tbShopPayType); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shop/service/impl/TbShopInfoServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shop/service/impl/TbShopInfoServiceImpl.java index 8f450704..f97e111e 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shop/service/impl/TbShopInfoServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shop/service/impl/TbShopInfoServiceImpl.java @@ -138,7 +138,11 @@ public class TbShopInfoServiceImpl implements TbShopInfoService { tbMerchantAccount.setIsMercantile(0); tbMerchantAccount.setStatus(1); tbMerchantAccount.setMsgAble(0); - merchantAccountRepository.save(tbMerchantAccount); + TbMerchantAccount save1 = merchantAccountRepository.save(tbMerchantAccount); + //绑定accountId + tbShopInfo.setMerchantId(String.valueOf(save1.getId())); + tbShopInfoRepository.save(tbShopInfo); + //添加收银系统后台账号 User user = new User(); user.setPassword(passwordEncoder.encode(resources.getPassword())); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopThirdApply/domain/TbMerchantThirdApply.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopThirdApply/domain/TbMerchantThirdApply.java index cabc2780..b808e5fc 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopThirdApply/domain/TbMerchantThirdApply.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopThirdApply/domain/TbMerchantThirdApply.java @@ -35,7 +35,6 @@ import java.io.Serializable; public class TbMerchantThirdApply implements Serializable { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "`id`") @ApiModelProperty(value = "自增id") private Integer id; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopThirdApply/repository/TbMerchantThirdApplyRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopThirdApply/repository/TbMerchantThirdApplyRepository.java index d1ec52fb..a884796f 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopThirdApply/repository/TbMerchantThirdApplyRepository.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopThirdApply/repository/TbMerchantThirdApplyRepository.java @@ -27,13 +27,14 @@ import org.springframework.data.jpa.repository.Query; * @date 2024-02-02 **/ public interface TbMerchantThirdApplyRepository extends JpaRepository, JpaSpecificationExecutor { - /** - * 根据 AppId 查询 - * @param app_id / - * @return / - */ - TbMerchantThirdApply findByAppId(String app_id); - @Query("select thirdApply from TbMerchantThirdApply thirdApply where thirdApply.shopId = :shopId") - TbMerchantThirdApply findByShopId(@Param("shopId") Integer shopId); + + @Query("select thirdApply from TbMerchantThirdApply thirdApply where thirdApply.id = :id") + TbMerchantThirdApply findByShopId(@Param("id") Integer id); + /** + * 根据 AppId 查询 + * @return / + */ + @Query("select thirdApply from TbMerchantThirdApply thirdApply where thirdApply.appId = :appId") + TbMerchantThirdApply findByAppId(@Param("appId") String appId); } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopThirdApply/rest/TbMerchantThirdApplyController.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopThirdApply/rest/TbMerchantThirdApplyController.java index 50bec276..a81b7c94 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopThirdApply/rest/TbMerchantThirdApplyController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopThirdApply/rest/TbMerchantThirdApplyController.java @@ -60,9 +60,9 @@ public class TbMerchantThirdApplyController { return new ResponseEntity<>(tbMerchantThirdApplyService.queryAll(criteria,pageable),HttpStatus.OK); } - @GetMapping("/{shopId}") - public ResponseEntity queryTbMerchantThirdApply(@PathVariable Integer shopId){ - TbMerchantThirdApplyDto byShopId = tbMerchantThirdApplyService.findByShopId(shopId); + @GetMapping("/{merchantId}") + public ResponseEntity queryTbMerchantThirdApply(@PathVariable Integer merchantId){ + TbMerchantThirdApplyDto byShopId = tbMerchantThirdApplyService.findByShopId(merchantId); if (byShopId == null){ return new ResponseEntity<>(new TbMerchantThirdApplyDto(),HttpStatus.OK); } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopThirdApply/service/impl/TbMerchantThirdApplyServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopThirdApply/service/impl/TbMerchantThirdApplyServiceImpl.java index 37d9d5d3..7639e6f6 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopThirdApply/service/impl/TbMerchantThirdApplyServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopInfo/shopThirdApply/service/impl/TbMerchantThirdApplyServiceImpl.java @@ -90,11 +90,17 @@ public class TbMerchantThirdApplyServiceImpl implements TbMerchantThirdApplyServ @Override @Transactional(rollbackFor = Exception.class) public void update(TbMerchantThirdApply resources) { - TbMerchantThirdApply tbMerchantThirdApply = tbMerchantThirdApplyRepository.findById(resources.getId()).orElseGet(TbMerchantThirdApply::new); - ValidationUtil.isNull( tbMerchantThirdApply.getId(),"TbMerchantThirdApply","id",resources.getId()); - tbMerchantThirdApply.setUpdatedAt(Instant.now().toEpochMilli()); - tbMerchantThirdApply.copy(resources); - tbMerchantThirdApplyRepository.saveAndFlush(tbMerchantThirdApply); + TbMerchantThirdApply tbMerchantThirdApply = tbMerchantThirdApplyRepository.findByShopId(resources.getId()); + if (tbMerchantThirdApply == null){ + resources.setCreatedAt(Instant.now().toEpochMilli()); + resources.setCreatedAt(Instant.now().toEpochMilli()); + tbMerchantThirdApplyRepository.save(resources); + }else { + ValidationUtil.isNull(tbMerchantThirdApply.getId(), "TbMerchantThirdApply", "id", resources.getId()); + tbMerchantThirdApply.setUpdatedAt(Instant.now().toEpochMilli()); + tbMerchantThirdApply.copy(resources); + tbMerchantThirdApplyRepository.saveAndFlush(tbMerchantThirdApply); + } } @Override