原型模式重构业务代码

原型类:UsrPlayRecord

  1. public class UsrPlayRecord extends BaseRequest2 implements Serializable{
  2.     
  3.     private static final long serialVersionUID = 1L;
  4.     
  5.     //播放记录编号
  6.     private Long id;
  7.     //用户ID
  8.     private Long userId;
  9.     //联想用户ID
  10.     private String lenovoUserId;
  11.     //模式 0:默认 1:儿童模式
  12.     private String mode;
  13.     //剧集ID
  14.     private Long conAlbumId;
  15.     //cp剧集ID
  16.     private String outConAlbumId;
  17.     //子剧集ID
  18.     private Long conContentId;
  19.     //cp子剧集ID
  20.     private String outConContentId;
  21.     //一级分类
  22.     private String category1Ids;
  23.     //二级分类
  24.     private String category2Ids;
  25.     //播放内容名称
  26.     private String contentName;
  27.     //播放地址
  28.     private String playUrl;
  29.     //海报
  30.     private String poster;
  31.     //PLATFORM
  32.     private Long platform;
  33.     //创建时间
  34.     private Date cDate;
  35.     //更新时间
  36.     private Date uDate;
  37.     //最后上报时间
  38.     private String updateTime;
  39.     //是否删除
  40.     private String  status; 
  41.     //播放记录时间
  42.     private Long currPlayTime;
  43.     //总时长
  44.     private Long duration;
  45.     //mm:ss时长
  46.     private String fDuration;
  47.     private String bssToken;
  48.     private String filterShort;

目标类:PlayRecord

  1. public class PlayRecord {
  2.     
  3.     /** 主键ID*/
  4.     private Long recordId;
  5.     /** 剧集编号 */
  6.     private Long conAlbumId;
  7.     /** cp剧集编号 */
  8.     private String outConAlbumId;
  9.     /** 子剧集编号 */
  10.     private Long conContentId;
  11.     /** 播放内容名称 */
  12.     private String contentName;
  13.     /** 模式 */
  14.     private String mode;
  15.     /** 播放地址 */
  16.     private String playUrl;
  17.     /**  海报url */
  18.     private String poster="";
  19.     /** 修改时间 */
  20.     private String updateTime;
  21.     /** 修改时间2 */
  22.     private Date updateTime2;
  23.     /** 当前影视播放时间 */
  24.     private Long currPlayTime;
  25.     /** cp子剧集编号 */
  26.     private String outConContentId;
  27.     /** cpId */
  28.     private String cpId;
  29.     /** 剧集时间 */
  30.     private String duration = "";
  31.     /** 剧集时间 */
  32.     private Long durationL = 0L;
  33.     /** 剩余时间 */
  34.     private String remainIngTime = "";
  35.     /** 是否为剧集0:电影1:电视剧、综艺 */
  36.     private String albumType;
  37.     /** 下一集 子剧集编号 */
  38.     private Long nextConContentId = 0L;
  39.     /** 下一集 cp子剧集编号  */
  40.     private String nextOutConContentId = "0";
  41.     /** 播放内容名称 */
  42.     private String nextContentName = "";
  43.     /** 当前集数 */
  44.     private String orderNumber;
  45.     /** 下一集数 */
  46.     private String nextOrderNumber;
  47.     /** 是否是正片 */
  48.     private String isMain;
  49.     /** 一级分类 */
  50.     private String category1Ids;
  51.     /** 二级分类 */
  52.     private String category2Ids;
  53.     /** 是否是VIP视频 */
  54.     private String payMark;
  55.     /** 是否可播放 */
  56.     private String isPlay;
  57.     /** 上次播放平台 */
  58.     private Long platform;

//未使用原型模式之前代码

  1. private PlayRecord getRecord(UsrPlayRecord record) {
  2.         PlayRecord returnRecord = new PlayRecord();
  3.         returnRecord.setRecordId(record.getId());
  4.         returnRecord.setPlayUrl(record.getPlayUrl());
  5.         returnRecord.setPlatform(record.getPlatform());
  6.         returnRecord.setUpdateTime2(record.getuDate());
  7.         returnRecord.setCpId(record.getCpId());
  8.         returnRecord.setConAlbumId(record.getConAlbumId());
  9.         returnRecord.setCurrPlayTime(record.getCurrPlayTime());
  10.         returnRecord.setContentName(record.getContentName());
  11.         returnRecord.setConContentId(record.getConContentId());
  12.         returnRecord.setOutConAlbumId(record.getOutConAlbumId());
  13.         returnRecord.setOutConContentId(record.getOutConContentId());
  14. }

使用原型模式后

  1. private PlayRecord getRecord(UsrPlayRecord record) {
  2.         PlayRecord returnRecord = new PlayRecord();
  3.         try {
  4.             BeanUtils.copyProperties(returnRecord, record);
  5.         } catch (Exception e) {
  6.             throw new RuntimeException("克隆对象出错!");
  7.         }
  8.         return returnRecord ;
  9. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值