lisai17@sina.com 2021-04-15 22:10:59 +08:00
commit 7aad6997bf
3 changed files with 76 additions and 21 deletions

View File

@ -165,7 +165,7 @@ public class PrepayService {
* @param etm
* @return
*/
public List<Record> consumption(Integer customer_id, Integer supermarket_id, String stm, String etm, String truck_license) {
public List<Record> consumption(Integer customer_id, Integer supermarket_id, String stm, String etm, String truck_license,Integer invoice_type) {
String sale_sql = " select t.sn, t.supermarket_id, t.truck_license, t.weight, t.total_price, t.paid, t.customer_id, t.customer_name, t.create_time \n" +
" from order_sale t \n" +
" left join customer c on c.id = t.customer_id \n" +
@ -201,6 +201,13 @@ public class PrepayService {
tempList.add(supermarket_id);
}
if (invoice_type!=null) {
sale_sql += " and t.invoice_type = ?";
saleList.add(invoice_type);
temp_sql += " and t.invoice_type = ?";
tempList.add(invoice_type);
}
if (customer_id != null && customer_id > 0) {
sale_sql += " and t.customer_id = ?";
saleList.add(customer_id);
@ -244,7 +251,7 @@ public class PrepayService {
return Db.find(sql, paraList.toArray());
}
public Workbook consumptionExport(Integer customer_id, Integer supermarket_id, String stm, String etm, String truck_license) {
public Workbook consumptionExport(Integer customer_id, Integer supermarket_id, String stm, String etm, String truck_license,Integer invoice_type) {
Customer customer = Customer.dao.findById(customer_id);
String cname = "";
@ -252,7 +259,7 @@ public class PrepayService {
cname = customer.getName();
}
List<Record> list = consumption(customer_id, supermarket_id, stm, etm, truck_license);
List<Record> list = consumption(customer_id, supermarket_id, stm, etm, truck_license,invoice_type);
list.sort(new Comparator<Record>() {
public int compare(Record o1, Record o2) {

View File

@ -1839,8 +1839,8 @@ public class OrderStatService {
return wb;
}
public Workbook trafficStatisticsOfEachSandStationExport(String stm, String etm){
List<Record> list=trafficStatisticsOfEachSandStation(stm, etm);
public Workbook trafficStatisticsOfEachSandStationExport(String stm, String etm,Integer invoice_type){
List<Record> list=trafficStatisticsOfEachSandStation(stm, etm,invoice_type);
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet(stm.substring(0, 10) + " ~ " + etm.substring(0, 10) + "各砂站运输量统计表");
@ -1953,22 +1953,22 @@ public class OrderStatService {
/**
*
*/
public List<Record> trafficStatisticsOfEachSandStation( String stm, String etm){
public List<Record> trafficStatisticsOfEachSandStation( String stm, String etm,Integer invoice_type){
List<Record> dataList = new ArrayList<>();
//零散用户统计
Record scattered=scatteredUsersAreNotClassified(stm,etm);
Record scattered=scatteredUsersAreNotClassified(stm,etm,invoice_type);
if(scattered.getBigDecimal("weight").compareTo(new BigDecimal("0"))>0||scattered.getBigDecimal("total_price").compareTo(new BigDecimal("0"))>0){
Record scatteredSandStation=scatteredUsersClassificationStatistics(stm,etm);
Record scatteredSandStation=scatteredUsersClassificationStatistics(stm,etm,invoice_type);
scattered.setColumns(scatteredSandStation);
dataList.add(scattered);
}
//固定用户统计
List<Record> recordList = fixedUserUnclassified(stm,etm);
List<Record> recordList = fixedUserUnclassified(stm,etm,invoice_type);
if(recordList!=null&&!recordList.isEmpty()){
for (Record record : recordList) {
if(record.getBigDecimal("weight").compareTo(new BigDecimal("0"))>0||record.getBigDecimal("total_price").compareTo(new BigDecimal("0"))>0){
Integer customer_id=record.getInt("customer_id");
Record sandStation=fixedUserClassificationStatistics(stm, etm,customer_id);
Record sandStation=fixedUserClassificationStatistics(stm, etm,customer_id,invoice_type);
record.setColumns(sandStation);
}
}
@ -1982,7 +1982,11 @@ public class OrderStatService {
/**
*
*/
public List<Record> fixedUserUnclassified(String stm, String etm){
public List<Record> fixedUserUnclassified(String stm, String etm,Integer invoice_type){
String paramsSql="";
if(invoice_type!=null){
paramsSql="and t.invoice_type=?\n";
}
String sql="SELECT\n" +
"a.customer_name,\n" +
" a.customer_id,\n" +
@ -2003,6 +2007,7 @@ public class OrderStatService {
"t.state = 5 \n" +
"AND t.create_time >=? \n" +
"AND t.create_time <=? \n" +
paramsSql+
"AND t.isprepaid = 1 UNION\n" +
"SELECT\n" +
"t.sn,t.customer_id,\n" +
@ -2017,12 +2022,20 @@ public class OrderStatService {
"t.state = 5 \n" +
"AND t.create_time >=? \n" +
"AND t.create_time <=? \n" +
paramsSql+
"AND t.isprepaid = 1 \n" +
") a\n" +
" JOIN customer c ON c.id = a.customer_id \n" +
"GROUP BY\n" +
"a.customer_id,a.customer_name";
List<Record> recordList = Db.find(sql, stm, etm, stm, etm);
List<Record> recordList;
if(invoice_type!=null){
recordList = Db.find(sql, stm, etm,invoice_type, stm, etm,invoice_type);
}else {
recordList = Db.find(sql, stm, etm, stm, etm);
}
return recordList;
}
@ -2030,7 +2043,11 @@ public class OrderStatService {
*
* @return
*/
public Record fixedUserClassificationStatistics(String stm, String etm,Integer customer_id){
public Record fixedUserClassificationStatistics(String stm, String etm,Integer customer_id,Integer invoice_type){
String paramsSql="";
if(invoice_type!=null){
paramsSql="and t.invoice_type=?\n";
}
String sql="SELECT\n" +
"ifnull( sum( CASE g.id WHEN 1 THEN g.weight END ), 0.00 ) zw_xsl,\n" +
"ifnull( sum( CASE g.id WHEN 1 THEN g.total_price END ), 0.00 ) zw_xse,\n" +
@ -2081,6 +2098,7 @@ public class OrderStatService {
"t.state = 5 \n" +
"AND t.create_time >=? \n" +
"AND t.create_time <=? \n" +
paramsSql+
"AND t.isprepaid = 1 UNION\n" +
"SELECT\n" +
"t.sn,t.supermarket_id AS id,\n" +
@ -2096,6 +2114,7 @@ public class OrderStatService {
"t.state = 5 \n" +
"AND t.create_time >=? \n" +
"AND t.create_time <=? \n" +
paramsSql+
"AND t.isprepaid = 1 \n" +
") a\n" +
"JOIN customer c ON c.id = a.customer_id \n" +
@ -2107,13 +2126,22 @@ public class OrderStatService {
") g \n" +
"GROUP BY\n" +
"g.customer_id";
Record record = Db.findFirst(sql, stm,etm, stm,etm, customer_id);
Record record;
if(invoice_type!=null){
record = Db.findFirst(sql, stm,etm,invoice_type, stm,etm,invoice_type, customer_id);
}else {
record = Db.findFirst(sql, stm,etm, stm,etm, customer_id);
}
return total(record);
}
/**
*
*/
public Record scatteredUsersAreNotClassified(String stm, String etm){
public Record scatteredUsersAreNotClassified(String stm, String etm,Integer invoice_type){
String paramsSql="";
if(invoice_type!=null){
paramsSql="and t.invoice_type=?\n";
}
String sql="SELECT '零散用户' customer_name, 0 customer_id,\n" +
"ifnull(sum( a.weight ),0) weight,\n" +
"ifnull(sum( a.total_price ),0) total_price\n" +
@ -2129,6 +2157,7 @@ public class OrderStatService {
"t.state = 5 \n" +
"AND t.create_time >=?\n" +
"AND t.create_time <=?\n" +
paramsSql+
"AND t.isprepaid = 0 UNION\n" +
"SELECT\n" +
"t.sn,t.weight,\n" +
@ -2140,9 +2169,16 @@ public class OrderStatService {
"t.state = 5 \n" +
"AND t.create_time >=?\n" +
"AND t.create_time <=?\n" +
paramsSql+
"AND t.isprepaid = 0 \n" +
") a";
Record record = Db.findFirst(sql, stm, etm, stm, etm);
Record record;
if(invoice_type!=null){
record = Db.findFirst(sql, stm, etm,invoice_type, stm, etm,invoice_type);
}else {
record = Db.findFirst(sql, stm, etm, stm, etm);
}
return record;
}
@ -2152,7 +2188,11 @@ public class OrderStatService {
* @param etm
* @return
*/
public Record scatteredUsersClassificationStatistics(String stm, String etm){
public Record scatteredUsersClassificationStatistics(String stm, String etm,Integer invoice_type){
String paramsSql="";
if(invoice_type!=null){
paramsSql="and t.invoice_type=?\n";
}
String sql="select \n" +
"ifnull( sum( CASE g.id WHEN 1 THEN IFNULL( g.weight, 0 ) END ), 0 ) zw_xsl,\n" +
"ifnull( sum( CASE g.id WHEN 1 THEN IFNULL( g.total_price, 0 ) END ), 0 ) zw_xse,\n" +
@ -2185,6 +2225,7 @@ public class OrderStatService {
"t.state = 5 \n" +
"AND t.create_time >=? \n" +
"AND t.create_time <=? \n" +
paramsSql+
"AND t.isprepaid = 0 UNION\n" +
"SELECT\n" +
"t.sn,t.supermarket_id AS id,\n" +
@ -2196,9 +2237,16 @@ public class OrderStatService {
"t.state = 5 \n" +
"AND t.create_time >=? \n" +
"AND t.create_time <=? \n" +
paramsSql+
"AND t.isprepaid = 0 ) n on m.id=n.id\n" +
") g";
Record record = Db.findFirst(sql, stm,etm, stm,etm);
Record record;
if(invoice_type!=null) {
record = Db.findFirst(sql, stm,etm,invoice_type, stm,etm,invoice_type);
}else {
record = Db.findFirst(sql, stm,etm, stm,etm);
}
return total(record);
}

View File

@ -30,11 +30,11 @@ public class PrepayController extends BaseController {
String stm = get("stm");
String etm = get("etm");
String truck_license = get("truck_license");
Integer invoice_type = getInt("invoice_type");
if (export == 0) {
renderJson(Result.success(PrepayService.me.consumption(customer_id, supermarket_id, stm, etm, truck_license)));
renderJson(Result.success(PrepayService.me.consumption(customer_id, supermarket_id, stm, etm, truck_license,invoice_type)));
} else {
Workbook wb = PrepayService.me.consumptionExport(customer_id, supermarket_id, stm, etm, truck_license);
Workbook wb = PrepayService.me.consumptionExport(customer_id, supermarket_id, stm, etm, truck_license,invoice_type);
render(new ExcelRender("消费记录_" + System.currentTimeMillis() + ".xlsx", wb));
}
}