| @@ -6,13 +6,11 @@ import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxDevice; | import com.iformall.domain.po.WxDevice; | ||||
| import com.iformall.domain.po.WxMall; | |||||
| import com.iformall.domain.po.WxScreenAd; | import com.iformall.domain.po.WxScreenAd; | ||||
| import com.iformall.enums.EnumScreenAdStatus; | import com.iformall.enums.EnumScreenAdStatus; | ||||
| import com.iformall.enums.EnumScreenAdType; | 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.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| @@ -22,6 +20,7 @@ import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
| import java.util.Date; | |||||
| import java.util.List; | import java.util.List; | ||||
| @RestController | @RestController | ||||
| @@ -33,6 +32,9 @@ public class WxDeviceScreenAdController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private WxScreenAdService wxScreenAdService; | private WxScreenAdService wxScreenAdService; | ||||
| @Autowired | |||||
| private WxMallService wxMallService; | |||||
| @Autowired | @Autowired | ||||
| private WxDeviceService wxDeviceService; | private WxDeviceService wxDeviceService; | ||||
| @@ -61,7 +63,7 @@ public class WxDeviceScreenAdController extends BaseController { | |||||
| @ApiImplicitParams({ | @ApiImplicitParams({ | ||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | ||||
| @ApiImplicitParam(name = "pageSize", 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); | WxDevice wxDevice = findDevice(deviceId); | ||||
| if (wxDevice == null) | if (wxDevice == null) | ||||
| @@ -83,20 +85,25 @@ public class WxDeviceScreenAdController extends BaseController { | |||||
| @ApiOperation("心跳") | @ApiOperation("心跳") | ||||
| @PostMapping("heartbeat") | @PostMapping("heartbeat") | ||||
| public Result heartbeat(@RequestBody String deviceId) { | |||||
| public Result heartbeat(@RequestParam String deviceId,@RequestBody String version) { | |||||
| WxDevice wxDevice = findDevice(deviceId); | WxDevice wxDevice = findDevice(deviceId); | ||||
| if (wxDevice == null) | if (wxDevice == null) | ||||
| return new ResultData(ErrorCode.DEVICE_NOT_FOUND); | 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("基础信息") | @ApiOperation("基础信息") | ||||
| @GetMapping("info") | @GetMapping("info") | ||||
| public Result detail(@RequestBody String deviceId) { | |||||
| public Result info(@RequestParam String deviceId) { | |||||
| WxDevice wxDevice = findDevice(deviceId); | WxDevice wxDevice = findDevice(deviceId); | ||||
| if (wxDevice == null) | if (wxDevice == null) | ||||
| return new ResultData(ErrorCode.DEVICE_NOT_FOUND); | return new ResultData(ErrorCode.DEVICE_NOT_FOUND); | ||||
| return new ResultData(); | |||||
| return new ResultData(wxMallService.getByTenantId(wxDevice.getTenantId())); | |||||
| } | } | ||||
| } | } | ||||
| @@ -82,6 +82,11 @@ public class WxMall implements Serializable { | |||||
| @io.swagger.annotations.ApiModelProperty(value="商场图标",name="imgUrlH") | @io.swagger.annotations.ApiModelProperty(value="商场图标",name="imgUrlH") | ||||
| private String 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") | @io.swagger.annotations.ApiModelProperty(value="小程序提示",name="weapNote") | ||||
| private String weapNote; | private String weapNote; | ||||
| @@ -195,6 +200,22 @@ public class WxMall implements Serializable { | |||||
| this.buildings = buildings; | 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 | public static enum Field | ||||
| { | { | ||||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | ||||
| @@ -68,6 +68,10 @@ public class WxScreenAd implements Serializable { | |||||
| @io.swagger.annotations.ApiModelProperty(value="广告目标ID",name="targetId") | @io.swagger.annotations.ApiModelProperty(value="广告目标ID",name="targetId") | ||||
| private Long targetId; | private Long targetId; | ||||
| /**广告目标二维码**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="二维码",name="qrcode") | |||||
| private byte[] qrcode; | |||||
| @Transient | @Transient | ||||
| protected Object target; | protected Object target; | ||||
| @@ -135,6 +139,14 @@ public class WxScreenAd implements Serializable { | |||||
| this.targetId = targetId; | this.targetId = targetId; | ||||
| } | } | ||||
| public byte[] getQrcode() { | |||||
| return qrcode; | |||||
| } | |||||
| public void setQrcode(byte[] qrcode) { | |||||
| this.qrcode = qrcode; | |||||
| } | |||||
| public static enum Field | public static enum Field | ||||
| { | { | ||||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | ||||
| @@ -1,19 +1,32 @@ | |||||
| package com.iformall.service.impl; | 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.PageHelper; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.common.IdWorker; | import com.iformall.common.IdWorker; | ||||
| import com.iformall.domain.po.WxAppinfo; | |||||
| import com.iformall.domain.po.WxScreenAd; | import com.iformall.domain.po.WxScreenAd; | ||||
| import com.iformall.enums.EnumScreenAdType; | |||||
| import com.iformall.mapper.WxScreenAdMapper; | import com.iformall.mapper.WxScreenAdMapper; | ||||
| import com.iformall.service.WxAppinfoService; | |||||
| import com.iformall.service.WxScreenAdService; | import com.iformall.service.WxScreenAdService; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | 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.stereotype.Service; | ||||
| import org.springframework.web.client.RestTemplate; | |||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.util.HashMap; | |||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Map; | |||||
| @Service | @Service | ||||
| public class WxScreenAdServiceImpl implements WxScreenAdService { | public class WxScreenAdServiceImpl implements WxScreenAdService { | ||||
| @@ -22,6 +35,9 @@ public class WxScreenAdServiceImpl implements WxScreenAdService { | |||||
| @Autowired | @Autowired | ||||
| WxScreenAdMapper wxScreenAdMapper; | WxScreenAdMapper wxScreenAdMapper; | ||||
| @Autowired | |||||
| WxAppinfoService wxAppinfoService; | |||||
| @Override | @Override | ||||
| public PageInfo<WxScreenAd> listAsPage(WxScreenAd record, Integer pageIndex, Integer pageSize) { | public PageInfo<WxScreenAd> listAsPage(WxScreenAd record, Integer pageIndex, Integer pageSize) { | ||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxScreenAdMapper.findList(record)); | return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxScreenAdMapper.findList(record)); | ||||
| @@ -38,9 +54,12 @@ public class WxScreenAdServiceImpl implements WxScreenAdService { | |||||
| final IdWorker idWorker = IdWorker.get(); | final IdWorker idWorker = IdWorker.get(); | ||||
| record.setId(idWorker.nextId()); | record.setId(idWorker.nextId()); | ||||
| record.setCreateDate(new Date()); | record.setCreateDate(new Date()); | ||||
| setQrcode(record); | |||||
| wxScreenAdMapper.insertSelective(record); | wxScreenAdMapper.insertSelective(record); | ||||
| } else { | } else { | ||||
| record.setUpdateDate(new Date()); | record.setUpdateDate(new Date()); | ||||
| setQrcode(record); | |||||
| wxScreenAdMapper.updateByPrimaryKeySelective(record); | wxScreenAdMapper.updateByPrimaryKeySelective(record); | ||||
| } | } | ||||
| } | } | ||||
| @@ -49,9 +68,67 @@ public class WxScreenAdServiceImpl implements WxScreenAdService { | |||||
| public void deleteById(Long id) { | public void deleteById(Long id) { | ||||
| wxScreenAdMapper.deleteByPrimaryKey(id); | wxScreenAdMapper.deleteByPrimaryKey(id); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public List<WxScreenAd> findList(WxScreenAd wxTagsType) { | public List<WxScreenAd> findList(WxScreenAd wxTagsType) { | ||||
| return wxScreenAdMapper.findList(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<String,Object> 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<Map<String,Object>> entity = new HttpEntity<Map<String,Object>>(map, headers); | |||||
| String reqUrl =wxacodeunlimit+accessToken; | |||||
| RestTemplate restTemplate = new RestTemplate(); | |||||
| ResponseEntity<byte[]> responseEntity = restTemplate.postForEntity(reqUrl, entity, byte[].class); | |||||
| if(responseEntity.hasBody()) { | |||||
| return responseEntity.getBody(); | |||||
| } else { | |||||
| return null; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -18,13 +18,14 @@ | |||||
| <result column="img_url" jdbcType="VARCHAR" property="imgUrl"/> | <result column="img_url" jdbcType="VARCHAR" property="imgUrl"/> | ||||
| <result column="img_url_h" jdbcType="VARCHAR" property="imgUrlH"/> | <result column="img_url_h" jdbcType="VARCHAR" property="imgUrlH"/> | ||||
| <result column="weap_note" jdbcType="VARCHAR" property="weapNote"/> | <result column="weap_note" jdbcType="VARCHAR" property="weapNote"/> | ||||
| <result column="img_qrcode_weapp" jdbcType="VARCHAR" property="imgQrcodeWeapp"/> | |||||
| <result column="img_qrcode_wemp" jdbcType="VARCHAR" property="imgQrcodeWemp"/> | |||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| `id`,`tenant_id`,`name`,`group`,`country`,`province`,`city`,`addr`, | `id`,`tenant_id`,`name`,`group`,`country`,`province`,`city`,`addr`, | ||||
| `total_area`,`operating_area`,`park_area`,`park_place_number`,`service_phone`, | `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` | |||||
| </sql> | </sql> | ||||
| <sql id="dynamicWhereConditions"> | <sql id="dynamicWhereConditions"> | ||||
| @@ -86,6 +87,14 @@ | |||||
| <if test=" null != imgUrlH "> | <if test=" null != imgUrlH "> | ||||
| and `img_ur_h` = #{imgUrlH} | and `img_ur_h` = #{imgUrlH} | ||||
| </if> | </if> | ||||
| <if test=" null != imgWeappQrcode "> | |||||
| and `img_qrcode_weapp` = #{imgQrcodeWeapp} | |||||
| </if> | |||||
| <if test=" null != imgWempQrcode "> | |||||
| and `img_qrcode_wemp` = #{imgQrcodeWemp} | |||||
| </if> | |||||
| <if test=" null != ids "> | <if test=" null != ids "> | ||||
| and id in | and id in | ||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | ||||
| @@ -0,0 +1,78 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
| <mapper namespace="com.iformall.mapper.WxScreenAdMapper"> | |||||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxScreenAd"> | |||||
| <id column="id" jdbcType="BIGINT" property="id"/> | |||||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/> | |||||
| <result column="type" jdbcType="INTEGER" property="type"/> | |||||
| <result column="status" jdbcType="INTEGER" property="status"/> | |||||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/> | |||||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/> | |||||
| <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/> | |||||
| <result column="target_id" jdbcType="BIGINT" property="targetId"/> | |||||
| <result column="qrcode" jdbcType="BLOB" property="qrcode"/> | |||||
| </resultMap> | |||||
| <sql id="allColumns"> | |||||
| `id`, `tenant_id`, `type`, `status`, `create_date`, `update_date`, `cover_img`, `target_id`, `qrcode` | |||||
| </sql> | |||||
| <sql id="dynamicWhereConditions"> | |||||
| where 1 = 1 | |||||
| <if test=" null != id "> | |||||
| and `id` = #{id} | |||||
| </if> | |||||
| <if test=" null != tenantId "> | |||||
| and `tenant_id` = #{tenantId} | |||||
| </if> | |||||
| <if test=" null != type "> | |||||
| and `type` = #{type} | |||||
| </if> | |||||
| <if test=" null != status "> | |||||
| and `status` = #{status} | |||||
| </if> | |||||
| <if test=" null != createDate "> | |||||
| and `create_date` = #{createDate} | |||||
| </if> | |||||
| <if test=" null != updateDate "> | |||||
| and `update_date` = #{updateDate} | |||||
| </if> | |||||
| <if test=" null != coverImg "> | |||||
| and `cover_img` = #{coverImg} | |||||
| </if> | |||||
| <if test=" null != targetId "> | |||||
| and `target_id` = #{targetId} | |||||
| </if> | |||||
| <if test=" null != hbCmd "> | |||||
| and `hb_cmd` = #{hbCmd} | |||||
| </if> | |||||
| <if test=" null != ids "> | |||||
| and id in | |||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||||
| #{idItem} | |||||
| </foreach> | |||||
| </if> | |||||
| <if test=" null != sortColumns">order by ${sortColumns}</if> | |||||
| </sql> | |||||
| <select id="findList" parameterType="com.iformall.domain.po.WxDevice" resultMap="BaseResultMap"> | |||||
| select | |||||
| <include refid="allColumns"/> | |||||
| from wx_screen_ad | |||||
| <include refid="dynamicWhereConditions"/> | |||||
| </select> | |||||
| </mapper> | |||||