修改一些bug

This commit is contained in:
xuwenbo
2020-08-12 00:23:44 +08:00
parent f01b16bc7c
commit a4f2800ee7
6 changed files with 62 additions and 5 deletions

View File

@ -9,12 +9,14 @@
package co.yixiang.modules.wechat.rest; package co.yixiang.modules.wechat.rest;
import java.util.Arrays; import java.util.Arrays;
import co.yixiang.dozer.service.IGenerator; import co.yixiang.dozer.service.IGenerator;
import co.yixiang.modules.wechat.service.WxMaLiveGoodsService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import co.yixiang.logging.aop.log.Log; import co.yixiang.logging.aop.log.Log;
import co.yixiang.modules.wechat.domain.YxWechatLiveGoods; import co.yixiang.modules.wechat.domain.YxWechatLiveGoods;
import co.yixiang.modules.wechat.service.YxWechatLiveGoodsService; import co.yixiang.modules.wechat.service.YxWechatLiveGoodsService;
import co.yixiang.modules.wechat.service.dto.YxWechatLiveGoodsQueryCriteria; import co.yixiang.modules.wechat.service.dto.YxWechatLiveGoodsQueryCriteria;
import co.yixiang.modules.wechat.service.dto.YxWechatLiveGoodsDto; import co.yixiang.modules.wechat.service.dto.YxWechatLiveGoodsDto;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -37,7 +39,7 @@ public class YxWechatLiveGoodsController {
private final YxWechatLiveGoodsService yxWechatLiveGoodsService; private final YxWechatLiveGoodsService yxWechatLiveGoodsService;
private final IGenerator generator; private final IGenerator generator;
private final WxMaLiveGoodsService wxMaLiveGoodsService;
@Log("导出数据") @Log("导出数据")
@ApiOperation("导出数据") @ApiOperation("导出数据")
@ -68,7 +70,7 @@ public class YxWechatLiveGoodsController {
@ApiOperation("修改yxWechatLiveGoods") @ApiOperation("修改yxWechatLiveGoods")
@PreAuthorize("@el.check('admin','yxWechatLiveGoods:edit')") @PreAuthorize("@el.check('admin','yxWechatLiveGoods:edit')")
public ResponseEntity<Object> update(@Validated @RequestBody YxWechatLiveGoods resources){ public ResponseEntity<Object> update(@Validated @RequestBody YxWechatLiveGoods resources){
yxWechatLiveGoodsService.updateById(resources); yxWechatLiveGoodsService.updategoods(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT); return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} }
@ -78,7 +80,7 @@ public class YxWechatLiveGoodsController {
@DeleteMapping @DeleteMapping
public ResponseEntity<Object> deleteAll(@RequestBody Long[] ids) { public ResponseEntity<Object> deleteAll(@RequestBody Long[] ids) {
Arrays.asList(ids).forEach(id->{ Arrays.asList(ids).forEach(id->{
yxWechatLiveGoodsService.removeById(id); yxWechatLiveGoodsService.removegoods(id);
}); });
return new ResponseEntity<>(HttpStatus.OK); return new ResponseEntity<>(HttpStatus.OK);
} }

View File

@ -49,4 +49,8 @@ public interface YxWechatLiveGoodsService extends BaseService<YxWechatLiveGoods
boolean saveGoods(YxWechatLiveGoods resources); boolean saveGoods(YxWechatLiveGoods resources);
boolean synchroWxOlLive(List<Integer> goodsIds); boolean synchroWxOlLive(List<Integer> goodsIds);
void removegoods(Long id);
void updategoods(YxWechatLiveGoods resources);
} }

View File

@ -20,11 +20,15 @@ import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
@Data @Data
public class YxWechatLiveDto implements Serializable { public class YxWechatLiveDto implements Serializable {
/** 直播间id */ /** 直播间id */
/** 防止精度丢失 */ /** 防止精度丢失 */
@JsonSerialize(using= ToStringSerializer.class) @JsonSerialize(using= ToStringSerializer.class)
private Long roomid; private Long roomid;
private Long id;
/** 直播间标题 */ /** 直播间标题 */
private String name; private String name;

View File

@ -20,6 +20,9 @@ import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
@Data @Data
public class YxWechatLiveGoodsDto implements Serializable { public class YxWechatLiveGoodsDto implements Serializable {
private Long id;
/** 直播商品id */ /** 直播商品id */
/** 防止精度丢失 */ /** 防止精度丢失 */
@JsonSerialize(using= ToStringSerializer.class) @JsonSerialize(using= ToStringSerializer.class)

View File

@ -9,6 +9,7 @@
package co.yixiang.modules.wechat.service.impl; package co.yixiang.modules.wechat.service.impl;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import co.yixiang.exception.BadRequestException; import co.yixiang.exception.BadRequestException;
@ -87,13 +88,50 @@ public class YxWechatLiveGoodsServiceImpl extends BaseServiceImpl<YxWechatLiveGo
} }
return true; return true;
} }
@Override
public void removegoods(Long id) {
this.removeById(id);
try {
wxMaLiveGoodsService.deleteGoods(id.intValue());
} catch (WxErrorException e) {
e.printStackTrace();
}
}
@Override
public void updategoods(YxWechatLiveGoods resources) {
YxWechatLiveGoods wechatLiveGoods = this.getById(resources.getGoodsId());
try {
WxMaService wxMaService = WxMaConfiguration.getWxMaService();
if(ObjectUtil.isNotEmpty(wechatLiveGoods)){
/** 审核状态 0未审核1审核中2:审核通过3审核失败 */
if("2".equals(wechatLiveGoods.getAuditStatus())){
}else if("0".equals(wechatLiveGoods.getAuditStatus())){
resources.setCoverImgUrl(uploadPhotoToWx(wxMaService,resources.getCoverImgeUrl()).getMediaId());
}else if("1".equals(wechatLiveGoods.getAuditStatus())){
throw new BadRequestException("商品审核中不允许修改");
}
}
WxMaLiveInfo.Goods goods = generator.convert(resources, WxMaLiveInfo.Goods.class);
boolean wxMaLiveResult = wxMaLiveGoodsService.updateGoods(goods);
this.saveOrUpdate(resources);
} catch (WxErrorException e) {
throw new BadRequestException(e.toString());
}
}
@Override @Override
//@Cacheable //@Cacheable
public Map<String, Object> queryAll(YxWechatLiveGoodsQueryCriteria criteria, Pageable pageable) { public Map<String, Object> queryAll(YxWechatLiveGoodsQueryCriteria criteria, Pageable pageable) {
getPage(pageable); getPage(pageable);
PageInfo<YxWechatLiveGoods> page = new PageInfo<>(queryAll(criteria)); PageInfo<YxWechatLiveGoods> page = new PageInfo<>(queryAll(criteria));
Map<String, Object> map = new LinkedHashMap<>(2); Map<String, Object> map = new LinkedHashMap<>(2);
map.put("content", generator.convert(page.getList(), YxWechatLiveGoodsDto.class)); List<YxWechatLiveGoodsDto> goodsDtos = generator.convert(page.getList(), YxWechatLiveGoodsDto.class);
goodsDtos.forEach(i ->{
i.setId(i.getGoodsId());
});
map.put("content",goodsDtos);
map.put("totalElements", page.getTotal()); map.put("totalElements", page.getTotal());
return map; return map;
} }

View File

@ -11,6 +11,7 @@ package co.yixiang.modules.wechat.service.impl;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import co.yixiang.exception.BadRequestException;
import co.yixiang.modules.wechat.domain.YxWechatLive; import co.yixiang.modules.wechat.domain.YxWechatLive;
import co.yixiang.common.service.impl.BaseServiceImpl; import co.yixiang.common.service.impl.BaseServiceImpl;
import co.yixiang.dozer.service.IGenerator; import co.yixiang.dozer.service.IGenerator;
@ -96,7 +97,11 @@ public class YxWechatLiveServiceImpl extends BaseServiceImpl<YxWechatLiveMapper,
PageInfo<YxWechatLive> page = new PageInfo<>(queryAll(criteria)); PageInfo<YxWechatLive> page = new PageInfo<>(queryAll(criteria));
Map<String, Object> map = new LinkedHashMap<>(2); Map<String, Object> map = new LinkedHashMap<>(2);
// List<WxMaLiveResult.RoomInfo> liveInfos = wxMaLiveService.getLiveInfos(); // List<WxMaLiveResult.RoomInfo> liveInfos = wxMaLiveService.getLiveInfos();
map.put("content", generator.convert(page.getList(), YxWechatLiveDto.class)); List<YxWechatLiveDto> liveDtos = generator.convert(page.getList(), YxWechatLiveDto.class);
liveDtos.forEach(i ->{
i.setId(i.getRoomid());
});
map.put("content",liveDtos);
map.put("totalElements", page.getTotal()); map.put("totalElements", page.getTotal());
return map; return map;
} }
@ -115,6 +120,7 @@ public class YxWechatLiveServiceImpl extends BaseServiceImpl<YxWechatLiveMapper,
this.save(resources); this.save(resources);
} catch (WxErrorException e) { } catch (WxErrorException e) {
e.printStackTrace(); e.printStackTrace();
throw new BadRequestException(e.toString());
} }
return false; return false;
} }