|
|
@@ -6,6 +6,7 @@ import com.ruoyi.common.core.utils.StringUtils;
|
|
|
import com.ruoyi.common.redis.service.RedisIdGenerator;
|
|
|
import com.ruoyi.logistics.config.InvoiceConfig;
|
|
|
import com.ruoyi.logistics.domain.InvoiceRequest;
|
|
|
+import com.ruoyi.logistics.domain.OrderRequest;
|
|
|
import com.ruoyi.logistics.domain.RptFinancialMonthSummary;
|
|
|
import com.ruoyi.logistics.service.IRptFinancialMonthSummaryService;
|
|
|
import com.ruoyi.logistics.service.InvoiceService;
|
|
|
@@ -20,10 +21,16 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import java.math.BigDecimal;
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
/**
|
|
|
* 开票相关接口
|
|
|
@@ -41,6 +48,8 @@ public class InvoiceServiceImpl implements InvoiceService {
|
|
|
private InvoiceConfig invoiceConfig;
|
|
|
@Autowired
|
|
|
JdbcTemplate jdbcTemplate;
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
|
|
|
@Autowired
|
|
|
private IRptFinancialMonthSummaryService rptFinancialMonthSummaryService;
|
|
|
@@ -119,6 +128,12 @@ public class InvoiceServiceImpl implements InvoiceService {
|
|
|
rptFinancialMonthSummary.setStatus("3");
|
|
|
rptFinancialMonthSummary.setBwDjbh(djbh);
|
|
|
rptFinancialMonthSummary.setSummaryId(invoiceRequest.getSummaryId());
|
|
|
+ LocalDate now = LocalDate.now();
|
|
|
+ // 定义格式:yyyy-MM-dd
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ // 转成字符串
|
|
|
+ String dateStr = now.format(formatter);
|
|
|
+ rptFinancialMonthSummary.setKprq(dateStr);
|
|
|
rptFinancialMonthSummaryService.updateRptFinancialMonthSummary(rptFinancialMonthSummary);
|
|
|
}
|
|
|
|
|
|
@@ -183,4 +198,62 @@ public class InvoiceServiceImpl implements InvoiceService {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map returnShop( InvoiceRequest invoiceRequest) throws JsonProcessingException {
|
|
|
+ //找到月度账单中已开票的单据
|
|
|
+ List<Map<String,Object>> invoiceList= jdbcTemplate.queryForList(" SELECT summary_id,payable_amount ,bw_djbh,kprq,dept_name,invoice_name,dept_code,leader FROM rpt_financial_month_summary a left join sys_dept b on a.dept_id=b.dept_id where a.summary_id=? ",invoiceRequest.getSummaryId());
|
|
|
+ if(invoiceList.size()==0){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Map map=invoiceList.get(0);
|
|
|
+ String url = invoiceConfig.getShopUrl();
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ BigDecimal free= new BigDecimal(map.get("payable_amount").toString());
|
|
|
+ OrderRequest request = new OrderRequest();
|
|
|
+ request.setOrderNumber(map.get("bw_djbh").toString());
|
|
|
+ request.setSkuId("787");
|
|
|
+ request.setGzTime(map.get("kprq").toString());
|
|
|
+ request.setOutCode("3204");
|
|
|
+ request.setUserId(map.get("leader").toString());
|
|
|
+ request.setUserCompanyName(map.get("invoice_name").toString());
|
|
|
+ request.setSapCode(map.get("dept_code").toString());
|
|
|
+ request.setShopName(map.get("dept_name").toString());
|
|
|
+ request.setPayType(1);
|
|
|
+ request.setProdName("快递服务");
|
|
|
+ request.setProdCount("1");
|
|
|
+ request.setBuyMoney(free); //销售金额 含税
|
|
|
+ request.setBuyPrice(free); //采购单价 含税
|
|
|
+ request.setSaleMoney(free); // 销售金额 含税
|
|
|
+ request.setPurchaseRate(BigDecimal.valueOf(0.06)); //进项税率
|
|
|
+ request.setPrice(free); //销售单价 含税
|
|
|
+ BigDecimal[] result =TaxAmountCalculator.calculateFromTaxIncluded(free, BigDecimal.valueOf(0.06));
|
|
|
+ request.setBuyMoneyNoTax(result[0]); // 采购金额(不含税)
|
|
|
+ request.setJxse(result[1]); //进项税额
|
|
|
+ BigDecimal[] result1 =TaxAmountCalculator.calculateFromTaxIncluded(free, BigDecimal.valueOf(0.06));
|
|
|
+ request.setOutputRate(BigDecimal.valueOf(0.06)); // 销项税率
|
|
|
+ request.setXxse(result1[1]); //销项税额
|
|
|
+ HttpEntity<OrderRequest> entity = new HttpEntity<>(request, headers);
|
|
|
+ // ✅ postForEntity
|
|
|
+ ResponseEntity<String> response = restTemplate.postForEntity(url, entity, String.class);
|
|
|
+
|
|
|
+
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Map<String, Object> shopMap = objectMapper.readValue(
|
|
|
+ response.getBody(),
|
|
|
+ new TypeReference<Map<String, Object>>() {}
|
|
|
+ );
|
|
|
+ if("0".equals(shopMap.get("code").toString())){
|
|
|
+ //这里成功后也要将单据编号进行回传月度报表
|
|
|
+ RptFinancialMonthSummary rptFinancialMonthSummary= new RptFinancialMonthSummary();
|
|
|
+ rptFinancialMonthSummary.setStatus("4");
|
|
|
+ rptFinancialMonthSummary.setSummaryId(invoiceRequest.getSummaryId());
|
|
|
+ rptFinancialMonthSummaryService.updateRptFinancialMonthSummary(rptFinancialMonthSummary);
|
|
|
+ }
|
|
|
+ return shopMap;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|