| @@ -1,6 +1,7 @@ | |||||
| package com.iformall.controller; | package com.iformall.controller; | ||||
| import com.alibaba.fastjson.JSONObject; | import com.alibaba.fastjson.JSONObject; | ||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ErrorCode; | 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; | ||||
| @@ -48,7 +49,16 @@ public class WxScreenAdController extends BaseController { | |||||
| public Result list(@ModelAttribute WxScreenAd wxScreenAd, Integer pageNum, Integer pageSize) { | public Result list(@ModelAttribute WxScreenAd wxScreenAd, Integer pageNum, Integer pageSize) { | ||||
| wxScreenAd.setTenantId(getTenantId()); | wxScreenAd.setTenantId(getTenantId()); | ||||
| wxScreenAd.setStatus(EnumScreenAdStatus.VALID.getCode()); | wxScreenAd.setStatus(EnumScreenAdStatus.VALID.getCode()); | ||||
| return new ResultData(wxScreenAdService.listAsPage(wxScreenAd,pageNum,pageSize)); | |||||
| PageInfo<WxScreenAd> page = wxScreenAdService.listAsPage(wxScreenAd,pageNum,pageSize); | |||||
| page.getList().stream().forEach(s->{ | |||||
| Object target = null; | |||||
| if (s.getType().equals(EnumScreenAdType.COUPON.getCode())) | |||||
| target = wxCouponChannelService.findDetailVo(s.getTargetId()); | |||||
| else if (s.getType().equals(EnumScreenAdType.CAMPAIGN.getCode())) | |||||
| target = wxCampaignService.getById(s.getTargetId()); | |||||
| s.setTarget(target); | |||||
| }); | |||||
| return new ResultData(page); | |||||
| } | } | ||||
| @ApiOperation("添加广告") | @ApiOperation("添加广告") | ||||
| @@ -56,8 +66,7 @@ public class WxScreenAdController extends BaseController { | |||||
| public Result add(@RequestBody WxScreenAd wxScreenAd) { | public Result add(@RequestBody WxScreenAd wxScreenAd) { | ||||
| wxScreenAd.setStatus(EnumScreenAdStatus.VALID.getCode()); | wxScreenAd.setStatus(EnumScreenAdStatus.VALID.getCode()); | ||||
| wxScreenAd.setTenantId(getTenantId()); | wxScreenAd.setTenantId(getTenantId()); | ||||
| wxScreenAdService.saveOrUpdate(wxScreenAd); | |||||
| return new ResultData(); | |||||
| return wxScreenAdService.saveOrUpdate(wxScreenAd); | |||||
| } | } | ||||
| @ApiOperation("更新广告") | @ApiOperation("更新广告") | ||||
| @@ -360,6 +360,7 @@ public enum ErrorCode{ | |||||
| */ | */ | ||||
| DEVICE_NOT_FOUND(26000, "设备未找到"), | DEVICE_NOT_FOUND(26000, "设备未找到"), | ||||
| DEVICE_ALREADY_EXIST(26001, "设备已经存在"), | DEVICE_ALREADY_EXIST(26001, "设备已经存在"), | ||||
| DEVICE_QRCODE_GET_FAILED(26002, "微信二维码生成失败,请重试"), | |||||
| ; | ; | ||||
| private int code; | private int code; | ||||
| @@ -2,6 +2,7 @@ package com.iformall.service; | |||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxScreenAd; | import com.iformall.domain.po.WxScreenAd; | ||||
| import java.util.List; | import java.util.List; | ||||
| @@ -34,7 +35,7 @@ public interface WxScreenAdService { | |||||
| * | * | ||||
| * @param record | * @param record | ||||
| */ | */ | ||||
| void saveOrUpdate(WxScreenAd record); | |||||
| ResultData saveOrUpdate(WxScreenAd record); | |||||
| /** | /** | ||||
| @@ -5,8 +5,10 @@ import com.alibaba.fastjson.JSONArray; | |||||
| import com.alibaba.fastjson.JSONObject; | 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.ErrorCode; | |||||
| import com.iformall.common.IdWorker; | import com.iformall.common.IdWorker; | ||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxAppinfo; | import com.iformall.domain.po.WxAppinfo; | ||||
| import com.iformall.domain.po.WxCouponChannel; | import com.iformall.domain.po.WxCouponChannel; | ||||
| import com.iformall.domain.po.WxScreenAd; | import com.iformall.domain.po.WxScreenAd; | ||||
| @@ -54,20 +56,24 @@ public class WxScreenAdServiceImpl implements WxScreenAdService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public void saveOrUpdate(WxScreenAd record) { | |||||
| public ResultData saveOrUpdate(WxScreenAd record) { | |||||
| if (record.getId() == null) { | if (record.getId() == null) { | ||||
| 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()); | ||||
| record.setUpdateDate(new Date()); | record.setUpdateDate(new Date()); | ||||
| setQrcode(record); | setQrcode(record); | ||||
| if (record.getQrcode() == null) | |||||
| return new ResultData(ErrorCode.DEVICE_QRCODE_GET_FAILED); | |||||
| wxScreenAdMapper.insertSelective(record); | wxScreenAdMapper.insertSelective(record); | ||||
| } else { | } else { | ||||
| record.setUpdateDate(new Date()); | record.setUpdateDate(new Date()); | ||||
| setQrcode(record); | setQrcode(record); | ||||
| wxScreenAdMapper.updateByPrimaryKeySelective(record); | wxScreenAdMapper.updateByPrimaryKeySelective(record); | ||||
| } | } | ||||
| return new ResultData(); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -162,12 +168,18 @@ public class WxScreenAdServiceImpl implements WxScreenAdService { | |||||
| byte[] result = null; | byte[] result = null; | ||||
| if(responseEntity.hasBody()) { | if(responseEntity.hasBody()) { | ||||
| result = responseEntity.getBody(); | result = responseEntity.getBody(); | ||||
| try { | |||||
| JSONObject jResult = JSONObject.parseObject(result.toString()); | |||||
| if (jResult != null) { //error | |||||
| logger.error( "QRCODE get error:" + jResult.getIntValue("errcode")+"-"+ jResult.getString("errmsg")); | |||||
| return null; | |||||
| } | |||||
| } catch (Exception e) { | |||||
| return result; | |||||
| } | |||||
| } | } | ||||
| if (result[0]==0xff){ //image | |||||
| return result; | |||||
| } else { | |||||
| logger.error( "QRCODE get error:" + result.toString()); | |||||
| return null; | |||||
| } | |||||
| logger.error( "QRCODE get error responseEntity:" + responseEntity.toString()); | |||||
| return null; | |||||
| } | } | ||||
| } | } | ||||