CommonController.java
6.28 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
package com.huaheng.system.controller;
import com.google.zxing.WriterException;
import com.huaheng.common.core.web.domain.AjaxResult;
import com.huaheng.common.log.annotation.Log;
import com.huaheng.common.log.enums.BusinessType;
import com.huaheng.common.security.utils.SecurityUtils;
import com.huaheng.system.api.domain.Company;
import com.huaheng.system.api.domain.Warehouse;
import com.huaheng.system.mapper.ExcelReportMapper;
import com.huaheng.system.utils.QRCodeGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.ObjectUtils;
import org.apache.ibatis.annotations.Lang;
import org.krysalis.barcode4j.HumanReadablePlacement;
import org.krysalis.barcode4j.impl.code128.Code128Bean;
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.*;
@Api(tags = "通用方法")
@Controller
public class CommonController {
@Resource
private ExcelReportMapper mapper;
@ApiOperation(value = "二维码")
@GetMapping(value = "/image/{text}")
@Log(title = "生成二维码", businessType = BusinessType.GRANT)
public ResponseEntity<byte[]> getImage(@PathVariable("text") String text) {
byte[] qrcode = null;
try {
qrcode = QRCodeGenerator.getQRCodeImage(text, 100, 100);
} catch (WriterException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// Set headers
final HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.IMAGE_PNG);
return new ResponseEntity<byte[]>(qrcode, headers, HttpStatus.CREATED);
}
/**
* 生成条形码
* @param message
* @return
*/
@ApiOperation(value = "生成条形码")
@GetMapping(value = "/code128/{message}")
@Log(title = "生成条形码", businessType = BusinessType.GRANT)
public ResponseEntity<byte[]> generateBarCode128(@PathVariable("message") String message) {
Double height = 50D;
Double width = 1D;
Code128Bean bean = new Code128Bean();
// 分辨率
int dpi = 512;
// 设置两侧是否留白
bean.doQuietZone(true);
// 设置条形码高度和宽度
bean.setBarHeight((double) ObjectUtils.defaultIfNull(height, 9.0D));
bean.setModuleWidth(width);
// 设置文本位置(包括是否显示)
bean.setMsgPosition(HumanReadablePlacement.HRP_BOTTOM);
bean.setFontSize(14);
// 设置图片类型
String format = "image/png";
ByteArrayOutputStream ous = new ByteArrayOutputStream();
BitmapCanvasProvider canvas = new BitmapCanvasProvider(ous, format, dpi,
BufferedImage.TYPE_BYTE_BINARY, false, 0);
// 生产条形码
bean.generateBarcode(canvas, message);
try {
canvas.finish();
} catch (IOException e) {
//ByteArrayOutputStream won't happen
}
final HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.IMAGE_PNG);
return new ResponseEntity<byte[]>(ous.toByteArray(), headers, HttpStatus.CREATED);
}
/**
* 6个显示后台
*/
@ApiOperation(value = "首页六个值")
@GetMapping("getCommonData")
@ResponseBody
@Log(title = "首页六个值", businessType = BusinessType.GRANT)
public AjaxResult getCommonData(){
String bllCount = "SELECT ifnull(sum(t.a),0) 'total' from (\n" +
"SELECT COUNT(*) 'a' FROM receipt_header WHERE DATEDIFF(NOW(), created)=0 " +
" UNION \n" +
"SELECT COUNT(*) 'a' FROM shipment_header WHERE DATEDIFF(NOW(), created)=0 " +
") t";
String receiptTotal = "SELECT ifnull(sum(t.qty),0) 'total' from task_detail t\n" +
"inner join receipt_header r on t.billCode=r.code and\n" +
"t.status>100 and DATEDIFF(NOW(), t.lastUpdated)=0;";
String shipmentTotal = "SELECT ifnull(sum(t.qty),0) 'total' from task_detail t\n" +
"inner join shipment_header s on t.billCode=s.code and\n" +
"t.status>100 and DATEDIFF(NOW(), t.lastUpdated)=0;";
String inventoryTotal = "SELECT IFNULL(SUM(qty),0) 'total' from inventory_detail where 1=1 " ;
String materialCount = "SELECT count(DISTINCT materialCode) 'total' from inventory_detail WHERE 1=1";
String taskUncompletedTotal = "SELECT COUNT(*) 'total' from task_header WHERE status < 100 " ;
Map<String, Object> map = new HashMap<>();
List<LinkedHashMap<String, Object>> temp1 = mapper.selectCommon(bllCount);
map.put("bllCount",temp1.get(0).entrySet().iterator().next().getValue());
List<LinkedHashMap<String, Object>> temp2 = mapper.selectCommon(receiptTotal);
map.put("receiptTotal",temp2.get(0).entrySet().stream().findFirst().get().getValue());
List<LinkedHashMap<String, Object>> temp3 = mapper.selectCommon(shipmentTotal);
map.put("shipmentTotal",temp3.get(0).entrySet().stream().findFirst().get().getValue());
List<LinkedHashMap<String, Object>> temp4 = mapper.selectCommon(inventoryTotal);
map.put("inventoryTotal",temp4.get(0).entrySet().stream().findFirst().get().getValue());
List<LinkedHashMap<String, Object>> temp5 = mapper.selectCommon(materialCount);
map.put("materialCount",temp5.get(0).entrySet().stream().findFirst().get().getValue());
List<LinkedHashMap<String, Object>> temp6 = mapper.selectCommon(taskUncompletedTotal);
map.put("taskUncompletedTotal",temp6.get(0).entrySet().stream().findFirst().get().getValue());
return AjaxResult.success(map);
}
}