|
@@ -1,15 +1,24 @@
|
|
package com.fdkankan.ucenter.service.impl;
|
|
package com.fdkankan.ucenter.service.impl;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.fdkankan.common.constant.AppConstant;
|
|
import com.fdkankan.common.constant.AppConstant;
|
|
|
|
+import com.fdkankan.common.constant.ErrorCode;
|
|
|
|
+import com.fdkankan.common.constant.ServerCode;
|
|
|
|
+import com.fdkankan.common.constant.TbStatus;
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
|
+import com.fdkankan.ucenter.common.PageInfo;
|
|
import com.fdkankan.ucenter.entity.*;
|
|
import com.fdkankan.ucenter.entity.*;
|
|
import com.fdkankan.ucenter.mapper.IInvoiceMapper;
|
|
import com.fdkankan.ucenter.mapper.IInvoiceMapper;
|
|
import com.fdkankan.ucenter.service.*;
|
|
import com.fdkankan.ucenter.service.*;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.fdkankan.ucenter.vo.request.InvoiceParam;
|
|
import com.fdkankan.ucenter.vo.request.InvoiceParam;
|
|
import com.fdkankan.ucenter.vo.request.PlaceOrderParam;
|
|
import com.fdkankan.ucenter.vo.request.PlaceOrderParam;
|
|
|
|
+import com.fdkankan.ucenter.vo.response.OrderVo;
|
|
import com.sun.xml.bind.v2.model.core.ID;
|
|
import com.sun.xml.bind.v2.model.core.ID;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.aspectj.weaver.ast.Or;
|
|
import org.aspectj.weaver.ast.Or;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -37,6 +46,8 @@ public class InvoiceServiceImpl extends ServiceImpl<IInvoiceMapper, Invoice> imp
|
|
IIncrementOrderService incrementOrderService;
|
|
IIncrementOrderService incrementOrderService;
|
|
@Autowired
|
|
@Autowired
|
|
IVirtualOrderService virtualOrderService;
|
|
IVirtualOrderService virtualOrderService;
|
|
|
|
+ @Autowired
|
|
|
|
+ IExpansionOrderService expansionOrderService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Invoice getByOrderId(Long orderId) {
|
|
public Invoice getByOrderId(Long orderId) {
|
|
@@ -170,4 +181,180 @@ public class InvoiceServiceImpl extends ServiceImpl<IInvoiceMapper, Invoice> imp
|
|
|
|
|
|
return dbEntity;
|
|
return dbEntity;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public JSONObject getMaxInvoice(InvoiceParam param) {
|
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
|
+ int maxInvoice = this.getMaxInvoice(param.getCameraId());
|
|
|
|
+ object.put("maxInvoice", maxInvoice < 0 ? 0 : maxInvoice);
|
|
|
|
+ return object;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private Integer getMaxInvoice(Long cameraId){
|
|
|
|
+ List<VirtualOrder> virtualOrderList = virtualOrderService.getByCameraId(cameraId);
|
|
|
|
+ int maxInvoice = 0;
|
|
|
|
+ for (VirtualOrder virtualOrderEntity : virtualOrderList){
|
|
|
|
+ if (virtualOrderEntity.getStatus() == 1 && virtualOrderEntity.getPayStatus() == 1){
|
|
|
|
+ maxInvoice += virtualOrderEntity.getPoints();
|
|
|
|
+ }else if (virtualOrderEntity.getStatus() == -2){
|
|
|
|
+ maxInvoice -= virtualOrderEntity.getPoints();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ List<ExpansionOrder> expansionOrderList = expansionOrderService.getByCameraId(cameraId);
|
|
|
|
+ for(ExpansionOrder expansionOrderEntity : expansionOrderList){
|
|
|
|
+ if(expansionOrderEntity.getPayStatus() == 1){
|
|
|
|
+ maxInvoice += expansionOrderEntity.getAmount().intValue();
|
|
|
|
+ }else if (expansionOrderEntity.getPayStatus() == -2){
|
|
|
|
+ maxInvoice -= expansionOrderEntity.getAmount().intValue();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ LambdaQueryWrapper<Invoice> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ wrapper.eq(Invoice::getCameraId,cameraId);
|
|
|
|
+ wrapper.eq(Invoice::getConsumeType,1);
|
|
|
|
+ List<Invoice> list = this.list(wrapper);
|
|
|
|
+ for (Invoice entity : list){
|
|
|
|
+ if (entity.getMoney() != null){
|
|
|
|
+ maxInvoice -= entity.getMoney().intValue();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return maxInvoice;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public PageInfo getInvoices(String token, InvoiceParam param) {
|
|
|
|
+ LambdaQueryWrapper<Invoice> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ if(StringUtils.isNotBlank(token)){
|
|
|
|
+ User user = userService.getByToken(token);
|
|
|
|
+ wrapper.eq(Invoice::getUserId,user.getId());
|
|
|
|
+ }
|
|
|
|
+ if(param.getCameraId() != null){
|
|
|
|
+ wrapper.eq(Invoice::getCameraId,param.getCameraId());
|
|
|
|
+ }
|
|
|
|
+ if(param.getType() != null){
|
|
|
|
+ if(param.getType() != 0){
|
|
|
|
+ wrapper.ne(Invoice::getType,0);
|
|
|
|
+ }else {
|
|
|
|
+ wrapper.eq(Invoice::getType,1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ wrapper.ne(Invoice::getConsumeType ,-1);
|
|
|
|
+ wrapper.orderByDesc(Invoice::getCreateTime);
|
|
|
|
+ Page<Invoice> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
|
|
|
|
+ return PageInfo.PageInfo(page);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Invoice getMyInvoiceInfo(String token, InvoiceParam param) {
|
|
|
|
+ User user = userService.getByToken(token);
|
|
|
|
+ return getMineInvoice(user.getId(),param.getInvoiceType());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Invoice getMineInvoice(Long userId,String invoiceType){
|
|
|
|
+ LambdaQueryWrapper<Invoice> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ wrapper.eq(Invoice::getUserId,userId);
|
|
|
|
+ wrapper.eq(Invoice::getConsumeType ,-1);
|
|
|
|
+ wrapper.eq(Invoice::getType ,invoiceType);
|
|
|
|
+ wrapper.last("LIMIT 1");
|
|
|
|
+ List<Invoice> list = this.list(wrapper);
|
|
|
|
+ if(list == null || list.size()<=0){
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ return list.get(0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void saveInvoice(String token, InvoiceParam param) {
|
|
|
|
+ User user = userService.getByToken(token);
|
|
|
|
+ Invoice dbEntity = getMineInvoice(user.getId(),param.getInvoiceType());
|
|
|
|
+ if (dbEntity == null){
|
|
|
|
+ dbEntity = new Invoice();
|
|
|
|
+ }
|
|
|
|
+ if (param.getCameraId() != null){
|
|
|
|
+ dbEntity.setCameraId(param.getCameraId());
|
|
|
|
+ }
|
|
|
|
+ dbEntity.setType(Integer.valueOf(param.getInvoiceType()));
|
|
|
|
+ dbEntity.setUserId(user.getId());
|
|
|
|
+ dbEntity.setBankAccount(param.getBankAccount());
|
|
|
|
+ dbEntity.setBankName(param.getBankName());
|
|
|
|
+ dbEntity.setRegisterPhone(param.getRegisterPhone());
|
|
|
|
+ dbEntity.setOrganizedAddress(param.getOrganizedAddress());
|
|
|
|
+ dbEntity.setCode(param.getCode());
|
|
|
|
+ dbEntity.setTitle(param.getTitle());
|
|
|
|
+ dbEntity.setEmailAddress(param.getEmailAddress());
|
|
|
|
+ dbEntity.setConsumeType(-1);
|
|
|
|
+ if(!this.saveOrUpdate(dbEntity)){
|
|
|
|
+ throw new BusinessException(ErrorCode.ERROR_MSG);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void addInvoice(String token, InvoiceParam param) {
|
|
|
|
+ User user = userService.getByToken(token);
|
|
|
|
+ if(param.getAmount() == null){
|
|
|
|
+ throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
|
+ }
|
|
|
|
+ int maxInvoice = this.getMaxInvoice(param.getCameraId());
|
|
|
|
+
|
|
|
|
+ if(Integer.parseInt(param.getAmount()) > maxInvoice){
|
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_8003);
|
|
|
|
+ }
|
|
|
|
+ saveOrUpdateInvoice(user.getId(),param,null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void updateInvoice(String token, InvoiceParam param) {
|
|
|
|
+ User user = userService.getByToken(token);
|
|
|
|
+ if(param.getInvoiceId() != null){
|
|
|
|
+ Invoice invoiceEntity = this.getById(param.getInvoiceId());
|
|
|
|
+ if(invoiceEntity == null){
|
|
|
|
+ throw new BusinessException(ErrorCode.NOT_RECORD);
|
|
|
|
+ }
|
|
|
|
+ this.saveOrUpdateInvoice(user.getId(), param,invoiceEntity);
|
|
|
|
+
|
|
|
|
+ }else {
|
|
|
|
+
|
|
|
|
+ OrderVo order = orderService.getOrderDetail(param.getOrderId());
|
|
|
|
+ if(order == null || order.getTotalAmount() == null){
|
|
|
|
+ throw new BusinessException(ErrorCode.ERROR_MSG);
|
|
|
|
+ }
|
|
|
|
+ param.setAmount(order.getTotalAmount().toString());
|
|
|
|
+ this.saveOrUpdateInvoice(user.getId(),param,null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void saveOrUpdateInvoice(Long userId, InvoiceParam param, Invoice invoiceEntity){
|
|
|
|
+ if(invoiceEntity == null){
|
|
|
|
+ invoiceEntity = new Invoice();
|
|
|
|
+ invoiceEntity.setUserId(userId);
|
|
|
|
+ invoiceEntity.setOrderId(param.getOrderId());
|
|
|
|
+ }
|
|
|
|
+ invoiceEntity.setType(Integer.valueOf(param.getInvoiceType()));
|
|
|
|
+ invoiceEntity.setTitle(param.getTitle());
|
|
|
|
+ invoiceEntity.setCode(param.getCode());
|
|
|
|
+
|
|
|
|
+ if (3 == invoiceEntity.getType()){
|
|
|
|
+ invoiceEntity.setOrganizedAddress(param.getOrganizedAddress());
|
|
|
|
+ invoiceEntity.setRegisterPhone(param.getRegisterPhone());
|
|
|
|
+ invoiceEntity.setBankName(param.getBankName());
|
|
|
|
+ invoiceEntity.setBankAccount(param.getBankAccount());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ invoiceEntity.setCameraId(param.getCameraId());
|
|
|
|
+ invoiceEntity.setMoney(new BigDecimal(param.getAmount()));
|
|
|
|
+ invoiceEntity.setConsumeType(param.getConsumeType() == null? 1 : param.getConsumeType());
|
|
|
|
+
|
|
|
|
+ invoiceEntity.setShipName(param.getShipName());
|
|
|
|
+ invoiceEntity.setShipMobile(param.getShipMobile());
|
|
|
|
+ invoiceEntity.setShipAddress(param.getShipAddress());
|
|
|
|
+ invoiceEntity.setShipAreaPath(param.getShipAreaPath());
|
|
|
|
+ invoiceEntity.setCameraId(param.getCameraId());
|
|
|
|
+ invoiceEntity.setEmailAddress(param.getEmailAddress());
|
|
|
|
+ if(!this.saveOrUpdate(invoiceEntity)){
|
|
|
|
+ throw new BusinessException(ErrorCode.ERROR_MSG);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|