QueryService.java
40.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
package cn.csbr.app.service;
import cn.csbr.app.config.FxConfigure;
import cn.csbr.app.exception.ApiException;
import cn.csbr.app.gui.GUIContext;
import cn.csbr.app.model.InboundItem;
import cn.csbr.springboot.dao.mapper.*;
import cn.csbr.springboot.dao.model.*;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import java.math.BigDecimal;
import java.sql.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.csbr.mybatis.CommonMapper;
import com.github.pagehelper.Page;
/**
* 查询业务类
*/
@Service
@Log4j2
public class QueryService {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
@Autowired
private CommonMapper commonMapper;
@Autowired
private GoodsService goodsService;
@Autowired
private MfcubestockdetailMapper mfcubestockdetailMapper;
@Autowired
private FxConfigure fxConfigure;
@Autowired
private MfcubestockstatementMapper mfcubestockstatementMapper;
@Autowired
private TrchargingdetailMapper trchargingdetailMapper;
@Autowired
private TrchargingMapper trchargingMapper;
@Autowired
private MfcubestockdetailOldMapper mfcubestockdetailOldMapper;
@Autowired
private GUIContext guiContext;
@Autowired
private HisGoodsMapper hisGoodsMapper;
public synchronized Page<Map<String, Object>> queryStockData(Mfcubestockdetail detail) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String sql = "SELECT \n" +
" a.`guid`,\n" +
" a.`LabGuid`,\n" +
" a.`GoodsGUID`,\n" +
" g.`GoodsCode`,\n" +
" a.`GoodsName`,\n" +
" g.`GoodsSpec`,\n" +
" g.Producer,\n" +
" a.`Unit`,\n" +
" a.`SupplierGUID`,\n" +
" a.`SupplierName`,\n" +
" a.`Lot`,\n" +
" a.`Productiondate`,\n" +
" a.ExpireDate,\n" +
" TO_DAYS(a.ExpireDate) - TO_DAYS(NOW()) AS NearDay,\n" +
" a.`CubeGuid`,\n" +
" a.`CubeName`,\n" +
" a.`BillState`\n" +
"FROM\n" +
" Mfcubestockdetail AS a \n" +
" LEFT JOIN `his_goods` AS g \n" +
" ON a.`GoodsGUID` = g.`GUID` \n" ;
sql=sql+ " WHERE 1=1 ";
if (!StringUtils.isEmpty(detail.getGoodsName())) {
sql += " AND (g.GoodsCode like '%" + detail.getGoodsName() + "%' or a.GoodsName like '%" + detail.getGoodsName() + "%' or a.LabGuid like'%" + detail.getGoodsName() + "%')";
}
if (!StringUtils.isEmpty(detail.getSupplierName())) {
sql +=" AND a.suppliername like '%"+detail.getSupplierName()+"%'";
}
if(StringUtils.isNotEmpty(detail.getBillState())) {
sql +=" AND a.billstate = '"+detail.getBillState()+"'";
}
if(StringUtils.isNotEmpty(detail.getCubeGuid())) {
sql +=" AND a.CubeGuid = '"+detail.getCubeGuid()+"'";
}
if(StringUtils.isNotEmpty(detail.getDepotGuid())) {
//sql +=" AND a.CubeGuid = '"+detail.getCubeGuid()+"'";
sql=sql+" and a.depotGuid="+"'"+detail.getDepotGuid()+"'";
}
// sql +=" AND a.Depotname = '"+guiContext.getLoginUserVali().getOrgName()+"'";
if(detail.getExpireDate() !=null) {
sql +=" AND a.ExpireDate <= '"+ format.format(detail.getExpireDate()) +"'";
}
if(!StringUtils.isEmpty(fxConfigure.getCabinetGroupCode())) {
sql +=" and CubeGuid in (select guid from cabinet where groupcode='" + fxConfigure.getCabinetGroupCode() + "')";
}
if(StringUtils.isNotEmpty(detail.getCubeName())) {
sql +=" AND a.CubeName = '"+detail.getCubeName()+"'";
}
sql +=" ORDER BY a.`ExpireDate` ASC";
System.out.println("库存查询SQL:"+sql);
//endregion
Page<Map> list = (Page<Map>) commonMapper.queryList(sql);
List<Map<String, Object>> results = new ArrayList();
Page<Map<String, Object>> newresults = new Page<>();
newresults.setPageNum(list.getPageNum());
newresults.setPages(list.getPages());
newresults.setPageSize(list.getPageSize());
newresults.setTotal(list.getTotal());
for(Map map:list) {
Map<String, Object> result = BeanUtil.beanToMap(map);
result.putAll(map);
result.put("labguid",map.get("LabGuid").toString());
result.put("suppliername",map.get("SupplierName").toString());
result.put("cubename",map.get("CubeName").toString());
result.put("guid",map.get("guid").toString());
StringBuilder goodsInfo = new StringBuilder();
goodsInfo.append(map.get("GoodsCode")).append("\n")
.append(map.get("GoodsName")).append("\n")
.append(map.get("Unit"));
result.put("goodsInfo", goodsInfo.toString());
StringBuilder goodsguiginfo = new StringBuilder();
HisGoods hisGoods=hisGoodsMapper.selectByPrimaryKey(map.get("GoodsGUID"));
if(hisGoods!=null) {
goodsguiginfo.append(hisGoods.getGoodsspec()).append("\n").append(hisGoods.getModel());
result.put("gsd",hisGoods.getGoodsspec()+"("+hisGoods.getModel()+")");
}
result.put("goodsguiginfo",goodsguiginfo.toString());
result.put("days", map.get("NearDay").toString());
String lot = map.get("Lot").toString();
lot += "\n" + format.format(map.get("ExpireDate"));
result.put("lot", lot);
if(map.get("Producer")!=null)
result.put("goodsCount",map.get("Producer").toString());
results.add(result);
}
newresults.addAll(results);
return newresults;
}
public synchronized Page<Map<String, Object>> queryStockDataByPage(Mfcubestockdetail detail,int pagesize,int pageindex) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String sql = "SELECT \n" +
" a.`guid`,\n" +
" a.`LabGuid`,\n" +
" a.`GoodsGUID`,\n" +
" g.`GoodsCode`,\n" +
" a.`GoodsName`,\n" +
" g.`GoodsSpec`,\n" +
" g.Producer,\n" +
" a.`Unit`,\n" +
" a.`SupplierGUID`,\n" +
" a.`SupplierName`,\n" +
" a.`Lot`,\n" +
" a.`Productiondate`,\n" +
" a.ExpireDate,\n" +
" TO_DAYS(a.ExpireDate) - TO_DAYS(NOW()) AS NearDay,\n" +
" a.`CubeGuid`,\n" +
" a.`CubeName`,\n" +
" a.`BillState`\n" +
"FROM\n" +
" Mfcubestockdetail AS a \n" +
" LEFT JOIN `his_goods` AS g \n" +
" ON a.`GoodsGUID` = g.`GUID` \n" ;
sql=sql+ " WHERE 1=1 ";
if (!StringUtils.isEmpty(detail.getGoodsName())) {
sql += " AND (g.GoodsCode like '%" + detail.getGoodsName() + "%' or a.GoodsName like '%" + detail.getGoodsName() + "%' or a.LabGuid like'%" + detail.getGoodsName() + "%')";
}
if (!StringUtils.isEmpty(detail.getSupplierName())) {
sql +=" AND a.suppliername like '%"+detail.getSupplierName()+"%'";
}
if(StringUtils.isNotEmpty(detail.getBillState()) && !detail.getBillState().equals("%")) {
sql +=" AND a.billstate = '"+detail.getBillState()+"'";
}
if(StringUtils.isNotEmpty(detail.getCubeGuid())) {
sql +=" AND a.CubeGuid = '"+detail.getCubeGuid()+"'";
}
if(StringUtils.isNotEmpty(detail.getDepotGuid())) {
//sql +=" AND a.CubeGuid = '"+detail.getCubeGuid()+"'";
sql=sql+" and a.depotGuid="+"'"+detail.getDepotGuid()+"'";
}
// sql +=" AND a.Depotname = '"+guiContext.getLoginUserVali().getOrgName()+"'";
if(detail.getExpireDate() !=null) {
sql +=" AND a.ExpireDate <= '"+ format.format(detail.getExpireDate()) +"'";
}
if(!StringUtils.isEmpty(fxConfigure.getCabinetGroupCode())) {
sql +=" and CubeGuid in (select guid from cabinet where groupcode='" + fxConfigure.getCabinetGroupCode() + "')";
}
sql +=" ORDER BY a.`ExpireDate` ASC";
System.out.println("库存查询SQL:"+sql);
//endregion
Page<Map> list = (Page<Map>) commonMapper.queryList(sql);
List<Map<String, Object>> results = new ArrayList();
Page<Map<String, Object>> newresults = new Page<>();
newresults.setPageNum(list.getPageNum());
newresults.setPages(list.getPages());
newresults.setPageSize(list.getPageSize());
newresults.setTotal(list.getTotal());
for(Map map:list) {
System.out.println("map"+map);
System.out.println("map"+map.get("CubeName"));
Map<String, Object> result = BeanUtil.beanToMap(map);
result.put("labguid",map.get("LabGuid").toString());
result.put("suppliername",map.get("SupplierName").toString());
result.put("cubename",map.get("CubeName").toString());
result.put("guid",map.get("guid").toString());
StringBuilder goodsInfo = new StringBuilder();
System.out.println("test1");
goodsInfo.append(map.get("GoodsCode")).append("\n")
.append(map.get("GoodsName")).append("\n")
.append(map.get("Unit"));
result.put("goodsInfo", goodsInfo.toString());
StringBuilder goodsguiginfo = new StringBuilder();
HisGoods hisGoods=hisGoodsMapper.selectByPrimaryKey(map.get("GoodsGUID"));
System.out.println("test1");
if(hisGoods!=null) {
goodsguiginfo.append(hisGoods.getGoodsspec()).append("\n").append(hisGoods.getModel());
}
result.put("goodsguiginfo",goodsguiginfo.toString());
result.put("days", map.get("NearDay").toString());
String lot = map.get("Lot").toString();
lot += "\n" + format.format(map.get("ExpireDate"));
result.put("lot", lot);
if(map.get("Producer")!=null)
result.put("goodsCount",map.get("Producer").toString());
results.add(result);
}
newresults.addAll(results);
return newresults;
}
public synchronized Page<Map<String, Object>> queryStockStatementData(Mfcubestockstatement statement, String beginDate, String endDate, List<String> otype) {
System.out.println(statement.getGoodsname());
System.out.println(statement.getSuppliername());
System.out.println(beginDate);
System.out.println(endDate);
Example condition = new Example(Mfcubestockstatement.class);
Example.Criteria cr = condition.createCriteria().andEqualTo("billno", statement.getBillno());
//cr.andEqualTo("storeguid",guiContext.getStoreguid());
cr.andCondition(" 1 = 1 ");
if (!StringUtils.isEmpty(statement.getGoodsname())) {
statement.setGoodsname("%" + statement.getGoodsname() + "%");
String sql = " ( GoodsName like '" + statement.getGoodsname() + "' or LabGuid like'" + statement.getGoodsname() + "')";
cr.andCondition("(" + sql + ")");
}
if (!StringUtils.isEmpty(statement.getSuppliername())) {
cr.andLike("suppliername", "%" + statement.getSuppliername() + "%");
}
// if(!StringUtils.isEmpty(statement.getDepotguid())) {
// //term.append(" and depotGuid='" + statement.getDepotguid()+ "'");
// cr.andEqualTo("depotguid",statement.getDepotguid());
// }
cr.andCondition(" depotguid ='"+guiContext.getLoginUserVali().getOrgGuid()+"'");
System.out.println("--------------begin date:" + beginDate);
if (!StringUtils.isEmpty(beginDate)) {
cr.andGreaterThanOrEqualTo("createTime", beginDate);
}
if (!StringUtils.isEmpty(endDate)) {
cr.andLessThanOrEqualTo("createTime", endDate);
}
if (otype != null && otype.size() > 0) {
cr.andIn("type", otype);
}
cr.andEqualTo("cubeguid", statement.getCubeguid());
cr.andCondition(" CubeGuid in (select guid from cabinet where groupcode='" + fxConfigure.getCabinetGroupCode() + "')");
condition.orderBy("createTime").desc();
Page<Mfcubestockstatement> datas = (Page) mfcubestockstatementMapper.selectByExample(condition);
List<Map<String, Object>> results = new ArrayList();
Page<Map<String, Object>> newresults = new Page<>();
newresults.setPageNum(datas.getPageNum());
newresults.setPages(datas.getPages());
newresults.setPageSize(datas.getPageSize());
newresults.setTotal(datas.getTotal());
for (Mfcubestockstatement data : datas) {
Map<String, Object> result = BeanUtil.beanToMap(data);
StringBuilder goodsInfo = new StringBuilder();
goodsInfo.append(data.getGoodsname()).append("\n")
.append(data.getUnit());
result.put("goodsInfo", goodsInfo.toString());
String lot = data.getLot() + "\n" + df.format(data.getProductiondate()) + "\n" + df.format(data.getExpiredate());
result.put("lot", lot);
String type = data.getType();
StringBuilder goodsguiginfo = new StringBuilder();
HisGoods hisGoods=hisGoodsMapper.selectByPrimaryKey(data.getGoodsguid());
if(hisGoods!=null) {
goodsguiginfo.append(hisGoods.getGoodsspec()).append("\n").append(hisGoods.getModel());
}
result.put("goodsguiginfo",goodsguiginfo.toString());
// 1:、入库 2:出库 3:盘升 4:盘损 5:退货,6还货
switch (type) {
case "1":
result.put("typeTitle", "入库");
break;
case "2":
result.put("typeTitle", "取货");
break;
case "3":
result.put("typeTitle", "盘升");
break;
case "4":
result.put("typeTitle", "盘损");
break;
case "5":
result.put("typeTitle", "退货");
break;
case "6":
result.put("typeTitle", "还货");
break;
default:
result.put("typeTitle", "不详");
break;
}
results.add(result);
DatUserLog datUserLog=new DatUserLog();
}
newresults.addAll(results);
return newresults;
}
/**
* 操作记录查询
* @param statement
* @param beginDate
* @param endDate
* @param otype
* @return
*/
public synchronized Page<Map<String, Object>> queryStockStatementData(Mfcubestockstatement statement, LocalDate beginDate, LocalDate endDate, List<String> otype) {
Example condition = new Example(Mfcubestockstatement.class);
Example.Criteria cr = condition.createCriteria().andEqualTo("billno", statement.getBillno());
cr.andEqualTo("storeguid",guiContext.getStoreguid());
if (!StringUtils.isEmpty(statement.getGoodsname())) {
statement.setGoodsname("%" + statement.getGoodsname() + "%");
String sql = " GoodsName like '" + statement.getGoodsname() + "' or LabGuid like'" + statement.getGoodsname() + "'";
cr.andCondition("(" + sql + ")");
}
if(!StringUtils.isEmpty(statement.getDepotguid())) {
//term.append(" and depotGuid='" + statement.getDepotguid()+ "'");
cr.andEqualTo("depotguid",statement.getDepotguid());
}
//cr.andEqualTo("depotguid", guiContext.getLoginUserVali().getOrgGuid());
if (!StringUtils.isEmpty(statement.getSuppliername())) {
cr.andLike("suppliername", "%" + statement.getSuppliername() + "%");
}
System.out.println("--------------begin date:" + beginDate);
cr.andGreaterThanOrEqualTo("createTime", beginDate);
cr.andLessThanOrEqualTo("createTime", endDate);
if (otype != null && otype.size() > 0) {
cr.andIn("type", otype);
}
if (!StringUtils.isEmpty(statement.getCubeguid()))
cr.andEqualTo("cubeguid", statement.getCubeguid());
cr.andCondition(" CubeGuid in (select guid from cabinet where groupcode='" + fxConfigure.getCabinetGroupCode() + "')");
condition.orderBy("createTime").desc();
Page<Mfcubestockstatement> datas = (Page) mfcubestockstatementMapper.selectByExample(condition);
List<Map<String, Object>> results = new ArrayList();
Page<Map<String, Object>> newresults = new Page<>();
newresults.setPageNum(datas.getPageNum());
newresults.setPages(datas.getPages());
newresults.setPageSize(datas.getPageSize());
newresults.setTotal(datas.getTotal());
for (Mfcubestockstatement data : datas) {
Map<String, Object> result = BeanUtil.beanToMap(data);
StringBuilder goodsInfo = new StringBuilder();
goodsInfo.append(data.getGoodscode()).append("\n")
.append(data.getGoodsname()).append("\n")
.append(data.getUnit());
result.put("goodsInfo", goodsInfo.toString());
String lot = data.getLot() + "\n" + df.format(data.getExpiredate())+"\n"+ df.format(data.getProductiondate());
result.put("lot", lot);
//result.put("goodsCount",data.getQty().stripTrailingZeros().toPlainString());
result.put("goodsCount",data.getManufacturer());
StringBuilder goodsguiginfo = new StringBuilder();
HisGoods hisGoods=hisGoodsMapper.selectByPrimaryKey(data.getGoodsguid());
if(hisGoods!=null) {
goodsguiginfo.append(hisGoods.getGoodsspec()).append("(").append(hisGoods.getModel()).append(")");
}
result.put("goodsguiginfo",goodsguiginfo.toString());
result.put("czsj",df.format(data.getCreateTime()));
String type = data.getType();
// 1:入库 2:出库 3:盘升 4:盘损 5:退货,6还货
switch (type) {
case "1":
result.put("typeTitle", "入库");
break;
case "2":
result.put("typeTitle", "取货");
break;
case "3":
result.put("typeTitle", "报溢");
break;
case "4":
result.put("typeTitle", "报损");
break;
case "5":
result.put("typeTitle", "退货");
break;
case "6":
result.put("typeTitle", "还货");
break;
default:
result.put("typeTitle", "不详");
break;
}
results.add(result);
}
newresults.addAll(results);
return newresults;
}
//使用记录查询方法
public synchronized Page<Map<String, Object>> queryOperateData(Mfcubestockstatement statement, LocalDate beginDate, LocalDate endDate, List<String> otype) {
StringBuilder sql = new StringBuilder();
sql.append("SELECT * FROM mfcubestockstatement a INNER JOIN ");
sql.append(" ( SELECT barcode,MAX(create_time) AS maxtime FROM mfcubestockstatement " );
sql.append(" where create_time >= '" + beginDate + "'");
sql.append(" and create_time <= '" + endDate + "'");
sql.append(" GROUP BY barcode ) b ");
sql.append(" ON a.barcode=b.barcode and a.DepotGuid='"+guiContext.getLoginUserVali().getOrgGuid()+"' AND a.create_time =b.maxtime and a.storeguid='" + guiContext.getStoreguid() + "'");
if (!StringUtils.isEmpty(statement.getGoodsname())) {
sql.append(" and (GoodsName like '%"+statement.getGoodsname()+"%' or LabGuid like'%"+ statement.getGoodsname() + "%')");
}
if (!StringUtils.isEmpty(statement.getSuppliername())) {
sql.append(" and suppliername like '%"+statement.getSuppliername()+"%'");
}
if (beginDate != null) {
sql.append(" and `create_time` >= '" + beginDate + "'");
}
if (endDate != null) {
sql.append(" and `create_time` <= '" + endDate + "'");
}
if(!StringUtils.isEmpty(statement.getCubeguid())) {
sql.append(" and cubeguid='"+statement.getCubeguid()+"'");
}
if(!StringUtils.isEmpty(fxConfigure.getCabinetGroupCode())) {
sql.append(" and CubeGuid in (select guid from cabinet where groupcode='" + fxConfigure.getCabinetGroupCode() + "')");
}
// if(!StringUtils.isEmpty(statement.getDepotguid())) {
// sql.append(" and depotGuid='" + statement.getDepotguid()+ "'");
// }
/* String sql = " select m.* from mfcubestockstatement m,( SELECT barcode,max(CREATE_TIME) cr FROM (select * from mfcubestockstatement where 1=1 " +term+
" order by `create_time` desc limit 10000000000) t" +
" GROUP BY barcode ) f where m.barcode=f.barcode and m.CREATE_TIME = f.cr order by create_time desc";*/
// String sql ="SELECT * FROM mfcubestockstatement a INNER JOIN" +
//// "(SELECT barcode,MAX(create_time) AS maxtime FROM mfcubestockstatement GROUP BY barcode) b " +
//// "ON a.barcode=b.barcode AND a.create_time =b.maxtime";
sql.append(" ORDER BY Create_time desc");
log.info(sql.toString());
Page<Map> datas = (Page<Map>) commonMapper.queryList(sql.toString());
List<Map<String, Object>> results = new ArrayList();
Page<Map<String, Object>> newresults = new Page<>();
newresults.setPageNum(datas.getPageNum());
newresults.setPages(datas.getPages());
newresults.setPageSize(datas.getPageSize());
newresults.setTotal(datas.getTotal());
for (Map map : datas) {
Mfcubestockstatement data = JSON.parseObject(JSON.toJSONString(map), Mfcubestockstatement.class);
Map<String, Object> result = BeanUtil.beanToMap(data);
StringBuilder goodsInfo = new StringBuilder();
goodsInfo.append(data.getGoodscode()).append("\n")
.append(data.getGoodsname()).append("\n")
.append(data.getUnit());
result.put("goodsInfo", goodsInfo.toString());
//result.put("goodsCount",data.getQty().stripTrailingZeros().toPlainString());
result.put("goodsCount",data.getManufacturer());
String lot = data.getLot() + "\n" + df.format(data.getExpiredate());
result.put("lot", lot);
StringBuilder goodsguiginfo = new StringBuilder();
HisGoods hisGoods=hisGoodsMapper.selectByPrimaryKey(data.getGoodsguid());
if(hisGoods!=null) {
goodsguiginfo.append(hisGoods.getGoodsspec()).append("\n").append(hisGoods.getModel());
}
result.put("goodsguiginfo",goodsguiginfo.toString());
String type = data.getType();
// 1:入库 2:出库 3:盘升 4:盘损 5:退货,6还货
switch (type) {
case "1":
result.put("typeTitle", "入库");
break;
case "2":
result.put("typeTitle", "取货");
break;
case "3":
result.put("typeTitle", "报溢");
break;
case "4":
result.put("typeTitle", "报损");
break;
case "5":
result.put("typeTitle", "退货");
break;
case "6":
result.put("typeTitle", "还货");
break;
default:
result.put("typeTitle", "不详");
break;
}
results.add(result);
}
newresults.addAll(results);
return newresults;
}
public synchronized Page<Map<String, Object>> queryExecptionData(Mfcubestockstatement statement, LocalDate beginDate, LocalDate endDate, List<String> otype) {
StringBuilder sql = new StringBuilder();
sql.append("SELECT * FROM mfcubestockstatement a INNER JOIN ");
sql.append(" ( SELECT barcode,MAX(create_time) AS maxtime FROM mfcubestockstatement " );
sql.append(" where create_time >= '" + beginDate + "'");
sql.append(" and create_time <= '" + endDate + "'");
sql.append(" GROUP BY barcode ) b ");
sql.append(" ON a.BackSts<>'N' and a.DepotGuid<>a.OperaterDeptGuid and type='2' and a.barcode=b.barcode and a.DepotGuid='"+statement.getDepotguid()+"' AND a.create_time =b.maxtime ");
if (!StringUtils.isEmpty(statement.getGoodsname())) {
sql.append(" and (GoodsName like '%"+statement.getGoodsname()+"%' or LabGuid like'%"+ statement.getGoodsname() + "%')");
}
if (!StringUtils.isEmpty(statement.getSuppliername())) {
sql.append(" and suppliername like '%"+statement.getSuppliername()+"%'");
}
if (beginDate != null) {
sql.append(" and `create_time` >= '" + beginDate + "'");
}
if (endDate != null) {
sql.append(" and `create_time` <= '" + endDate + "'");
}
if(!StringUtils.isEmpty(statement.getCubeguid())) {
sql.append(" and cubeguid='"+statement.getCubeguid()+"'");
}
if(!StringUtils.isEmpty(fxConfigure.getCabinetGroupCode())) {
sql.append(" and CubeGuid in (select guid from cabinet where groupcode='" + fxConfigure.getCabinetGroupCode() + "')");
}
sql.append(" ORDER BY Create_time desc");
log.info(sql.toString());
Page<Map> datas = (Page<Map>) commonMapper.queryList(sql.toString());
List<Map<String, Object>> results = new ArrayList();
Page<Map<String, Object>> newresults = new Page<>();
newresults.setPageNum(datas.getPageNum());
newresults.setPages(datas.getPages());
newresults.setPageSize(datas.getPageSize());
newresults.setTotal(datas.getTotal());
for (Map map : datas) {
Mfcubestockstatement data = JSON.parseObject(JSON.toJSONString(map), Mfcubestockstatement.class);
Map<String, Object> result = BeanUtil.beanToMap(data);
StringBuilder goodsInfo = new StringBuilder();
goodsInfo.append(data.getGoodscode()).append("\n")
.append(data.getGoodsname()).append("\n")
.append(data.getUnit());
result.put("goodsInfo", goodsInfo.toString());
result.put("goodsCount",data.getManufacturer());
String lot = data.getLot() + "\n" + df.format(data.getExpiredate());
result.put("lot", lot);
StringBuilder goodsguiginfo = new StringBuilder();
HisGoods hisGoods=hisGoodsMapper.selectByPrimaryKey(data.getGoodsguid());
if(hisGoods!=null) {
goodsguiginfo.append(hisGoods.getGoodsspec()).append("\n").append(hisGoods.getModel());
}
result.put("goodsguiginfo",goodsguiginfo.toString());
results.add(result);
}
newresults.addAll(results);
return newresults;
}
public Page<Map<String, Object>> feeQuery(LocalDate beginDate, LocalDate endDate, String goodsInfo, String suppliername, String patientName,String org) {
StringBuilder sql = new StringBuilder();
sql.append("select * from trchargingdetail td inner join trcharging t on td.tguid = t.guid and t.storeguid="+"'"+guiContext.getStoreguid()+"'"+" where CubeGuid in (select guid from cabinet where groupcode='").append(fxConfigure.getCabinetGroupCode())
.append("') ");
if (!StringUtils.isEmpty(patientName)) {
sql.append(" and t.name like '%" + patientName + "%'");
}
// sql.append(" and td.depotGuid ='"+guiContext.getLoginUserVali().getOrgGuid()+"'");
if (!StringUtils.isEmpty(suppliername)) {
sql.append(" and td.SupplierName like '%" + suppliername + "%'");
}
if (!StringUtils.isEmpty(goodsInfo)) {
sql.append(" and (td.GoodsName like '%" + goodsInfo + "%' or td.LabGuid LIKE '%" + goodsInfo + "%') "); }
if(!StringUtils.isEmpty(org)) {
sql.append(" and td.depotGuid='" + org+ "'");
}
if (beginDate != null) {
sql.append(" and td.InputDate >= '" + beginDate + "'");
}
if (endDate != null) {
sql.append(" and td.InputDate <= '" + endDate + "'");
}
sql.append(" order by td.InputDate desc");
System.out.println(sql);
Page<Map> datas = (Page) commonMapper.queryList(sql.toString());
List<Map<String, Object>> results = new ArrayList();
Page<Map<String, Object>> newresults = new Page<>();
newresults.setPageNum(datas.getPageNum());
newresults.setPages(datas.getPages());
newresults.setPageSize(datas.getPageSize());
newresults.setTotal(datas.getTotal());
for (Map data : datas) {
Map<String, Object> result = new HashMap<>();
result.putAll(data);
String pInfo = getStrValue(data, "name") + "\n" + getStrValue(data, "inpatienNo") + "\n" + getStrValue(data, "sickbedNo");
result.put("patientInfo", pInfo);
StringBuilder goodsInfol = new StringBuilder();
goodsInfol.append(getStrValue(data, "GoodsName")).append("\n")
.append(getStrValue(data, "Unit"));
result.put("goodsInfo", goodsInfol.toString());
String lot = getStrValue(data,"Lot") + "\n" + getStrValue(data,"ExpireDate")+"\n"+ getStrValue(data,"ProductionDate");;
result.put("lotinfo", lot);
result.put("goodsCount",new BigDecimal(getStrValue(data,"qty")).stripTrailingZeros().toPlainString());
StringBuilder goodsguiginfo = new StringBuilder();
HisGoods hisGoods=hisGoodsMapper.selectByPrimaryKey(data.get("GoodsGUID"));
if(hisGoods!=null) {
goodsguiginfo.append(hisGoods.getGoodsspec()).append("\n").append(hisGoods.getModel());
}
result.put("goodsguiginfo",goodsguiginfo.toString());
results.add(result);
}
newresults.addAll(results);
return newresults;
}
private String getStrValue(Map src, String key) {
Object val = src.get(key);
if (val == null) {
return "";
}
return val.toString();
}
public synchronized Page<Map<String, Object>> queryDetailUseData(String barCode) {
String sql = "select * from mfcubestockstatement where barcode = '"+barCode+"' ORDER by CREATE_TIME desc";
Page<Map> datas = (Page<Map>) commonMapper.queryList(sql);
List<Map<String, Object>> results = new ArrayList();
Page<Map<String, Object>> newresults = new Page<>();
newresults.setPageNum(datas.getPageNum());
newresults.setPages(datas.getPages());
newresults.setPageSize(datas.getPageSize());
newresults.setTotal(datas.getTotal());
for (Map map : datas) {
Mfcubestockstatement data = JSON.parseObject(JSON.toJSONString(map), Mfcubestockstatement.class);
Map<String, Object> result = BeanUtil.beanToMap(data);
data.setCreateTime((java.util.Date)map.get("CREATE_TIME"));
StringBuilder goodsInfo = new StringBuilder();
goodsInfo.append(data.getGoodsname()).append("\n")
.append(data.getUnit());
result.put("goodsInfo", goodsInfo.toString());
result.put("goodsCount",data.getQty().stripTrailingZeros().toPlainString());
String lot = data.getLot() + "\n" + df.format(data.getExpiredate());
result.put("lot", lot);
StringBuilder goodsguiginfo = new StringBuilder();
HisGoods hisGoods=hisGoodsMapper.selectByPrimaryKey(data.getGoodsguid());
if(hisGoods!=null) {
goodsguiginfo.append(hisGoods.getGoodsspec()).append("\n").append(hisGoods.getModel());
}
result.put("goodsguiginfo",goodsguiginfo.toString());
result.put("czsj", df.format(data.getCreateTime()));
String type = data.getType();
// 1:入库 2:出库 3:盘升 4:盘损 5:退货,6还货
switch (type) {
case "1":
result.put("typeTitle", "入库");
break;
case "2":
result.put("typeTitle", "出库");
break;
case "3":
result.put("typeTitle", "报溢");
break;
case "4":
result.put("typeTitle", "报损");
break;
case "5":
result.put("typeTitle", "退货");
break;
case "6":
result.put("typeTitle", "还货");
break;
default:
result.put("typeTitle", "不详");
break;
}
results.add(result);
}
newresults.addAll(results);
return newresults;
}
//根据柜子名称查询库存信息
public List<InboundItem> queryInboundItemByCabinet(String cabinetCode) {
List<InboundItem> inboundItems = new ArrayList();
String sql= "select * from mfcubestockdetail where storeguid = '"+guiContext.getStoreguid()+"' and CubeName = '"+cabinetCode+"'";
List<Map> details = commonMapper.queryList(sql);
for (Map detail : details) {
Mfcubestockdetail data = JSON.parseObject(JSON.toJSONString(detail), Mfcubestockdetail.class);
InboundItem inboundItem = new InboundItem();
inboundItem.setBarcode(data.getLabGuid());
inboundItem.setGoodsname(data.getGoodsName());
StringBuilder goodsguiginfo = new StringBuilder();
HisGoods hisGoods=hisGoodsMapper.selectByPrimaryKey(data.getGoodsGUID());
if(hisGoods!=null) {
goodsguiginfo.append(hisGoods.getGoodsspec()).append("\n").append(hisGoods.getModel());
}
inboundItem.setGoodsspec(goodsguiginfo.toString());
inboundItems.add(inboundItem);
}
return inboundItems;
}
@Transactional(rollbackFor = {ApiException.class, Exception.class})
public String getConSum(Map map,GUIContext g) throws Exception {
Trcharging trcharging = trchargingMapper.getTrcharging(map.get("operationNo").toString());//根据手术单号查询手术单是否存在
String stroeid=trcharging.getStoreguid();
System.out.println("stroeid:"+stroeid);
if (trcharging == null) {
log.info("没有该手术单" + map.get("operationNo").toString() + ",无法进行反消耗");
throw new ApiException("没有该手术单" + map.get("operationNo").toString() + ",无法进行反消耗");
}
//进行手术单删除
int count = trchargingdetailMapper.delTrchargingDetail(trcharging.getGuid());
if (count > 0) {
//删除手术单头表
trchargingMapper.delTrcharging(map.get("operationNo").toString());
log.info("手术单清除成功=>" + map.get("operationNo").toString());
}
//List<ConsumDetail> consumDetailList = mfcubest.getConsumDetailList();
// for (int j = 0; j < consumDetailList.size(); j++) {
// ConsumDetail consumDetail = consumDetailList.get(j);
MfcubestockdetailOld mfcubestockdetailOld = mfcubestockdetailOldMapper.searchDetailByBarcode(map.get("barcode").toString());
if (mfcubestockdetailOld == null) {
log.info("该耗材" + map.get("barcode").toString() + "没有消耗记录");
throw new ApiException("该耗材" + map.get("barcode").toString() + "没有消耗记录");
}
Mfcubestockdetail mfcubestockdetail = mfcubestockdetailMapper.searchDetailByBarcode(map.get("barcode").toString());
if (mfcubestockdetail != null) {
log.info("该耗材" + map.get("barcode").toString() + "还在柜中没有被消耗");
throw new ApiException("该耗材" + map.get("barcode").toString() + "还在柜中没有被消耗");
}
System.out.println("库存历史记录表"+mfcubestockdetailOld.toString());
System.out.println("库存历史记录表时间"+mfcubestockdetailOld.getUseTime());
Mfcubestockdetail mfcubestockdetail1 = new Mfcubestockdetail();
BeanUtils.copyProperties(mfcubestockdetailOld,mfcubestockdetail1);
mfcubestockdetail1.setUseTime(new Date(System.currentTimeMillis()));
System.out.println("库存"+mfcubestockdetail1.toString()+":ss"+stroeid);
mfcubestockdetail1.setStoreguid(stroeid);
mfcubestockdetail1.setStorename("");
// mfcubestockdetail.setStoreguid(guiContext.getStoreguid());
// mfcubestockdetail.setStoreguid("");
int insert = mfcubestockdetailMapper.insert(mfcubestockdetail1);
if (insert > 0) {
//开始删除库存历史
mfcubestockdetailOldMapper.mfcubestockdetaildel(map.get("barcode").toString());
log.info("反消耗成功");
}
return "ok";
}
public String getConSum2(String id,GUIContext g) throws Exception {
Trchargingdetail trchargingdetail=new Trchargingdetail();
trchargingdetail.setGuid(id);
trchargingdetail= trchargingdetailMapper.selectOne(trchargingdetail);
//进行手术单删除
int count = trchargingdetailMapper.delTrchargingDetail(trchargingdetail.getGuid());
if (count > 0) {
//删除手术单头表
trchargingMapper.delTrcharging(trchargingdetail.getTguid());
log.info("手术单清除成功=>" +trchargingdetail.getTguid());
}
MfcubestockdetailOld mfcubestockdetailOld = mfcubestockdetailOldMapper.searchDetailByBarcode(trchargingdetail.getBarcode());
if (mfcubestockdetailOld == null) {
log.info("该耗材" + trchargingdetail.getBarcode() + "没有消耗记录");
throw new ApiException("该耗材" + trchargingdetail.getBarcode() + "没有消耗记录");
}
Mfcubestockdetail mfcubestockdetail = mfcubestockdetailMapper.searchDetailByBarcode(trchargingdetail.getBarcode());
if (mfcubestockdetail != null) {
log.info("该耗材" + trchargingdetail.getBarcode() + "还在柜中没有被消耗");
throw new ApiException("该耗材" + trchargingdetail.getBarcode() + "还在柜中没有被消耗");
}
System.out.println("库存历史记录表"+mfcubestockdetailOld.toString());
System.out.println("库存历史记录表时间"+mfcubestockdetailOld.getUseTime());
Mfcubestockdetail mfcubestockdetail1 = new Mfcubestockdetail();
BeanUtils.copyProperties(mfcubestockdetailOld,mfcubestockdetail1);
mfcubestockdetail1.setUseTime(new Date(System.currentTimeMillis()));
mfcubestockdetail1.setStoreguid(mfcubestockdetail.getStoreguid());
mfcubestockdetail1.setStorename("");
// mfcubestockdetail.setStoreguid(guiContext.getStoreguid());
// mfcubestockdetail.setStoreguid("");
int insert = mfcubestockdetailMapper.insert(mfcubestockdetail1);
if (insert > 0) {
//开始删除库存历史
mfcubestockdetailOldMapper.mfcubestockdetaildel(trchargingdetail.getBarcode());
log.info("反消耗成功");
}
return "ok";
}
}