From 1afdc7e8ebd84b0d7e896ef60963352d1166d12a Mon Sep 17 00:00:00 2001 From: KKSU <15274802129@163.com> Date: Tue, 16 Jul 2024 11:50:46 +0800 Subject: [PATCH] 后台 --- src/main/java/cc/mrbird/febs/mall/service/impl/MallNewsInfoServiceImpl.java | 396 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 364 insertions(+), 32 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/MallNewsInfoServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/MallNewsInfoServiceImpl.java index eb93f7e..8d16a87 100644 --- a/src/main/java/cc/mrbird/febs/mall/service/impl/MallNewsInfoServiceImpl.java +++ b/src/main/java/cc/mrbird/febs/mall/service/impl/MallNewsInfoServiceImpl.java @@ -2,20 +2,40 @@ import cc.mrbird.febs.common.entity.FebsResponse; import cc.mrbird.febs.common.entity.QueryRequest; +import cc.mrbird.febs.common.enumerates.DataDictionaryEnum; +import cc.mrbird.febs.common.enumerates.FlowTypeNewEnum; +import cc.mrbird.febs.common.enumerates.MoneyFlowTypeNewEnum; +import cc.mrbird.febs.common.enumerates.ProductEnum; +import cc.mrbird.febs.common.exception.FebsException; +import cc.mrbird.febs.common.utils.LoginUserUtil; +import cc.mrbird.febs.common.utils.MallUtils; +import cc.mrbird.febs.mall.conversion.MallProductNftConversion; +import cc.mrbird.febs.mall.dto.AdminBuyRecordPayDto; +import cc.mrbird.febs.mall.dto.AdminMallProductNftDto; +import cc.mrbird.febs.mall.dto.AdminPickSellRecordDtoDto; import cc.mrbird.febs.mall.dto.MallNewsInfoDto; -import cc.mrbird.febs.mall.entity.MallNewsCategory; -import cc.mrbird.febs.mall.entity.MallNewsInfo; -import cc.mrbird.febs.mall.mapper.MallNewsCategoryMapper; -import cc.mrbird.febs.mall.mapper.MallNewsInfoMapper; +import cc.mrbird.febs.mall.entity.*; +import cc.mrbird.febs.mall.mapper.*; +import cc.mrbird.febs.mall.service.IMallMoneyFlowService; import cc.mrbird.febs.mall.service.IMallNewsInfoService; -import cc.mrbird.febs.mall.vo.AdminMallNewsInfoVo; +import cc.mrbird.febs.mall.vo.*; +import cc.mrbird.febs.rabbit.producter.AgentProducer; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.crypto.SecureUtil; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.List; /** * @author wzy @@ -27,7 +47,16 @@ public class MallNewsInfoServiceImpl extends ServiceImpl<MallNewsInfoMapper, MallNewsInfo> implements IMallNewsInfoService { private final MallNewsCategoryMapper mallNewsCategoryMapper; - + private final MallProductNftMapper mallProductNftMapper; + private final MallProductBuyMapper mallProductBuyMapper; + private final MallProductSellMapper mallProductSellMapper; + private final MallProductSellRecordMapper mallProductSellRecordMapper; + private final MallProductBuyRecordMapper mallProductBuyRecordMapper; + private final IMallMoneyFlowService mallMoneyFlowService; + private final AgentProducer agentProducer; + private final MallMemberSpeakMapper mallMemberSpeakMapper; + private final DataDictionaryCustomMapper dataDictionaryCustomMapper; + @Override public IPage<AdminMallNewsInfoVo> getNewInfoList(MallNewsInfo mallNewsInfo, QueryRequest request) { Page<AdminMallNewsInfoVo> page = new Page<>(request.getPageNum(), request.getPageSize()); @@ -37,20 +66,27 @@ @Override public FebsResponse addNewsInfo(MallNewsInfoDto mallNewsInfoDto) { - Integer type = mallNewsInfoDto.getType(); - if(type == 2){ - Long goodsId = mallNewsInfoDto.getGoodsId()==null?0L:mallNewsInfoDto.getGoodsId(); - if(goodsId == 0L){ - return new FebsResponse().fail().message("请选择跳转的产品"); - } +// Integer type = mallNewsInfoDto.getType(); +// if(type == 2){ +// Long goodsId = mallNewsInfoDto.getGoodsId()==null?0L:mallNewsInfoDto.getGoodsId(); +// if(goodsId == 0L){ +// return new FebsResponse().fail().message("请选择跳转的产品"); +// } +// } +// MallNewsInfo mallNewsInfo = new MallNewsInfo(); +// mallNewsInfo.setTitle(mallNewsInfoDto.getTitle()); +// mallNewsInfo.setContent(mallNewsInfoDto.getContent()); +// mallNewsInfo.setType(mallNewsInfoDto.getType()); +// if(mallNewsInfoDto.getType() == 2){ +// mallNewsInfo.setTargetId(mallNewsInfoDto.getGoodsId()); +// } + String content = mallNewsInfoDto.getContent(); + if(StrUtil.isNotBlank(content)){ + //正文图片样式居中 + mallNewsInfoDto.setContent(content+"<style>img{max-width:100%!important;}</style>"); } MallNewsInfo mallNewsInfo = new MallNewsInfo(); - mallNewsInfo.setTitle(mallNewsInfoDto.getTitle()); - mallNewsInfo.setContent(mallNewsInfoDto.getContent()); - mallNewsInfo.setType(mallNewsInfoDto.getType()); - if(mallNewsInfoDto.getType() == 2){ - mallNewsInfo.setTargetId(mallNewsInfoDto.getGoodsId()); - } + BeanUtil.copyProperties(mallNewsInfoDto, mallNewsInfo); this.baseMapper.insert(mallNewsInfo); return new FebsResponse().success(); } @@ -71,22 +107,31 @@ if(ObjectUtil.isEmpty(mallNewsInfoBefore)){ return new FebsResponse().fail().message("系统繁忙,请刷新页面重试"); } - Integer type = mallNewsInfoDto.getType(); - if(type == 2){ - Long goodsId = mallNewsInfoDto.getGoodsId()==null?0L:mallNewsInfoDto.getGoodsId(); - if(goodsId == 0L){ - return new FebsResponse().fail().message("请选择跳转的产品"); - } +// Integer type = mallNewsInfoDto.getType(); +// if(type == 2){ +// Long goodsId = mallNewsInfoDto.getGoodsId()==null?0L:mallNewsInfoDto.getGoodsId(); +// if(goodsId == 0L){ +// return new FebsResponse().fail().message("请选择跳转的产品"); +// } +// } +// MallNewsInfo mallNewsInfo = new MallNewsInfo(); +// mallNewsInfo.setTitle(mallNewsInfoDto.getTitle()); +// mallNewsInfo.setContent(mallNewsInfoDto.getContent()); +// mallNewsInfo.setType(mallNewsInfoDto.getType()); +// if(mallNewsInfoDto.getType() == 2){ +// mallNewsInfo.setTargetId(mallNewsInfoDto.getGoodsId()); +// } +// this.baseMapper.insert(mallNewsInfo); +// this.baseMapper.deleteById(mallNewsInfoDto.getId()); + + String content = mallNewsInfoDto.getContent(); + if(StrUtil.isNotBlank(content)){ + //正文图片样式居中 + mallNewsInfoDto.setContent(content+"<style>img{max-width:100%!important;}</style>"); } MallNewsInfo mallNewsInfo = new MallNewsInfo(); - mallNewsInfo.setTitle(mallNewsInfoDto.getTitle()); - mallNewsInfo.setContent(mallNewsInfoDto.getContent()); - mallNewsInfo.setType(mallNewsInfoDto.getType()); - if(mallNewsInfoDto.getType() == 2){ - mallNewsInfo.setTargetId(mallNewsInfoDto.getGoodsId()); - } - this.baseMapper.insert(mallNewsInfo); - this.baseMapper.deleteById(mallNewsInfoDto.getId()); + BeanUtil.copyProperties(mallNewsInfoDto, mallNewsInfo); + this.baseMapper.updateById(mallNewsInfo); return new FebsResponse().success(); } @@ -114,4 +159,291 @@ public MallNewsCategory findNewsCategoryById(Long id) { return mallNewsCategoryMapper.selectById(id); } + + @Override + public List<MallNewsCategory> findAllCategory() { + return mallNewsCategoryMapper.selectList(null); + } + + @Override + public FebsResponse delNewsCategoryInfo(Long id) { + MallNewsCategory mallNewsCategory = mallNewsCategoryMapper.selectById(id); + if(ObjectUtil.isEmpty(mallNewsCategory)){ + return new FebsResponse().fail().message("系统繁忙,请刷新页面重试"); + } + mallNewsCategoryMapper.deleteById(id); + return new FebsResponse().success(); + } + + @Override + public IPage<AdminMallProductNftVo> getProductNFTList(MallProductNft mallProductNft, QueryRequest request) { + Page<AdminMallProductNftVo> page = new Page<>(request.getPageNum(), request.getPageSize()); + IPage<AdminMallProductNftVo> adminMallNewsInfoVoIPage = mallProductNftMapper.getProductNFTList(page, mallProductNft); + return adminMallNewsInfoVoIPage; + } + + @Override + public FebsResponse addProductNFT(AdminMallProductNftDto adminMallProductNftDto) { + MallProductNft mallProductNft = MallProductNftConversion.INSTANCE.dtoToEntity(adminMallProductNftDto); + mallProductNftMapper.insert(mallProductNft); + return new FebsResponse().success(); + } + + @Override + public FebsResponse delNFT(Long id) { + MallProductNft mallProductNft = mallProductNftMapper.selectById(id); + if(ObjectUtil.isEmpty(mallProductNft)){ + return new FebsResponse().fail().message("系统繁忙,请刷新页面重试"); + } + mallProductNftMapper.deleteById(id); + return new FebsResponse().success(); + } + + @Override + public FebsResponse nftInfoUpdate(MallProductNft mallProductNft) { + mallProductNftMapper.updateById(mallProductNft); + return new FebsResponse().success(); + } + + @Override + public IPage<AdminMallProductBuyVo> getBuyList(MallProductBuy mallProductBuy, QueryRequest request) { + Page<AdminMallProductBuyVo> page = new Page<>(request.getPageNum(), request.getPageSize()); + IPage<AdminMallProductBuyVo> adminMallProductBuyVoIPage = mallProductNftMapper.getBuyList(page, mallProductBuy); + DateTime nowTime = DateUtil.parseTime(DateUtil.formatTime(DateUtil.date())); + DataDictionaryCustom endTimeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( + DataDictionaryEnum.YU_YUE_END_TIME.getType(), + DataDictionaryEnum.YU_YUE_END_TIME.getCode() + ); + DateTime endTime = DateUtil.parseTime(endTimeDic.getValue()); + /** + * 当前时间比结束时间大 + */ + List<AdminMallProductBuyVo> records = adminMallProductBuyVoIPage.getRecords(); + if(CollUtil.isNotEmpty(records)){ + for(AdminMallProductBuyVo adminMallProductBuyVo :records){ + if(nowTime.compareTo(endTime) >= 0){ + adminMallProductBuyVo.setButtonState(0); + }else{ + adminMallProductBuyVo.setButtonState(1); + } + } + } + return adminMallProductBuyVoIPage; + } + + @Override + public IPage<MallProductBuyRecord> getBuyRecordList(MallProductBuy mallProductBuy, QueryRequest request) { + if(ObjectUtil.isNotEmpty(mallProductBuy.getAccountLogin())){ + String accountLogin = mallProductBuy.getAccountLogin(); + + } + Page<MallProductBuyRecord> page = new Page<>(request.getPageNum(), request.getPageSize()); + IPage<MallProductBuyRecord> mallProductBuyRecordIPage = mallProductNftMapper.getBuyRecordList(page, mallProductBuy); + return mallProductBuyRecordIPage; + } + + @Override + public IPage<AdminMallProductSellVo> getSellList(MallProductSell mallProductSell, QueryRequest request) { + Page<AdminMallProductSellVo> page = new Page<>(request.getPageNum(), request.getPageSize()); + IPage<AdminMallProductSellVo> adminMallProductSellVoIPage = mallProductNftMapper.getSellList(page, mallProductSell); + return adminMallProductSellVoIPage; + } + + @Override + public List<AdminMallProductSellPickVo> findSellList() { + List<AdminMallProductSellPickVo> list = mallProductNftMapper.selectProductSellByState(ProductEnum.PRODUCT_SELL_ON_GOING.getValue()); + return list; + } + + @Override + public FebsResponse pickSellRecord(AdminPickSellRecordDtoDto pickSellRecordDto) { + /** + * 买单条件是否满足 + * 卖单条件是否满足 + * 生成卖单子记录 + * 生成买单子记录 + * 更新卖单状态 + * 更新买单状态 + */ + Long productBuyId = pickSellRecordDto.getId(); + Long productSellId = pickSellRecordDto.getProductSellId(); + BigDecimal pickNftCnt = new BigDecimal(pickSellRecordDto.getPickNftCnt()); + //买单 + MallProductBuy mallProductBuy = mallProductBuyMapper.selectById(productBuyId); + int state = mallProductBuy.getState(); + if(ProductEnum.PRODUCT_BUY_ON_GOING.getValue() != state){ + return new FebsResponse().fail().message("预约状态不是进行中"); + } + BigDecimal nftAva = mallProductBuy.getNftAva(); + if(BigDecimal.ZERO.compareTo(pickNftCnt) >= 0){ + return new FebsResponse().fail().message("本次金额不能小于等于零"); + } + if(nftAva.compareTo(pickNftCnt) < 0){ + return new FebsResponse().fail().message("可分配不足"); + } + //卖单 + MallProductSell mallProductSell = mallProductSellMapper.selectById(productSellId); + BigDecimal nftCntAva = mallProductSell.getNftCntAva(); + if(ProductEnum.PRODUCT_SELL_ON_GOING.getValue() != mallProductSell.getState()){ + return new FebsResponse().fail().message("预约状态不是进行中"); + } + if(nftCntAva.compareTo(pickNftCnt) < 0){ + return new FebsResponse().fail().message("匹配提现剩余不足"); + } + DateTime orderTime = DateUtil.date(); + //生成卖单子记录 + MallProductSellRecord mallProductSellRecord = new MallProductSellRecord(); + mallProductSellRecord.setSellId(mallProductSell.getId()); + mallProductSellRecord.setMemberId(mallProductBuy.getMemberId()); + mallProductSellRecord.setOrderTime(orderTime); + mallProductSellRecord.setNftCnt(pickNftCnt); + mallProductSellRecord.setState(ProductEnum.PRODUCT_MATE_STATE_WAIT_PAY.getValue()); + mallProductSellRecordMapper.insert(mallProductSellRecord); + //生成买单子记录 + MallProductBuyRecord mallProductBuyRecord = new MallProductBuyRecord(); + mallProductBuyRecord.setBuyId(mallProductBuy.getId()); + mallProductBuyRecord.setMemberId(mallProductSell.getMemberId()); + mallProductBuyRecord.setSellRecordId(mallProductSellRecord.getId()); + mallProductBuyRecord.setPickNftCnt(pickNftCnt); + mallProductBuyRecord.setBuyOrderNo(mallProductBuy.getOrderNo()); + mallProductBuyRecord.setState(ProductEnum.PRODUCT_MATE_STATE_WAIT_PAY.getValue()); + mallProductBuyRecord.setOrderTime(orderTime); + mallProductBuyRecordMapper.insert(mallProductBuyRecord); + //更新卖单 + mallProductSell.setNftCntAva(mallProductSell.getNftCntAva().subtract(pickNftCnt)); + mallProductSellMapper.updateById(mallProductSell); + mallProductSellRecord.setBuyRecordId(mallProductBuyRecord.getId()); + mallProductSellRecordMapper.updateById(mallProductSellRecord); + //更新买单 + mallProductBuy.setNftAva(mallProductBuy.getNftAva().subtract(pickNftCnt)); + mallProductBuyMapper.updateById(mallProductBuy); + return new FebsResponse().success(); + } + + @Override + public FebsResponse buyRecordPay(AdminBuyRecordPayDto buyRecordPayDto) { + Long buyRecordId = buyRecordPayDto.getId(); + String nftImg = buyRecordPayDto.getNftImg(); + Integer type = buyRecordPayDto.getType(); + /** + * 验证订单是否存在 + * 更新买单状态 + * 更新卖单状态 + * 生成流水信息 + */ + MallProductBuyRecord mallProductBuyRecord = mallProductBuyRecordMapper.selectById(buyRecordId); + if(ObjectUtil.isEmpty(mallProductBuyRecord)){ + throw new FebsException("记录不存在"); + } +// Integer state = mallProductBuyRecord.getState(); +// if(ProductEnum.PRODUCT_MATE_STATE_WAIT_PAY.getValue() != state){ +// throw new FebsException("记录不是待支付状态"); +// } + + MallProductSellRecord mallProductSellRecord = mallProductSellRecordMapper.selectById(mallProductBuyRecord.getSellRecordId()); + if(ObjectUtil.isEmpty(mallProductSellRecord)){ + throw new FebsException("记录不存在"); + } +// Integer stateSell = mallProductSellRecord.getState(); +// if(ProductEnum.PRODUCT_MATE_STATE_WAIT_PAY.getValue() != stateSell){ +// throw new FebsException("记录不是待支付状态"); +// } + + DateTime payTime = DateUtil.date(); + mallProductBuyRecord.setState(ProductEnum.PRODUCT_MATE_STATE_PAY.getValue()); + mallProductBuyRecord.setPayTime(payTime); + mallProductBuyRecord.setNftImg(nftImg); + mallProductBuyRecord.setType(type); + mallProductBuyRecordMapper.updateById(mallProductBuyRecord); + + mallProductSellRecord.setState(ProductEnum.PRODUCT_MATE_STATE_PAY.getValue()); + mallProductSellRecord.setPayTime(payTime); + mallProductSellRecord.setNftImg(nftImg); + mallProductSellRecord.setType(type); + mallProductSellRecordMapper.updateById(mallProductSellRecord); + + String orderNo = MallUtils.getOrderNum("ZF"); + mallMoneyFlowService.addMoneyFlow( + mallProductSellRecord.getMemberId(), + mallProductBuyRecord.getPickNftCnt(), + MoneyFlowTypeNewEnum.PAY.getValue(), + orderNo, + mallProductSellRecord.getMemberId(), + FlowTypeNewEnum.NFT.getValue(), + MoneyFlowTypeNewEnum.PAY.getDescrition()); + return new FebsResponse().success(); + } + + @Override + public FebsResponse buyRecordConfirm(Long id) { + /** + * 验证订单是否存在 + * 更新买单状态 + * 更新卖单状态 + * 生成流水信息 + */ + MallProductBuyRecord mallProductBuyRecord = mallProductBuyRecordMapper.selectById(id); + if(ObjectUtil.isEmpty(mallProductBuyRecord)){ + throw new FebsException("记录不存在"); + } +// Integer state = mallProductBuyRecord.getState(); +// if(ProductEnum.PRODUCT_MATE_STATE_PAY.getValue() != state){ +// throw new FebsException("记录不是已支付状态"); +// } + Long sellRecordId = mallProductBuyRecord.getSellRecordId(); + MallProductSellRecord mallProductSellRecord = mallProductSellRecordMapper.selectById(mallProductBuyRecord.getSellRecordId()); + if(ObjectUtil.isEmpty(mallProductSellRecord)){ + throw new FebsException("记录不存在"); + } +// Integer stateSell = mallProductSellRecord.getState(); +// if(ProductEnum.PRODUCT_MATE_STATE_PAY.getValue() != stateSell){ +// throw new FebsException("记录不是已支付状态"); +// } + + mallProductBuyRecord.setState(ProductEnum.PRODUCT_MATE_STATE_CONFIRM.getValue()); + mallProductBuyRecordMapper.updateById(mallProductBuyRecord); + + mallProductSellRecord.setState(ProductEnum.PRODUCT_MATE_STATE_CONFIRM.getValue()); + mallProductSellRecordMapper.updateById(mallProductSellRecord); + + agentProducer.sendFcmOrderSellInsureMsg(sellRecordId); + return new FebsResponse().success(); + } + + @Override + public FebsResponse buyRecordCancel(Long id) { + MallProductBuyRecord mallProductBuyRecord = mallProductBuyRecordMapper.selectById(id); + if(ObjectUtil.isEmpty(mallProductBuyRecord)){ + throw new FebsException("记录不存在"); + } +// Integer state = mallProductBuyRecord.getState(); +// if(ProductEnum.PRODUCT_MATE_STATE_WAIT_PAY.getValue() != state){ +// throw new FebsException("记录不是待支付状态"); +// } + Long sellRecordId = mallProductBuyRecord.getSellRecordId(); + //更新买单子表的数据 + mallProductBuyRecord.setState(ProductEnum.PRODUCT_MATE_STATE_FAIL.getValue()); + mallProductBuyRecordMapper.updateById(mallProductBuyRecord); + //更新买单主表 + MallProductBuy mallProductBuy = mallProductBuyMapper.selectById(mallProductBuyRecord.getBuyId()); + mallProductBuy.setNftAva(mallProductBuy.getNftAva().add(mallProductBuyRecord.getPickNftCnt())); + mallProductBuyMapper.updateById(mallProductBuy); + //更新卖单子表的数据 + MallProductSellRecord mallProductSellRecord = mallProductSellRecordMapper.selectById(sellRecordId); + mallProductSellRecord.setState(ProductEnum.PRODUCT_MATE_STATE_FAIL.getValue()); + mallProductSellRecordMapper.updateById(mallProductSellRecord); + //更新卖单主表 + Long sellId = mallProductSellRecord.getSellId(); + MallProductSell mallProductSell = mallProductSellMapper.selectById(sellId); + mallProductSell.setNftCntAva(mallProductSell.getNftCntAva().add(mallProductSellRecord.getNftCnt())); + mallProductSellMapper.updateById(mallProductSell); + return new FebsResponse().success(); + } + + @Override + public IPage<MallMemberSpeak> getSpeakList(MallMemberSpeak mallMemberSpeak, QueryRequest request) { + Page<MallMemberSpeak> page = new Page<>(request.getPageNum(), request.getPageSize()); + IPage<MallMemberSpeak> adminMallNewsInfoVoIPage = mallProductSellMapper.getSpeakListInPage(page, mallMemberSpeak); + return adminMallNewsInfoVoIPage; + } } -- Gitblit v1.9.1