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.

216 lines
8.4 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.mapper.CustomMapper;
6 years ago
import com.gszc.mapper.InvoiceHeaderMapper;
import com.gszc.mapper.InvoiceMapper;
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;
6 years ago
import java.time.LocalDateTime;
import java.util.ArrayList;
6 years ago
import java.util.Date;
6 years ago
import java.util.List;
import java.util.UUID;
/**
* <p>
*
* </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
public void addInvoice(Invoice invoice){
6 years ago
String id = Uuid8Utils.generateShortUUID();
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;
6 years ago
JSONObject jsonObject = countService.VATCount("4", "1", ""+custom.getRegisterType(), money.doubleValue());
BigDecimal money1 = jsonObject.getBigDecimal("money");
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<>();
6 years ago
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"));
6 years ago
if(null==type){
}else if(type.equals("disable")){
customId.eq("status_code","disable");
}else if(type.equals("enable")){
customId.eq("status_code","enable");
}
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){
list.addAll(invoiceList);
}
}
return list;
}
public JSONObject invoiceDetail(String invoiceId){
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());
6 years ago
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);
6 years ago
invoiceHeader.setCreateDate(new Date());
invoiceHeader.setModifyDate(new Date());
6 years ago
invoiceHeaderMapper.insert(invoiceHeader);
}
public void updateInvoiceHeader(InvoiceHeader invoiceHeader){
6 years ago
invoiceHeader.setModifyDate(new Date());
6 years ago
invoiceHeaderMapper.updateById(invoiceHeader);
}
public void deleteInvoiceHeader(String invoiceHeaderId){
6 years ago
if(invoiceMapper.selectCount(new EntityWrapper<Invoice>().eq("invoice_header_id", invoiceHeaderId))>0){
throw new RuntimeException("抬头已被使用");
}
6 years ago
invoiceHeaderMapper.deleteById(invoiceHeaderId);
}
public InvoiceHeader invoiceHeaderDetail(String invoiceHeaderId){
InvoiceHeader invoiceHeader = invoiceHeaderMapper.selectById(invoiceHeaderId);
return invoiceHeader;
}
6 years ago
public JSONObject pcDisableInvoiceList(Integer pageNum,Integer pageSize){
Integer count = invoiceMapper.selectCount(new EntityWrapper<Invoice>().eq("status_code", "disable"));
6 years ago
List<Invoice> invoiceList = invoiceMapper.selectPage(new RowBounds((pageNum-1)*pageSize,pageSize),new EntityWrapper<Invoice>().eq("status_code", "disable").orderBy("create_date",false));
6 years ago
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());
}
6 years ago
JSONObject jsonObject = new JSONObject();
jsonObject.put("count",count);
jsonObject.put("invoiceList",invoiceList);
return jsonObject;
6 years ago
}
6 years ago
public JSONObject pcEnableInvoiceList(Integer pageNum,Integer pageSize){
Integer count = invoiceMapper.selectCount(new EntityWrapper<Invoice>().eq("status_code", "enable"));
6 years ago
List<Invoice> invoiceList = invoiceMapper.selectPage(new RowBounds((pageNum-1)*pageSize,pageSize),new EntityWrapper<Invoice>().eq("status_code", "enable").orderBy("create_date",false));
6 years ago
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());
}
6 years ago
JSONObject jsonObject = new JSONObject();
jsonObject.put("count",count);
jsonObject.put("invoiceList",invoiceList);
return jsonObject;
6 years ago
}
public void invoiceConfirm(String invoiceId,String trackingCompany,String trackingCode,String trackingImg){
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);
invoice.setTrackingImg(trackingImg);
invoiceMapper.updateById(invoice);
}
6 years ago
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;
}
6 years ago
}