| | |
| | | |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.entity.QueryRequest; |
| | | import cc.mrbird.febs.common.enumerates.ProductEnum; |
| | | import cc.mrbird.febs.mall.conversion.MallProductNftConversion; |
| | | 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.IMallNewsInfoService; |
| | | import cc.mrbird.febs.mall.vo.AdminMallNewsInfoVo; |
| | | import cc.mrbird.febs.mall.vo.*; |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | 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 com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | 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; |
| | | |
| | | @Override |
| | | public IPage<AdminMallNewsInfoVo> getNewInfoList(MallNewsInfo mallNewsInfo, QueryRequest request) { |
| | | Page<AdminMallNewsInfoVo> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | |
| | | // 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(); |
| | | BeanUtil.copyProperties(mallNewsInfoDto, mallNewsInfo); |
| | | this.baseMapper.insert(mallNewsInfo); |
| | |
| | | // 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(); |
| | | BeanUtil.copyProperties(mallNewsInfoDto, mallNewsInfo); |
| | | this.baseMapper.updateById(mallNewsInfo); |
| | |
| | | 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); |
| | | return adminMallProductBuyVoIPage; |
| | | } |
| | | |
| | | @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.setState(ProductEnum.PRODUCT_MATE_STATE_WAIT_PAY.getValue()); |
| | | mallProductBuyRecord.setOrderTime(orderTime); |
| | | mallProductBuyRecordMapper.insert(mallProductBuyRecord); |
| | | //更新卖单 |
| | | mallProductSell.setNftCntAva(mallProductSell.getNftCntAva().subtract(pickNftCnt)); |
| | | mallProductSellMapper.updateById(mallProductSell); |
| | | //更新买单 |
| | | mallProductBuy.setNftAva(mallProductBuy.getNftAva().subtract(pickNftCnt)); |
| | | mallProductBuyMapper.updateById(mallProductBuy); |
| | | return new FebsResponse().success(); |
| | | } |
| | | } |