diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxDeviceScreenAdController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxDeviceScreenAdController.java index b754d6d00..736a60a2c 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/WxDeviceScreenAdController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxDeviceScreenAdController.java @@ -6,13 +6,11 @@ import com.iformall.common.ErrorCode; import com.iformall.common.Result; import com.iformall.common.ResultData; import com.iformall.domain.po.WxDevice; +import com.iformall.domain.po.WxMall; import com.iformall.domain.po.WxScreenAd; import com.iformall.enums.EnumScreenAdStatus; import com.iformall.enums.EnumScreenAdType; -import com.iformall.service.WxCampaignService; -import com.iformall.service.WxCouponChannelService; -import com.iformall.service.WxDeviceService; -import com.iformall.service.WxScreenAdService; +import com.iformall.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -22,6 +20,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.Date; import java.util.List; @RestController @@ -33,6 +32,9 @@ public class WxDeviceScreenAdController extends BaseController { @Autowired private WxScreenAdService wxScreenAdService; + @Autowired + private WxMallService wxMallService; + @Autowired private WxDeviceService wxDeviceService; @@ -61,7 +63,7 @@ public class WxDeviceScreenAdController extends BaseController { @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) - public Result list(@RequestBody String deviceId, Integer pageNum, Integer pageSize) { + public Result list(@RequestParam String deviceId, Integer pageNum, Integer pageSize) { WxDevice wxDevice = findDevice(deviceId); if (wxDevice == null) @@ -83,20 +85,25 @@ public class WxDeviceScreenAdController extends BaseController { @ApiOperation("心跳") @PostMapping("heartbeat") - public Result heartbeat(@RequestBody String deviceId) { + public Result heartbeat(@RequestParam String deviceId,@RequestBody String version) { WxDevice wxDevice = findDevice(deviceId); if (wxDevice == null) return new ResultData(ErrorCode.DEVICE_NOT_FOUND); - return new ResultData(); + if (wxDevice.getFirstHbTime() == null) + wxDevice.setFirstHbTime(new Date()); + wxDevice.setLastHbTime(new Date()); + wxDevice.setVersion(version); + wxDeviceService.saveOrUpdate(wxDevice); + return new ResultData(wxDevice); } @ApiOperation("基础信息") @GetMapping("info") - public Result detail(@RequestBody String deviceId) { + public Result info(@RequestParam String deviceId) { WxDevice wxDevice = findDevice(deviceId); if (wxDevice == null) return new ResultData(ErrorCode.DEVICE_NOT_FOUND); - return new ResultData(); + return new ResultData(wxMallService.getByTenantId(wxDevice.getTenantId())); } } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxMall.java b/mallinkService/src/main/java/com/iformall/domain/po/WxMall.java index 5d6e8fa55..0374028ac 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxMall.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxMall.java @@ -82,6 +82,11 @@ public class WxMall implements Serializable { @io.swagger.annotations.ApiModelProperty(value="商场图标",name="imgUrlH") private String imgUrlH; + @io.swagger.annotations.ApiModelProperty(value="小程序二维码",name="imgQrcodeWeapp") + private String imgQrcodeWeapp; + @io.swagger.annotations.ApiModelProperty(value="公众平台二维码",name="imgQrcodeWemp") + private String imgQrcodeWemp; + @io.swagger.annotations.ApiModelProperty(value="小程序提示",name="weapNote") private String weapNote; @@ -195,6 +200,22 @@ public class WxMall implements Serializable { this.buildings = buildings; } + public String getImgQrcodeWeapp() { + return imgQrcodeWeapp; + } + + public void setImgQrcodeWeapp(String imgQrcodeWeapp) { + this.imgQrcodeWeapp = imgQrcodeWeapp; + } + + public String getImgQrcodeWemp() { + return imgQrcodeWemp; + } + + public void setImgQrcodeWemp(String imgQrcodeWemp) { + this.imgQrcodeWemp = imgQrcodeWemp; + } + public static enum Field { Id_ASC("`id` ASC"),Id_DESC("`id` DESC") diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxScreenAd.java b/mallinkService/src/main/java/com/iformall/domain/po/WxScreenAd.java index 6a75bbe79..43afb7616 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxScreenAd.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxScreenAd.java @@ -68,6 +68,10 @@ public class WxScreenAd implements Serializable { @io.swagger.annotations.ApiModelProperty(value="广告目标ID",name="targetId") private Long targetId; + /**广告目标二维码**/ + @io.swagger.annotations.ApiModelProperty(value="二维码",name="qrcode") + private byte[] qrcode; + @Transient protected Object target; @@ -135,6 +139,14 @@ public class WxScreenAd implements Serializable { this.targetId = targetId; } + public byte[] getQrcode() { + return qrcode; + } + + public void setQrcode(byte[] qrcode) { + this.qrcode = qrcode; + } + public static enum Field { Id_ASC("`id` ASC"),Id_DESC("`id` DESC") diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxScreenAdServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxScreenAdServiceImpl.java index 43cdfcab5..1baf9d466 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxScreenAdServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxScreenAdServiceImpl.java @@ -1,19 +1,32 @@ package com.iformall.service.impl; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.iformall.common.IdWorker; +import com.iformall.domain.po.WxAppinfo; import com.iformall.domain.po.WxScreenAd; +import com.iformall.enums.EnumScreenAdType; import com.iformall.mapper.WxScreenAdMapper; +import com.iformall.service.WxAppinfoService; import com.iformall.service.WxScreenAdService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; @Service public class WxScreenAdServiceImpl implements WxScreenAdService { @@ -22,6 +35,9 @@ public class WxScreenAdServiceImpl implements WxScreenAdService { @Autowired WxScreenAdMapper wxScreenAdMapper; + @Autowired + WxAppinfoService wxAppinfoService; + @Override public PageInfo listAsPage(WxScreenAd record, Integer pageIndex, Integer pageSize) { return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxScreenAdMapper.findList(record)); @@ -38,9 +54,12 @@ public class WxScreenAdServiceImpl implements WxScreenAdService { final IdWorker idWorker = IdWorker.get(); record.setId(idWorker.nextId()); record.setCreateDate(new Date()); + setQrcode(record); + wxScreenAdMapper.insertSelective(record); } else { record.setUpdateDate(new Date()); + setQrcode(record); wxScreenAdMapper.updateByPrimaryKeySelective(record); } } @@ -49,9 +68,67 @@ public class WxScreenAdServiceImpl implements WxScreenAdService { public void deleteById(Long id) { wxScreenAdMapper.deleteByPrimaryKey(id); } + @Override public List findList(WxScreenAd wxTagsType) { return wxScreenAdMapper.findList(wxTagsType); } + + + private void setQrcode(WxScreenAd record){ + if (record.getTargetId() != null && + record.getType() != null && + record.getTenantId() != null) + try { + record.setQrcode(getQrcode(record.getTargetId(), + record.getType().intValue(), + wxAppinfoService.getCAppInfo(record.getTenantId()))); + }catch (Exception e) { + logger.error("QRCODE set Error:"+e.getMessage()); + } + } + + private static String wxacodeunlimit = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="; + + private static int QRCODE_WIDTH = 300; + private static String QRCODE_PAGE_COUPON = "pages/coupon/detail/index"; + private static String QRCODE_PAGE_CAMPGIN = "pages/bannerdetail/index"; + private static String QRCODE_PAGE_HOME = "pages/index/index"; + private static boolean QRCODE_AUTO_COLOR = false; + //private static int QRCODE_LINCOLOR =; + private static boolean QRCODE_IS_HYALINE = false; + + private byte[] getQrcode(Long id, int type, WxAppinfo appInfo) throws Exception { + String accessToken = appInfo.getAccessToken(); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + Map map = new HashMap<>(); + + map.put("scene", id.toString()); + + if (EnumScreenAdType.COUPON.getCode().equals(type)) + map.put("page", QRCODE_PAGE_COUPON); + else if (EnumScreenAdType.CAMPAIGN.getCode().equals(type)) + map.put("page", QRCODE_PAGE_CAMPGIN); + else + map.put("page", QRCODE_PAGE_HOME); + + map.put("width", QRCODE_WIDTH); + map.put("auto_color", QRCODE_AUTO_COLOR); + //map.put("line_color", ); + map.put("is_hyaline", QRCODE_IS_HYALINE); + + HttpEntity> entity = new HttpEntity>(map, headers); + String reqUrl =wxacodeunlimit+accessToken; + + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity responseEntity = restTemplate.postForEntity(reqUrl, entity, byte[].class); + + if(responseEntity.hasBody()) { + return responseEntity.getBody(); + } else { + return null; + } + } } diff --git a/mallinkService/src/main/resources/mapper/WxMallMapper.xml b/mallinkService/src/main/resources/mapper/WxMallMapper.xml index 27e638828..8c1d7b3a5 100644 --- a/mallinkService/src/main/resources/mapper/WxMallMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxMallMapper.xml @@ -18,13 +18,14 @@ - + + `id`,`tenant_id`,`name`,`group`,`country`,`province`,`city`,`addr`, `total_area`,`operating_area`,`park_area`,`park_place_number`,`service_phone`, - `img_url`,`img_url_h`, `weap_note` + `img_url`,`img_url_h`, `weap_note`, `img_weapp_qrcode`, `img_wemp_qrcode` @@ -86,6 +87,14 @@ and `img_ur_h` = #{imgUrlH} + + + and `img_qrcode_weapp` = #{imgQrcodeWeapp} + + + and `img_qrcode_wemp` = #{imgQrcodeWemp} + + and id in diff --git a/mallinkService/src/main/resources/mapper/WxScreenAdMapper.xml b/mallinkService/src/main/resources/mapper/WxScreenAdMapper.xml new file mode 100644 index 000000000..0ac273f23 --- /dev/null +++ b/mallinkService/src/main/resources/mapper/WxScreenAdMapper.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + `id`, `tenant_id`, `type`, `status`, `create_date`, `update_date`, `cover_img`, `target_id`, `qrcode` + + + + where 1 = 1 + + + and `id` = #{id} + + + + and `tenant_id` = #{tenantId} + + + + and `type` = #{type} + + + + and `status` = #{status} + + + + and `create_date` = #{createDate} + + + + and `update_date` = #{updateDate} + + + + and `cover_img` = #{coverImg} + + + + and `target_id` = #{targetId} + + + + and `hb_cmd` = #{hbCmd} + + + + + and id in + + #{idItem} + + + order by ${sortColumns} + + + + + +