package com.fdkankan.ucenter.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.fdkankan.common.constant.TbStatus; import com.fdkankan.ucenter.common.PageInfo; import com.fdkankan.common.util.NumberUtils; import com.fdkankan.ucenter.entity.DownloadOrder; import com.fdkankan.ucenter.entity.Invoice; import com.fdkankan.ucenter.entity.User; import com.fdkankan.ucenter.mapper.IDownloadOrderMapper; import com.fdkankan.ucenter.service.IDownloadOrderService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.fdkankan.ucenter.service.IInvoiceService; import com.fdkankan.ucenter.service.IUserService; import com.fdkankan.ucenter.util.DateUserUtil; import com.fdkankan.ucenter.vo.request.DownNumParam; import com.fdkankan.ucenter.vo.request.IncrementOrderParam; import com.fdkankan.ucenter.vo.response.DownloadVo; import com.sun.javafx.font.directwrite.DWFactory; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; import java.util.List; /** *

* 下载次数订单表 服务实现类 *

* * @author * @since 2022-07-13 */ @Service public class DownloadOrderServiceImpl extends ServiceImpl implements IDownloadOrderService { @Autowired IUserService userService; @Autowired IInvoiceService invoiceService; @Override public PageInfo pageList(IncrementOrderParam param) { User user = userService.getByUserName(param.getUserName()); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(DownloadOrder::getUserId,user.getId()); wrapper.orderByDesc(DownloadOrder::getTradeTime); Page page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper); List listVo = new ArrayList<>(); for (DownloadOrder record : page.getRecords()) { if(StringUtils.isNotBlank(record.getTradeTime())){ record.setTradeTime(DateUserUtil.AddMinute(record.getTradeTime(),record.getTimeZoneOff())); } DownloadVo vo = new DownloadVo(); BeanUtils.copyProperties(record,vo); Invoice invoice = invoiceService.getByDownId(record.getId()); vo.setInvoice(invoice); listVo.add(vo); } Page pageVo = new Page<>(param.getPageNum(),param.getPageSize()); pageVo.setTotal(page.getTotal()); pageVo.setRecords(listVo); return PageInfo.PageInfo(pageVo); } @Override public DownloadOrder getByOrderSn(String orderSn) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(DownloadOrder::getOrderSn,orderSn); List list = this.list(queryWrapper); if(list == null || list.size() <=0){ return null; } return list.get(0); } @Override public DownloadOrder getByOrderSnNoPay(String orderSn) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(DownloadOrder::getOrderSn,orderSn); queryWrapper.lambda().ne(DownloadOrder::getPayStatus,1); List list = this.list(queryWrapper); if(list == null || list.size() <=0){ return null; } return list.get(0); } @Override public boolean paySuccessDownloadOrder(String orderSn, String tradeNo, int paymentTypeName) { LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); updateWrapper.set(DownloadOrder::getPayType,paymentTypeName) .set(DownloadOrder::getNumber,tradeNo) .set(DownloadOrder::getPayStatus,1) .set(DownloadOrder::getTradeTime,new Date()) .eq(DownloadOrder::getOrderSn,orderSn); return this.update(updateWrapper); } @Override public DownloadOrder insertDownloadOrder(Long userId, DownNumParam param, BigDecimal price) { BigDecimal total = price.multiply(new BigDecimal(param.getCount())); DownloadOrder downloadOrderEntity = new DownloadOrder(); downloadOrderEntity.setOrderSn(NumberUtils.getOrderSn()); downloadOrderEntity.setAmount(total); downloadOrderEntity.setPayType(param.getPayType()); downloadOrderEntity.setPayStatus(-1); downloadOrderEntity.setUserId(userId); downloadOrderEntity.setCount(param.getCount()); downloadOrderEntity.setAbroad(param.getAbroad()); downloadOrderEntity.setStatus(1); downloadOrderEntity.setSceneNum(param.getSceneNum()); downloadOrderEntity.setSceneName(param.getSceneName()); downloadOrderEntity.setTimeZoneOff(param.getTimeZoneOff()); downloadOrderEntity.setRecStatus("A"); downloadOrderEntity.setCreateTime(DateUserUtil.getDate(new Date())); downloadOrderEntity.setUpdateTime(DateUserUtil.getDate(new Date())); this.save(downloadOrderEntity); return downloadOrderEntity; } }