From 54d2e6cccbcc8ecb176d807f80f5f64cf104018f Mon Sep 17 00:00:00 2001 From: xiaoyong931011 <15274802129@163.com> Date: Wed, 24 Nov 2021 16:21:01 +0800 Subject: [PATCH] 20211124 fish --- src/main/java/com/xcong/excoin/modules/fish/service/impl/MemberCannonServiceImpl.java | 26 +++++++++++-- src/main/java/com/xcong/excoin/modules/fish/dao/CannonOwnRecordDao.java | 2 + src/main/resources/mapper/fish/CannonOwnRecordDao.xml | 4 ++ src/main/resources/mapper/fish/CannonSettingDao.xml | 4 ++ src/main/java/com/xcong/excoin/modules/fish/vo/OwnCannonVo.java | 1 src/main/java/com/xcong/excoin/modules/fish/dto/FishingDto.java | 21 ++++++++++ src/main/java/com/xcong/excoin/modules/fish/controller/MemberCannonController.java | 13 ++++-- src/main/java/com/xcong/excoin/modules/fish/service/MemberCannonService.java | 7 +-- src/main/java/com/xcong/excoin/modules/fish/dao/CannonSettingDao.java | 2 + 9 files changed, 68 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/xcong/excoin/modules/fish/controller/MemberCannonController.java b/src/main/java/com/xcong/excoin/modules/fish/controller/MemberCannonController.java index 4feb965..eb2af90 100644 --- a/src/main/java/com/xcong/excoin/modules/fish/controller/MemberCannonController.java +++ b/src/main/java/com/xcong/excoin/modules/fish/controller/MemberCannonController.java @@ -3,10 +3,7 @@ import com.xcong.excoin.common.response.Result; import com.xcong.excoin.modules.coin.parameter.vo.MemberWalletAgentInfoVo; import com.xcong.excoin.modules.coin.parameter.vo.OrderWalletCoinDealVo; -import com.xcong.excoin.modules.fish.dto.CannonExchangeDto; -import com.xcong.excoin.modules.fish.dto.CoinGoldExchangeDto; -import com.xcong.excoin.modules.fish.dto.GetCannonsDto; -import com.xcong.excoin.modules.fish.dto.GoldExchangeDto; +import com.xcong.excoin.modules.fish.dto.*; import com.xcong.excoin.modules.fish.service.MemberCannonService; import com.xcong.excoin.modules.fish.vo.CannonSettingVo; import com.xcong.excoin.modules.fish.vo.GoldAccountVo; @@ -86,5 +83,13 @@ return memberCannonService.getOwnCannon(); } + /** + * 捕鱼 + */ + @ApiOperation(value = "捕鱼") + @PostMapping(value = "/fishing") + public Result fishing(@RequestBody FishingDto fishingDto) { + return memberCannonService.fishing(fishingDto); + } } diff --git a/src/main/java/com/xcong/excoin/modules/fish/dao/CannonOwnRecordDao.java b/src/main/java/com/xcong/excoin/modules/fish/dao/CannonOwnRecordDao.java index 5f3056b..722e17b 100644 --- a/src/main/java/com/xcong/excoin/modules/fish/dao/CannonOwnRecordDao.java +++ b/src/main/java/com/xcong/excoin/modules/fish/dao/CannonOwnRecordDao.java @@ -12,4 +12,6 @@ List<CannonOwnRecord> selectCannonOwnRecordsByMemberIdAndCannonCode(@Param("memberId")Long memberId, @Param("code")String code); List<OwnCannonVo> selectCannonOwnRecordsByMemberId(@Param("memberId")Long memberId); + + List<CannonOwnRecord> selectCannonOwnRecordsByIdAndMemberId(@Param("id")Long cannonOwnId, @Param("memberId")Long memberId); } diff --git a/src/main/java/com/xcong/excoin/modules/fish/dao/CannonSettingDao.java b/src/main/java/com/xcong/excoin/modules/fish/dao/CannonSettingDao.java index 5decbb4..14894b6 100644 --- a/src/main/java/com/xcong/excoin/modules/fish/dao/CannonSettingDao.java +++ b/src/main/java/com/xcong/excoin/modules/fish/dao/CannonSettingDao.java @@ -15,4 +15,6 @@ List<CannonExchangeRatio> selectCannonExchangeRatio(); IPage<CannonSettingVo> findCannonSettingInPage(Page<CannonSettingVo> page, @Param("cannonSetting")CannonSetting cannonSetting); + + CannonSetting selectCannonSettingByCannonCode(@Param("cannonCode")String cannonCode); } diff --git a/src/main/java/com/xcong/excoin/modules/fish/dto/FishingDto.java b/src/main/java/com/xcong/excoin/modules/fish/dto/FishingDto.java new file mode 100644 index 0000000..23e9d52 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/fish/dto/FishingDto.java @@ -0,0 +1,21 @@ +package com.xcong.excoin.modules.fish.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@Data +@ApiModel(value = "FishingDto", description = "参数类") +public class FishingDto { + + + @NotNull(message = "炮塔不能为空") + @ApiModelProperty(value = "炮塔ID", example = "100") + private Long cannonOwnId; + + @ApiModelProperty(value = "获得金币", example = "100") + private Integer goldWin; + +} diff --git a/src/main/java/com/xcong/excoin/modules/fish/service/MemberCannonService.java b/src/main/java/com/xcong/excoin/modules/fish/service/MemberCannonService.java index 8c60692..207a488 100644 --- a/src/main/java/com/xcong/excoin/modules/fish/service/MemberCannonService.java +++ b/src/main/java/com/xcong/excoin/modules/fish/service/MemberCannonService.java @@ -2,10 +2,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.xcong.excoin.common.response.Result; -import com.xcong.excoin.modules.fish.dto.CannonExchangeDto; -import com.xcong.excoin.modules.fish.dto.CoinGoldExchangeDto; -import com.xcong.excoin.modules.fish.dto.GetCannonsDto; -import com.xcong.excoin.modules.fish.dto.GoldExchangeDto; +import com.xcong.excoin.modules.fish.dto.*; import com.xcong.excoin.modules.fish.entity.CannonOwnRecord; import org.apache.ibatis.annotations.Param; @@ -26,4 +23,6 @@ Result getGoldAccount(); Result getOwnCannon(); + + Result fishing(FishingDto fishingDto); } diff --git a/src/main/java/com/xcong/excoin/modules/fish/service/impl/MemberCannonServiceImpl.java b/src/main/java/com/xcong/excoin/modules/fish/service/impl/MemberCannonServiceImpl.java index ee974e7..ea0460d 100644 --- a/src/main/java/com/xcong/excoin/modules/fish/service/impl/MemberCannonServiceImpl.java +++ b/src/main/java/com/xcong/excoin/modules/fish/service/impl/MemberCannonServiceImpl.java @@ -14,10 +14,7 @@ import com.xcong.excoin.modules.fish.dao.CannonOwnRecordDao; import com.xcong.excoin.modules.fish.dao.CannonSettingDao; import com.xcong.excoin.modules.fish.dao.MemberAccountGoldDao; -import com.xcong.excoin.modules.fish.dto.CannonExchangeDto; -import com.xcong.excoin.modules.fish.dto.CoinGoldExchangeDto; -import com.xcong.excoin.modules.fish.dto.GetCannonsDto; -import com.xcong.excoin.modules.fish.dto.GoldExchangeDto; +import com.xcong.excoin.modules.fish.dto.*; import com.xcong.excoin.modules.fish.entity.*; import com.xcong.excoin.modules.fish.service.MemberCannonService; import com.xcong.excoin.modules.fish.vo.CannonSettingVo; @@ -237,6 +234,27 @@ return Result.ok(cannonOwnRecords); } + @Override + public Result fishing(FishingDto fishingDto) { + Long memberId = LoginUserUtils.getAppLoginUser().getId(); + Integer goldWin = fishingDto.getGoldWin() == null?0:fishingDto.getGoldWin(); + if(goldWin < 0){ + return Result.fail("请求异常,请刷新页面"); + } + Long cannonOwnId = fishingDto.getCannonOwnId(); + List<CannonOwnRecord> cannonOwnRecords = cannonOwnRecordDao.selectCannonOwnRecordsByIdAndMemberId(cannonOwnId,memberId); + if(CollUtil.isEmpty(cannonOwnRecords)){ + Result.fail("请求异常,请刷新页面"); + } + //消耗金币 = 每发炮弹的消耗 - 获得金币; + CannonOwnRecord cannonOwnRecord = cannonOwnRecords.get(0); + CannonSetting cannonSetting = cannonSettingDao.selectCannonSettingByCannonCode(cannonOwnRecord.getCannonCode()); + BigDecimal goldConsume = cannonSetting.getGoldConsume().subtract(new BigDecimal(goldWin)).setScale(0,BigDecimal.ROUND_DOWN); + MemberAccountGold memberAccountGold = memberAccountGoldDao.selectAccountGoldByMemberId(memberId); + memberCannonService.updateTotalBalanceAndAvailableBalance(memberAccountGold.getId(),goldConsume.negate(),goldConsume.negate(),null); + return Result.ok("success"); + } + public static void main(String[] args) { System.out.println(UUID.randomUUID().toString()); } diff --git a/src/main/java/com/xcong/excoin/modules/fish/vo/OwnCannonVo.java b/src/main/java/com/xcong/excoin/modules/fish/vo/OwnCannonVo.java index 23823f8..6dc2329 100644 --- a/src/main/java/com/xcong/excoin/modules/fish/vo/OwnCannonVo.java +++ b/src/main/java/com/xcong/excoin/modules/fish/vo/OwnCannonVo.java @@ -9,6 +9,7 @@ @ApiModel(value = "OwnCannonVo", description = "金币账户") public class OwnCannonVo { + private Long id; private Long memberId; @ApiModelProperty(value = "炮台UUID")//炮台UUID private String cannonUuid; diff --git a/src/main/resources/mapper/fish/CannonOwnRecordDao.xml b/src/main/resources/mapper/fish/CannonOwnRecordDao.xml index e79ff28..ba3b187 100644 --- a/src/main/resources/mapper/fish/CannonOwnRecordDao.xml +++ b/src/main/resources/mapper/fish/CannonOwnRecordDao.xml @@ -13,4 +13,8 @@ where a.member_id = #{memberId} </select> + <select id="selectCannonOwnRecordsByIdAndMemberId" resultType="com.xcong.excoin.modules.fish.entity.CannonOwnRecord"> + select a.* from cannon_own_record a where a.member_id = #{memberId} and a.id = #{id} + </select> + </mapper> \ No newline at end of file diff --git a/src/main/resources/mapper/fish/CannonSettingDao.xml b/src/main/resources/mapper/fish/CannonSettingDao.xml index c32369d..0bdfba0 100644 --- a/src/main/resources/mapper/fish/CannonSettingDao.xml +++ b/src/main/resources/mapper/fish/CannonSettingDao.xml @@ -10,4 +10,8 @@ select a.* from cannon_setting a order by id asc </select> + <select id="selectCannonSettingByCannonCode" resultType="com.xcong.excoin.modules.fish.entity.CannonSetting"> + select a.* from cannon_setting a where a.code = #{cannonCode} + </select> + </mapper> \ No newline at end of file -- Gitblit v1.9.1