提交 b86a35a4 编写于 作者: R Ray

通用服务中增加二维码生成接口

上级 8ee8fc6b
......@@ -24,6 +24,8 @@ echo "Wants=network-online.target" >>${servicePath}
echo "After=network.target" >>${servicePath}
echo "[Service]" >>${servicePath}
echo "Type=simple" >>${servicePath}
echo "StandardOutput=null" >>${servicePath}
echo "StandardError=null" >>${servicePath}
echo "ExecStart=${current_dir}/${scriptName}" >>${servicePath}
echo "ExecReload=${current_dir}/restart_linux.sh" >>${servicePath}
echo "ExecStop=${current_dir}/stop_linux.sh" >>${servicePath}
......
......@@ -45,4 +45,11 @@ public class NumberTools {
return value.doubleValue() < number.doubleValue();
}
public static boolean nullOrGreaterThan(Number value, Number number) {
if (value == null) {
return true;
}
return value.doubleValue() > number.doubleValue();
}
}
......@@ -9,12 +9,14 @@ import com.x.general.assemble.control.jaxrs.area.AreaAction;
import com.x.general.assemble.control.jaxrs.ecnet.EcnetAction;
import com.x.general.assemble.control.jaxrs.generalfile.GeneralFileAction;
import com.x.general.assemble.control.jaxrs.office.OfficeAction;
import com.x.general.assemble.control.jaxrs.qrcode.QrCodeAction;
import com.x.general.assemble.control.jaxrs.upgrade.UpgradeAction;
import com.x.general.assemble.control.jaxrs.worktime.WorkTimeAction;
@ApplicationPath("jaxrs")
public class ActionApplication extends AbstractActionApplication {
@Override
public Set<Class<?>> getClasses() {
classes.add(AreaAction.class);
classes.add(EcnetAction.class);
......@@ -22,6 +24,7 @@ public class ActionApplication extends AbstractActionApplication {
classes.add(WorkTimeAction.class);
classes.add(GeneralFileAction.class);
classes.add(UpgradeAction.class);
classes.add(QrCodeAction.class);
return classes;
}
......
package com.x.general.assemble.control.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.AnonymousCipherManagerUserJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/qrcode/*", asyncSupported = true)
public class QrCodeJaxrsFilter extends AnonymousCipherManagerUserJaxrsFilter {
}
package com.x.general.assemble.control.jaxrs.qrcode;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoFile;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
public class ActionGetCreate extends BaseAction {
private static final Logger LOGGER = LoggerFactory.getLogger(ActionGetCreate.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, Integer width, Integer height, String text)
throws Exception {
LOGGER.debug("effectivePerson: {}.", effectivePerson.getDistinguishedName());
ActionResult<Wo> result = new ActionResult<>();
byte[] bytes = this.create(width, height, text);
Wo wo = new Wo(bytes, this.contentType(false, FILENAME), this.contentDisposition(false, FILENAME));
result.setData(wo);
return result;
}
public class Wo extends WoFile {
private static final long serialVersionUID = -6210739068105920249L;
public Wo(byte[] bytes, String contentType, String contentDisposition) {
super(bytes, contentType, contentDisposition);
}
}
}
package com.x.general.assemble.control.jaxrs.qrcode;
import org.apache.commons.lang3.StringUtils;
import com.google.gson.JsonElement;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoFile;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
public class ActionPostCreate extends BaseAction {
private static final Logger LOGGER = LoggerFactory.getLogger(ActionPostCreate.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
LOGGER.debug("effectivePerson: {}.", effectivePerson.getDistinguishedName());
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
ActionResult<Wo> result = new ActionResult<>();
byte[] bytes = this.create(wi.getWidth(), wi.getHeight(), wi.getText());
Wo wo = new Wo(bytes, this.contentType(false, FILENAME), this.contentDisposition(false, FILENAME));
result.setData(wo);
return result;
}
public class Wi extends GsonPropertyObject {
private static final long serialVersionUID = -670631145209495465L;
@FieldDescribe("转换文本")
private String text;
@FieldDescribe("图像宽度,默认200.")
private Integer width;
@FieldDescribe("图像高度,默认200.")
private Integer height;
public String getText() {
return StringUtils.trimToEmpty(text);
}
public void setText(String text) {
this.text = text;
}
public Integer getWidth() {
return width;
}
public void setWidth(Integer width) {
this.width = width;
}
public Integer getHeight() {
return height;
}
public void setHeight(Integer height) {
this.height = height;
}
}
public class Wo extends WoFile {
private static final long serialVersionUID = -6210739068105920249L;
public Wo(byte[] bytes, String contentType, String contentDisposition) {
super(bytes, contentType, contentDisposition);
}
}
}
package com.x.general.assemble.control.jaxrs.qrcode;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.EnumMap;
import java.util.Map;
import javax.imageio.ImageIO;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
abstract class BaseAction extends StandardJaxrsAction {
protected static final String FILENAME = "qrcode.png";
private static final Map<EncodeHintType, String> HINTS = new EnumMap<>(EncodeHintType.class);
static {
HINTS.put(EncodeHintType.MARGIN, "1");
HINTS.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.Q.toString());
}
private static final String FORMAT = "png";
private static final int DEFAULTWIDTH = 200;
private static final int MAXWIDTH = 400;
private static final int MINWIDTH = 40;
private static final int DEFAULTHEIGHT = 200;
private static final int MAXHEIGHT = 400;
private static final int MINHEIGHT = 40;
private static final int BLACK = 0xFF000000;
private static final int WHITE = 0xFFFFFFFF;
protected byte[] create(Integer width, Integer height, String text) throws WriterException, IOException {
int w = this.width(width);
int h = this.height(height);
BitMatrix bitMatrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, w, h, HINTS);
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
image.setRGB(x, y, bitMatrix.get(x, y) ? BLACK : WHITE);
}
}
byte[] bytes = null;
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
ImageIO.write(image, FORMAT, out);
bytes = out.toByteArray();
}
return bytes;
}
private Integer width(Integer width) {
return (null == width) || (width < MINWIDTH) || (width > MAXWIDTH) ? DEFAULTWIDTH : width;
}
private Integer height(Integer height) {
return (null == height) || (height < MINHEIGHT) || (height > MAXHEIGHT) ? DEFAULTHEIGHT : height;
}
}
package com.x.general.assemble.control.jaxrs.qrcode;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import com.google.gson.JsonElement;
import com.x.base.core.project.annotation.JaxrsDescribe;
import com.x.base.core.project.annotation.JaxrsMethodDescribe;
import com.x.base.core.project.annotation.JaxrsParameterDescribe;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.http.HttpMediaType;
import com.x.base.core.project.jaxrs.ResponseFactory;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
@Path("qrcode")
@JaxrsDescribe("二维码")
public class QrCodeAction extends StandardJaxrsAction {
private static final Logger LOGGER = LoggerFactory.getLogger(QrCodeAction.class);
@JaxrsMethodDescribe(value = "POST方法生成二维码图像.", action = ActionPostCreate.class)
@POST
@Consumes(MediaType.APPLICATION_JSON)
public void postCreate(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
JsonElement jsonElement) {
ActionResult<ActionPostCreate.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionPostCreate().execute(effectivePerson, jsonElement);
} catch (Exception e) {
LOGGER.error(e, effectivePerson, request, jsonElement);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "GET方法生成二维码图像.", action = ActionGetCreate.class)
@GET
@Path("width/{width}/height/{height}/text/{text}")
@Consumes(MediaType.APPLICATION_JSON)
public void getCreate(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("宽") @PathParam("width") Integer width,
@JaxrsParameterDescribe("高") @PathParam("height") Integer height,
@JaxrsParameterDescribe("文本") @PathParam("text") String text) {
ActionResult<ActionGetCreate.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionGetCreate().execute(effectivePerson, width, height, text);
} catch (Exception e) {
LOGGER.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
\ No newline at end of file
......@@ -73,48 +73,6 @@ class ActionBind extends BaseAction {
private static final int BLACK = 0xFF000000;
private static final int WHITE = 0xFFFFFFFF;
// private static final byte[] logoBytes = new byte[] { -119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82,
// 0, 0, 0, 64, 0, 0, 0, 64, 8, 6, 0, 0, 0, -86, 105, 113, -34, 0, 0, 0, 4, 103, 65, 77, 65, 0, 0, -79, -113,
// 11, -4, 97, 5, 0, 0, 0, 32, 99, 72, 82, 77, 0, 0, 122, 38, 0, 0, -128, -124, 0, 0, -6, 0, 0, 0, -128, -24,
// 0, 0, 117, 48, 0, 0, -22, 96, 0, 0, 58, -104, 0, 0, 23, 112, -100, -70, 81, 60, 0, 0, 0, 6, 98, 75, 71, 68,
// 0, 0, 0, 0, 0, 0, -7, 67, -69, 127, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 11, 18, 0, 0, 11, 18, 1, -46, -35,
// 126, -4, 0, 0, 3, 36, 73, 68, 65, 84, 120, -38, -19, -101, -51, 79, 19, 65, 24, -58, -97, 89, 49, -107,
// -125, -75, 74, 37, 86, 69, 18, 67, -62, 87, -119, 7, 77, -76, -127, -58, -125, 127, 0, -31, 35, 106, 60,
// -101, 72, 52, 24, 14, 4, 57, 122, -82, 112, -63, 24, 76, -4, 7, -60, -92, -59, -60, -77, 94, 10, 42, 28,
// -107, 34, 120, 48, -126, 32, 6, -86, -108, 30, -124, 30, -24, 122, 104, 119, 83, 118, 27, 29, 103, 63, -34,
// 118, 119, 127, -57, -39, -39, -23, -13, 60, -23, -68, -99, -66, -39, 101, 40, 65, -106, -27, 65, 0, 93, 0,
// -94, 0, 66, 112, 22, 27, 0, -110, 0, 102, 24, 99, -113, -107, 65, 86, 52, 30, 0, -16, 20, -64, 13, 106,
// -107, 54, 49, 5, 96, -128, 49, -106, 81, 2, 120, -18, 34, -13, 106, 8, -116, -79, -101, -84, -8, -75, -97,
// -96, 86, 67, -60, -3, 26, 20, -10, -68, -54, -20, -89, 77, -116, 37, 82, 72, 103, 115, -44, -30, 76, 37,
// -24, -9, 97, -72, -73, 29, -99, -83, -11, -91, -61, 93, 18, 10, 5, 79, -59, -119, -26, 1, 32, -99, -51, 97,
// 44, -111, -46, 14, 71, 37, 104, -86, -67, 19, -51, -1, -59, 91, 72, -94, 22, 69, -115, 23, 0, -75, 0, 106,
// 106, 120, 39, 62, 27, -116, -96, -27, -20, 49, 106, -67, 92, 44, -81, 103, 113, 123, -30, 45, -41, 92, -18,
// 111, 64, -75, -104, 7, -128, -26, 51, 126, -18, -71, -82, -33, 2, -36, 1, 124, -8, -70, 77, -83, -43, 18,
// -72, 107, -64, -67, -55, 57, 106, -83, 101, 9, -6, 125, 24, -23, 11, 35, -46, 114, 82, -24, -2, -86, -33, 2,
// -23, 108, 14, -79, -8, -126, -16, -3, 85, 31, -128, 18, -126, -85, 3, 48, -126, -124, 66, -89, 68, 37, -24,
// -9, 81, 107, -78, 61, -128, 100, -23, -64, 104, 127, 7, 66, 39, 106, -87, 117, -39, 70, 13, -128, 25, 0,
// -41, -107, -127, -53, -51, 65, -68, 120, 112, -107, 90, 87, 89, 22, 87, 51, -72, -13, -28, -67, -87, 107,
// 74, -59, 6, -31, 20, -75, 57, 30, -38, -50, 5, 76, 95, -45, 43, -126, -59, -98, -96, -37, 26, -94, 42, -70,
// -98, -32, -69, -91, 45, 60, 74, -92, -80, -75, -77, 7, 0, 56, 117, -68, 22, -93, -3, 97, 92, 108, -86, -125,
// 118, -34, -40, 116, 10, -101, -103, 61, -31, 15, -105, 36, -122, 75, 77, 117, 120, 120, -21, 2, -114, -42,
// 30, 46, -67, 116, -115, 49, -10, 6, 0, 100, 89, -106, -83, 12, 64, -41, 19, -116, -59, 23, 84, -13, 0, -16,
// 99, 123, -73, 92, 47, 13, -79, -8, -126, 33, -13, 0, -112, -49, -53, -104, -1, -100, 70, 124, 118, 69, 123,
// 41, 42, -78, -98, 104, 0, -1, -20, 9, -82, -3, -4, -83, 27, 51, -77, 119, -8, -3, -41, -82, 118, -24, -68,
// -99, 1, -72, 26, -31, 0, -22, 3, 71, -88, -75, -45, 6, 48, -46, 27, 118, -60, -119, -111, -69, 31, -96, -27,
// 127, 79, -116, -5, 121, 25, -29, -45, -117, 120, 53, -1, -115, -38, -13, 1, 108, -85, 1, -121, 36, -122,
// -114, -58, 0, -75, 95, -70, 0, 42, 21, -37, 2, -40, -49, -53, -8, -72, -110, -95, -10, -85, 67, -72, 6, -52,
// 45, -89, 49, -2, 50, -123, 13, -3, 111, 120, 85, 33, 28, 64, 44, 97, -4, 36, 88, 9, 8, 111, 1, 39, -104, 55,
// 20, -128, 83, -88, -120, 0, 78, -21, 15, 84, 95, -20, -6, 108, -31, 26, 96, 6, -54, -33, -31, -66, -50, 70,
// -19, -91, -92, -56, 122, 21, 17, -64, -28, -35, 43, 8, 27, 63, -16, -68, -74, -72, 13, -96, 98, -6, 22, 48,
// -63, -68, -83, 84, 68, 13, 112, 84, 0, -117, -85, 25, -53, -60, 90, -79, -74, -23, 53, -64, -20, -66, -67,
// -43, 120, 91, -128, 90, 0, 53, 94, 0, -62, 55, 50, 70, -83, -35, 20, 45, -62, 1, -12, 68, 26, 42, 34, 4,
// -119, 49, -12, 68, 26, -124, -17, 23, -2, 21, 24, -22, 110, -61, 80, 119, 27, -75, 127, -61, 120, 53, -128,
// 90, 0, 53, -36, 1, 44, -81, 103, -87, -75, 114, -77, -76, -74, -61, 61, -105, -69, 6, -16, 62, 123, 91, 109,
// 120, 91, -128, 90, 0, 53, 94, 0, 112, -47, 115, -126, 101, -68, 109, -24, -98, 19, 28, -18, 109, 119, 100,
// 8, -54, 107, 115, 26, -110, -82, 127, 113, -46, -11, -81, -50, 42, 69, 112, 0, 85, -14, -80, -92, 89, -26,
// -117, -98, 113, -32, -17, -100, 27, 95, -97, -1, 3, 15, 32, -32, 95, -60, -127, 21, 87, 0, 0, 0, 0, 73, 69,
// 78, 68, -82, 66, 96, -126 };
public class Wo extends Bind {
private static final long serialVersionUID = -3574645735233129236L;
......
......@@ -330,6 +330,7 @@ public class TaskCompleted extends SliceJpaObject implements ProjectionInterface
} else {
this.expired = false;
}
this.latest = true;
this.duration = duration;
this.processingType = processingType;
/* 必须使用set方法,执行opinion的判断 */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册