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