根据设计图抽象的枚举类,一张模板背景图(会改变),二维码(传入参数生成),一个关闭的icon(固定不变)
设计图如下
去除重复模板后共五个,根据需求编写枚举类如下,url则对应不同的模板,编写成后台人员的可配置项,
- public enum ImageTemplateEnum {
- PURCHASE("purchase","url1"),
- BAR_CARD("barcard","url2"),
- FAILURE("failure","url3"),
- COINING("coining","url4"),
- INVITE("invite","url5");
-
- private String template;
- private String url;
-
- ImageTemplateEnum(String template, String url) {
- this.template = template;
- this.url = url;
- }
-
- /**
- * 通过template返回枚举常量对象
- * @param template
- * @return
- */
- public static String getValue(String template){
-
- for (ImageTemplateEnum item: values()) {
- if(item.getTemplate().equals(template)){
- return item.url;
- }
- }
- return null;
-
- }
-
-
- public String getTemplate() {
- return template;
- }
-
- public void setTemplate(String template) {
- this.template = template;
- }
-
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
- }
- @PostMapping(value = "/xxxx")
- @SignCtrl
- @ResponseBody
- public String composeImg(String template,String userId,String state) {
- TbUser tbUser = userService.selectUserByUserId(userId);
- if (null == tbUser) {
- return JSON.toJSONString(new CommonView("500", "用户不存在", null));
- }
- Map
result = new HashMap<>(); - result.put("url", imgService.createImgByTemplate(template, tbUser.getThirdUserId(), state));
- return JSON.toJSONString(new CommonView("200","成功",result));
- }
根据传入条件生成二维码与模板拼接
测试
根据前端传入template参数就能拿到模板的url了