Browse Source

no message

FengChaoYu 1 week ago
parent
commit
5d9bde2e75

+ 0 - 225
src/main/java/com/gree/mall/manager/logic/tax/TaxLogic.java

@@ -1,225 +0,0 @@
-package com.gree.mall.manager.logic.tax;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import com.alibaba.fastjson.TypeReference;
-import com.gree.mall.manager.bean.tax.*;
-import com.gree.mall.manager.commonmapper.TaxMapper;
-import com.gree.mall.manager.constant.Constant;
-import com.gree.mall.manager.exception.RemoteServiceException;
-import com.gree.mall.manager.plus.entity.*;
-import com.gree.mall.manager.plus.service.OrderDetailService;
-import com.gree.mall.manager.plus.service.OrderInfoService;
-import com.gree.mall.manager.plus.service.OrderTaxService;
-import com.gree.mall.manager.utils.HttpUtils;
-import com.gree.mall.manager.utils.RedisUtil;
-import com.gree.mall.manager.utils.email.EmailUtils;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
-
-import java.math.BigDecimal;
-import java.math.MathContext;
-import java.math.RoundingMode;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-@Service
-@Slf4j
-public class    TaxLogic {
-    @Value("${tax.token.appid}")
-    private String clientId;
-    @Value("${tax.token.appSecret}")
-    private String clientSecret;
-    @Value("${tax.token.url}")
-    private String taxTokenUrl;
-    @Value("${tax.invoice.url}")
-    private String taxUrl;
-    @Autowired
-    private OrderInfoService orderInfoService;
-    @Autowired
-    private OrderTaxService orderTaxService;
-    @Autowired
-    private TaxMapper taxMapper;
-    @Autowired
-    private OrderDetailService orderDetailService;
-    private final String KPY = "李家丽";
-    private final String SKY = "陈惠明";
-    private final String FHR = "罗年欢";
-    @Autowired
-    RedisUtil redisUtil;
-
-    public String getTaxToken() throws RemoteServiceException {
-        Object token = redisUtil.get(Constant.RedisPrefix.TOKEN_TAX);
-
-        if (token != null) {
-            return token.toString();
-        }
-        //过期就重新获取
-        return this.deleteAndAddWxToken();
-    }
-
-    public String deleteAndAddWxToken() throws RemoteServiceException {
-        HashMap<String, String> params = new HashMap();
-        params.put("clientId", this.clientId);
-        params.put("clientSecret", this.clientSecret);
-        String content = HttpUtils.requestGet(taxTokenUrl, params, null);
-        Map<String, Object> resMap = JSON.parseObject(content, new TypeReference<HashMap<String, Object>>() {
-        });
-
-        int code = (int) resMap.get("code");
-        if (code == 1) {
-            String token = (String) resMap.get("data");
-            redisUtil.set(Constant.RedisPrefix.TOKEN_TAX, token, 2 * 60 * 60);//2小时过期
-            return token;
-        }
-        return null;
-    }
-//
-//    public TaxTitleItem title(String companyName) throws RemoteServiceException {
-//        HashMap<String, String> params = new HashMap();
-//        HashMap<String, String> heads = new HashMap();
-//        heads.put("authorization_token", getTaxToken());
-//        params.put("companyName", companyName);
-//        String content = HttpUtils.requestGet(taxTitleUrl, params, heads);
-//        TaxTitleBean taxTitleBean = JSON.parseObject(content, new TypeReference<TaxTitleBean>() {
-//        });
-//
-//        int code = taxTitleBean.getCode();
-//        if (code == 1 && taxTitleBean.getData().size() > 0) {
-//            return taxTitleBean.getData().get(0);
-//        }
-//        return null;
-//    }
-
-    public BaseBean generateTaxData(String orderId) {
-        OrderTax orderTax = orderTaxService.lambdaQuery()
-                .eq(OrderTax::getOrderId, orderId)
-                .one();
-        if (orderTax == null) {
-            return null;
-        }
-        //专票
-        if (orderTax.getTaxType()) {
-            return null;
-        }
-        String title =  orderTax.getName();
-        if (orderTax.getType()) {
-            title = orderTax.getName();
-        }
-        List<OrderDetail> orderDetailList = orderDetailService.lambdaQuery()
-                .eq(OrderDetail::getOrderId, orderId)
-                .list();
-
-        OrderInfo orderInfo = orderInfoService.getById(orderId);
-        BaseBean baseBean = new BaseBean();
-        Content content = new Content();
-        TaxPayerInfo taxPayerInfo = new TaxPayerInfo();
-        List<TaxDetail> taxDetails = new ArrayList<>();
-
-        for (OrderDetail orderDetail : orderDetailList) {
-            TaxDetail taxDetail = new TaxDetail();
-            GoodsCategory goodsCategory = taxMapper.queryTaxById(orderDetail.getOrderDetailId());
-            if (goodsCategory == null) {
-                return null;
-            }
-            if(goodsCategory.getTaxPercent() == null){
-                continue;
-            }
-            taxDetail.setSl(goodsCategory.getTaxPercent().doubleValue());
-            taxDetail.setHsbz("1");
-            taxDetail.setFphxz("0");
-            taxDetail.setSpbm(goodsCategory.getTaxNumber());
-            taxDetail.setXmmc(orderDetail.getGoodsName().length()<50?
-                    orderDetail.getGoodsName():orderDetail.getGoodsName().substring(0,50));
-            taxDetail.setXmsl(orderDetail.getNum().doubleValue());
-            taxDetail.setYhzcbs("0");
-            taxDetail.setXmje((orderDetail.getPayAmount().add(orderDetail.getFreight())).doubleValue());
-//            BigDecimal alpha = new BigDecimal(taxDetail.getSl());
-//            BigDecimal beta = new BigDecimal(taxDetail.getSl()).add(new BigDecimal("1.00"));
-//            taxDetail.setSe(orderDetail.getPayAmount()
-//                    .multiply(alpha.divide(beta, 2, RoundingMode.HALF_UP), new MathContext(2, RoundingMode.HALF_UP))
-//                    .doubleValue());
-            taxDetail.setXmmc(taxDetail.getXmmc().replaceAll(" ",""));
-            taxDetails.add(taxDetail);
-        }
-
-        taxPayerInfo.setKpxm(orderInfo.getOrderTitle().length()<50?
-                orderInfo.getOrderTitle():orderInfo.getOrderTitle().substring(0,50));
-        taxPayerInfo.setGhfmc(title);
-//        if(StringUtils.isNotEmpty(orderTax.getReceiverEmail())){
-//            taxPayerInfo.setBillSentSign("1");
-//            taxPayerInfo.setGhf_email(orderTax.getReceiverEmail());
-//        }else{
-//        }
-        taxPayerInfo.setBillSentSign("0");
-        taxPayerInfo.setDkbz("0");
-        taxPayerInfo.setKplx("1");
-        taxPayerInfo.setQd_bz("0");
-        taxPayerInfo.setKpy(KPY);
-        taxPayerInfo.setSky(SKY);
-        taxPayerInfo.setFhr(FHR);
-
-//        taxPayerInfo.setXhfmc("航信培训企业");
-//        taxPayerInfo.setKpy("张会计");
-        if (!orderTax.getType()) {//个人发票
-            taxPayerInfo.setGhfqylx("03");
-        } else {
-            taxPayerInfo.setGhfqylx("01");
-            taxPayerInfo.setGhf_nsrsbh(orderTax.getTaxNo().trim());
-        }
-        content.setFptxx(taxPayerInfo);
-        content.setXmxx(taxDetails);
-        baseBean.setKpContent(content);
-        return baseBean;
-    }
-
-    public void taxHttp(String orderId) {
-        BaseBean baseBean = generateTaxData(orderId);
-        if (baseBean == null) {
-            return;
-        }
-        HashMap<String, String> heads = new HashMap();
-        try {
-            String token = getTaxToken();
-            if (StringUtils.isEmpty(token)) {
-                return;
-            }
-            heads.put("authorization_token", token);
-        } catch (RemoteServiceException e) {
-            return;
-        }
-        String content = null;
-        try {
-            content = HttpUtils.requestPostBody(taxUrl, JSON.toJSONString(baseBean), heads);
-        } catch (RemoteServiceException e) {
-            return;
-        }
-
-        Map<String, Object> resMap = JSON.parseObject(content, new TypeReference<HashMap<String, Object>>() {
-        });
-
-        int code = (int) resMap.get("code");
-        if (code == 1) {
-            String pdfUrl = "" + resMap.get("data");
-            if (StringUtils.isEmpty(pdfUrl)) {
-                return;
-            }
-            orderTaxService.lambdaUpdate()
-                    .eq(OrderTax::getOrderId, orderId)
-                    .set(OrderTax::getStatus, true)
-                    .set(OrderTax::getTaxType, false)
-                    .set(OrderTax::getTaxLink, pdfUrl)
-                    .update();
-//            new EmailUtils().sendMail();
-        }
-
-
-    }
-
-
-}

+ 0 - 46
src/main/java/com/gree/mall/manager/schedule/TaxSchedule.java

@@ -1,46 +0,0 @@
-package com.gree.mall.manager.schedule;
-
-import com.gree.mall.manager.enums.OrderShareStatusEnum;
-import com.gree.mall.manager.enums.OrderStatusEnum;
-import com.gree.mall.manager.logic.tax.TaxLogic;
-import com.gree.mall.manager.plus.entity.OrderInfo;
-import com.gree.mall.manager.plus.entity.OrderShare;
-import com.gree.mall.manager.plus.entity.OrderTax;
-import com.gree.mall.manager.plus.service.OrderInfoService;
-import com.gree.mall.manager.plus.service.OrderTaxService;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.stereotype.Component;
-
-import java.util.Calendar;
-import java.util.List;
-
-@ConditionalOnProperty(name = "schedule.enable", havingValue = "true", matchIfMissing = true)
-@Slf4j
-@Component
-public class TaxSchedule {
-    @Autowired
-    private TaxLogic taxLogic;
-    @Autowired
-    private OrderInfoService orderInfoService;
-    @Autowired
-    private OrderTaxService orderTaxService;
-
-    @Scheduled(fixedDelay = 5 * 60 * 1000)
-    public void orderShareTask() {
-        List<OrderTax> OrderTaxList = orderTaxService.lambdaQuery()
-                .eq(OrderTax::getStatus,false)
-                .list();
-
-        for (OrderTax orderTax : OrderTaxList) {
-            OrderInfo orderInfo = orderInfoService.getById(orderTax.getOrderId());
-            if(orderInfo==null||!orderInfo.getOrderStatus().equals(OrderStatusEnum.OVER.toString())){
-                continue;
-            }
-            taxLogic.taxHttp(orderTax.getOrderId());
-        }
-    }
-
-}