You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

313 lines
13 KiB
Java

6 years ago
package com.gszc.service.impl;
6 years ago
import com.alibaba.fastjson.JSONArray;
6 years ago
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
6 years ago
import com.baomidou.mybatisplus.mapper.Wrapper;
6 years ago
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.gszc.entity.Custom;
import com.gszc.entity.Invoice;
import com.gszc.entity.InvoiceHeader;
6 years ago
import com.gszc.entity.PcUser;
6 years ago
import com.gszc.mapper.CustomMapper;
6 years ago
import com.gszc.mapper.InvoiceHeaderMapper;
import com.gszc.mapper.InvoiceMapper;
6 years ago
import com.gszc.mapper.PcUserMapper;
6 years ago
import com.gszc.service.CountService;
6 years ago
import com.gszc.service.IInvoiceService;
6 years ago
import com.gszc.util.KdniaoTrackQueryAPI;
6 years ago
import com.gszc.util.Uuid8Utils;
6 years ago
import org.apache.ibatis.session.RowBounds;
6 years ago
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
6 years ago
import org.springframework.transaction.annotation.Transactional;
6 years ago
6 years ago
import java.math.BigDecimal;
5 years ago
import java.util.*;
6 years ago
import java.util.stream.Collectors;
6 years ago
/**
* <p>
6 years ago
*
6 years ago
* </p>
*
* @author ky
* @since 2020-04-27
*/
@Service
6 years ago
@Transactional
6 years ago
public class InvoiceServiceImpl extends ServiceImpl<InvoiceMapper, Invoice> implements IInvoiceService {
@Autowired
InvoiceMapper invoiceMapper;
@Autowired
InvoiceHeaderMapper invoiceHeaderMapper;
@Autowired
CustomServiceImpl customService;
6 years ago
@Autowired
CustomMapper customMapper;
6 years ago
@Autowired
CountService countService;
6 years ago
@Autowired
PcUserMapper pcUserMapper;
6 years ago
public void addInvoice(Invoice invoice) {
5 years ago
String id = String.format("%06d",new Random().nextInt(999999)+1);
Invoice isHave = invoiceMapper.selectById(id);
while(null!=isHave){
id = String.format("%06d",new Random().nextInt(999999)+1);
isHave = invoiceMapper.selectById(id);
}
6 years ago
invoice.setId(id);
invoice.setStatusCode("disable");
6 years ago
invoice.setCreateDate(new Date());
invoice.setModifyDate(new Date());
6 years ago
BigDecimal money = invoice.getMoney();
String customId = invoice.getCustomId();
Custom custom = customMapper.selectById(customId);
try {
6 years ago
String companyType;
String invoiceType;
String taxType;
5 years ago
// JSONObject jsonObject = countService.VATCount(custom.getRegisterType(), invoice.getInvoiceType(), "1", money.doubleValue());
JSONObject jsonObject = countService.VATSurchargeCount(money.toString());
BigDecimal money1 = jsonObject.getBigDecimal("result");
6 years ago
invoice.setTaxMoney(money1.toString());
} catch (Exception e) {
e.printStackTrace();
}
6 years ago
invoiceMapper.insert(invoice);
}
6 years ago
public List<Invoice> invoiceList(String userId, String type) {
6 years ago
List<Invoice> list = new ArrayList<>();
5 years ago
JSONArray customs = customService.customList(userId, "all");
6 years ago
for (int i = 0; i < customs.size(); i++) {
6 years ago
Wrapper<Invoice> customId = new EntityWrapper<Invoice>().eq("custom_id", customs.getJSONObject(i).getJSONObject("custom").getString("id"));
6 years ago
if (null == type) {
6 years ago
6 years ago
} else if (type.equals("disable")) {
customId.eq("status_code", "disable");
} else if (type.equals("enable")) {
customId.eq("status_code", "enable");
6 years ago
}
6 years ago
customId.orderBy("create_date", false);
6 years ago
List<Invoice> invoiceList = invoiceMapper.selectList(customId);
6 years ago
for (Invoice invoice : invoiceList) {
6 years ago
invoice.setCustomName(customs.getJSONObject(i).getJSONObject("custom").getString("companyName"));
invoice.setCustomType(customs.getJSONObject(i).getJSONObject("custom").getString("registerType"));
6 years ago
String invoiceHeaderId = invoice.getInvoiceHeaderId();
InvoiceHeader invoiceHeader = invoiceHeaderMapper.selectById(invoiceHeaderId);
6 years ago
6 years ago
invoice.setInvoiceHeaderName(invoiceHeader.getCompanyName());
invoice.setTaxCode(invoiceHeader.getTaxCode());
}
6 years ago
if (invoiceList.size() > 0) {
6 years ago
list.addAll(invoiceList);
}
}
return list;
}
6 years ago
public JSONObject invoiceDetail(String invoiceId) {
6 years ago
JSONObject jsonObject = new JSONObject();
Invoice invoice = invoiceMapper.selectById(invoiceId);
6 years ago
String customId = invoice.getCustomId();
Custom custom = customMapper.selectById(customId);
invoice.setCustomName(custom.getCompanyName());
5 years ago
invoice.setCustomSocialCreditCode(custom.getSocialCreditCode());
6 years ago
InvoiceHeader invoiceHeader = invoiceHeaderMapper.selectById(invoice.getInvoiceHeaderId());
6 years ago
jsonObject.put("invoice", invoice);
jsonObject.put("invoiceHeader", invoiceHeader);
6 years ago
return jsonObject;
}
6 years ago
public List<InvoiceHeader> invoiceHeaderList(String userId) {
6 years ago
List<InvoiceHeader> invoiceHeaderList = invoiceHeaderMapper.selectList(new EntityWrapper<InvoiceHeader>().eq("mini_user_id", userId));
return invoiceHeaderList;
}
6 years ago
public void addInvoiceHeader(InvoiceHeader invoiceHeader) {
6 years ago
String uuid = UUID.randomUUID().toString();
invoiceHeader.setId(uuid);
6 years ago
invoiceHeader.setCreateDate(new Date());
invoiceHeader.setModifyDate(new Date());
6 years ago
invoiceHeaderMapper.insert(invoiceHeader);
}
6 years ago
public void updateInvoiceHeader(InvoiceHeader invoiceHeader) {
6 years ago
invoiceHeader.setModifyDate(new Date());
6 years ago
invoiceHeaderMapper.updateById(invoiceHeader);
}
6 years ago
public void deleteInvoiceHeader(String invoiceHeaderId) {
6 years ago
6 years ago
if (invoiceMapper.selectCount(new EntityWrapper<Invoice>().eq("invoice_header_id", invoiceHeaderId)) > 0) {
6 years ago
throw new RuntimeException("抬头已被使用");
}
6 years ago
invoiceHeaderMapper.deleteById(invoiceHeaderId);
}
6 years ago
public InvoiceHeader invoiceHeaderDetail(String invoiceHeaderId) {
6 years ago
InvoiceHeader invoiceHeader = invoiceHeaderMapper.selectById(invoiceHeaderId);
return invoiceHeader;
}
6 years ago
public JSONObject pcDisableInvoiceList(Integer pageNum, Integer pageSize, String copycatId) {
5 years ago
Integer count = 0;
List<Invoice> invoiceList = new ArrayList<>();
6 years ago
if (null == copycatId) {
count = invoiceMapper.selectCount(new EntityWrapper<Invoice>().eq("status_code", "disable"));
invoiceList = invoiceMapper.selectPage(new RowBounds((pageNum - 1) * pageSize, pageSize), new EntityWrapper<Invoice>().eq("status_code", "disable").orderBy("create_date", false));
} else {
List<Custom> customList = customMapper.selectList(new EntityWrapper<Custom>().eq("copycat_id", copycatId));
5 years ago
if (customList.size() != 0) {
count = invoiceMapper.selectCount(new EntityWrapper<Invoice>().eq("status_code", "disable").in("custom_id", customList.stream().map(item ->
item.getId()
).collect(Collectors.toList())));
invoiceList = invoiceMapper.selectPage(new RowBounds((pageNum - 1) * pageSize, pageSize), new EntityWrapper<Invoice>().eq("status_code", "disable").in("custom_id", customList.stream().map(item ->
item.getId()
).collect(Collectors.toList())).orderBy("create_date", false));
}
6 years ago
}
6 years ago
6 years ago
for (Invoice invoice : invoiceList) {
6 years ago
String invoiceHeaderId = invoice.getInvoiceHeaderId();
String customId = invoice.getCustomId();
Custom custom = customMapper.selectById(customId);
InvoiceHeader invoiceHeader = invoiceHeaderMapper.selectById(invoiceHeaderId);
invoice.setCustomName(custom.getCompanyName());
invoice.setInvoiceHeaderName(invoiceHeader.getCompanyName());
5 years ago
if (null != custom.getCopycatId()) {
6 years ago
PcUser pcUser = pcUserMapper.selectById(custom.getCopycatId());
6 years ago
invoice.setCopycatName(pcUser.getName());
}
6 years ago
}
6 years ago
JSONObject jsonObject = new JSONObject();
6 years ago
jsonObject.put("count", count);
jsonObject.put("invoiceList", invoiceList);
6 years ago
return jsonObject;
6 years ago
}
5 years ago
public JSONObject pcEnableInvoiceList(Integer pageNum, Integer pageSize, String copycatId,String keyword,Long beginTime,Long endTime) {
6 years ago
Integer count = null;
5 years ago
List<Invoice> invoiceList = new ArrayList<>();
6 years ago
5 years ago
Wrapper<Invoice> invoiceWrapper = new EntityWrapper<Invoice>().eq("status_code", "enable");
6 years ago
if (null == copycatId) {
5 years ago
Wrapper<Custom> wrapper = new EntityWrapper<Custom>();
if(null!=keyword){
wrapper.like("company_name",keyword);
}
if(null!=beginTime){
5 years ago
invoiceWrapper.ge("create_date",new Date(beginTime));
5 years ago
}
if(null!=endTime){
5 years ago
invoiceWrapper.le("create_date",new Date(endTime));
5 years ago
}
List<Custom> customList = customMapper.selectList(wrapper);
if (customList.size() != 0) {
5 years ago
count = invoiceMapper.selectCount(invoiceWrapper.in("custom_id", customList.stream().map(item ->
5 years ago
item.getId()
).collect(Collectors.toList())));
5 years ago
invoiceList = invoiceMapper.selectPage(new RowBounds((pageNum - 1) * pageSize, pageSize), invoiceWrapper.in("custom_id", customList.stream().map(item ->
5 years ago
item.getId()
).collect(Collectors.toList())).orderBy("create_date", false));
}
5 years ago
6 years ago
} else {
5 years ago
Wrapper<Custom> wrapper = new EntityWrapper<Custom>().eq("copycat_id", copycatId);
if(null!=keyword){
wrapper.like("company_name",keyword);
}
if(null!=beginTime){
5 years ago
invoiceWrapper.ge("create_date",new Date(beginTime));
5 years ago
}
if(null!=endTime){
5 years ago
invoiceWrapper.le("create_date",new Date(endTime));
5 years ago
}
List<Custom> customList = customMapper.selectList(wrapper);
5 years ago
if (customList.size() != 0) {
5 years ago
count = invoiceMapper.selectCount(invoiceWrapper.in("custom_id", customList.stream().map(item ->
5 years ago
item.getId()
).collect(Collectors.toList())));
5 years ago
invoiceList = invoiceMapper.selectPage(new RowBounds((pageNum - 1) * pageSize, pageSize), invoiceWrapper.in("custom_id", customList.stream().map(item ->
5 years ago
item.getId()
).collect(Collectors.toList())).orderBy("create_date", false));
}
6 years ago
}
for (Invoice invoice : invoiceList) {
6 years ago
String invoiceHeaderId = invoice.getInvoiceHeaderId();
5 years ago
InvoiceHeader invoiceHeader = invoiceHeaderMapper.selectById(invoiceHeaderId);
6 years ago
String customId = invoice.getCustomId();
Custom custom = customMapper.selectById(customId);
invoice.setCustomName(custom.getCompanyName());
invoice.setInvoiceHeaderName(invoiceHeader.getCompanyName());
5 years ago
if (null != custom.getCopycatId()) {
6 years ago
PcUser pcUser = pcUserMapper.selectById(custom.getCopycatId());
6 years ago
invoice.setCopycatName(pcUser.getName());
}
6 years ago
}
6 years ago
JSONObject jsonObject = new JSONObject();
6 years ago
jsonObject.put("count", count);
jsonObject.put("invoiceList", invoiceList);
6 years ago
return jsonObject;
6 years ago
}
6 years ago
public void invoiceConfirm(String invoiceId, String trackingCompany, String trackingCode, String invoiceImg) {
6 years ago
Invoice invoice = new Invoice();
invoice.setId(invoiceId);
invoice.setStatusCode("enable");
6 years ago
invoice.setModifyDate(new Date());
6 years ago
invoice.setTrackingCompany(trackingCompany);
invoice.setTrackingCode(trackingCode);
6 years ago
invoice.setInvoiceImg(invoiceImg);
6 years ago
invoiceMapper.updateById(invoice);
}
6 years ago
public JSONObject trackingDetail(String trackingCompany, String trackingCode) {
6 years ago
KdniaoTrackQueryAPI api = new KdniaoTrackQueryAPI();
JSONObject orderTracesByJson = new JSONObject();
try {
6 years ago
String orderTracesByJsonString = api.getOrderTracesByJson(trackingCompany, trackingCode);
orderTracesByJson = JSONObject.parseObject(orderTracesByJsonString);
6 years ago
} catch (Exception e) {
e.printStackTrace();
return orderTracesByJson;
}
return orderTracesByJson;
}
5 years ago
public JSONObject queryInvoiceCount(String copycatId) {
Integer count = null;
if (null == copycatId) {
count = invoiceMapper.selectCount(new EntityWrapper<Invoice>().eq("status_code", "disable"));
} else {
List<Custom> customList = customMapper.selectList(new EntityWrapper<Custom>().eq("copycat_id", copycatId));
count = invoiceMapper.selectCount(new EntityWrapper<Invoice>().eq("status_code", "disable").in("custom_id", customList.stream().map(item ->
item.getId()
).collect(Collectors.toList())));
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("count", count);
return jsonObject;
}
6 years ago
}