标签系统
一、增加拿手的興趣標簽和身份標簽,用于后續商家增值服務使用,同時建立基礎的用戶畫像。
1、系統增加兩類標簽
身份標簽:
? 身份標簽為拿手的的用戶屬性,用于描述拿手的自身的特性,具體如下:
? 時尚潮人
? 數碼極客
? 文藝青年
? 運動達人
? 無敵辣媽
? 御宅一族興趣標簽:
? 興趣標簽為淘寶的寶貝類目,用于了解拿手在淘寶上的消費習慣,具體標簽內容如下:
? 服裝鞋包
? 手機數碼
? 家用電器
? 美妝飾品
? 母嬰用品
? 家居建材
? 百貨食品
? 運動戶外
? 文化玩樂
? 生活服務
? 汽配摩托
2、拿手手機端增加打標簽的頁面
? 拿手手機端新增兩個頁面,用于拿手身份標簽和興趣標簽的選擇,界面原型如下,設計稿界面待更新;
? 在設定標簽的過程中,有可能會發生返回的操作,所以在最后點擊“開啟我的白拿拿之旅”時,進行保存的操作
3、標簽頁面觸發入口
- 新注冊用戶:
對于新注冊的用戶,完成注冊或者綁定手機號完成后,直接進入上述的標簽原則頁,且拿手必須完成標簽的選擇后,才可進入到首頁; - 老用戶
對于已注冊的用戶,在返回的首頁的時候(包括點擊分享的鏈接、公眾號底部菜單、其它頁面返回首頁等),如果未設定過身份標簽和興趣標簽,則直接進入標簽設定頁,設定完成后才可以進入到首頁;
4、保存設定的信息到拿手的標簽中
? 拿手設定完成后,保存對應的身份標簽和興趣標簽到該拿手的標簽信息中,同時后臺標簽管理中,需要增加該拿手對應標簽的展示
二、系統設計:
1、標簽配置表:
實體類:
標簽是分級的,這里面是用parent一個字段就可以表示層級關系了
2、用戶標簽對應表
實體類:
package com.zhibi.xiuba.user.spi.model;import com.zhibi.xiuba.user.spi.enums.DataTypeEnum; import com.zhibi.xiuba.utils.StringUtils; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Type;import javax.persistence.*; import java.io.Serializable; import java.util.Date;/*** Created by QinHe on 2018-05-08.* 增值業務配置類*/ @Entity @Table(name = "xb_us_tag_library") public class TagLibrary implements Serializable {private static final long serialVersionUID = -4645714347119745836L;@Id@GeneratedValue(generator = "id_generator")@GenericGenerator(name = "id_generator", strategy = "redis_id")private Long id;/*** 標簽 多對一*/@ManyToOne@JoinColumn(nullable = false, updatable = false, name = "tag_config_id", referencedColumnName = "id")private TagConfig tagConfig;/*** 用戶id*/private Long userId;private String stringValue;private Date dateValue;private Long longValue;@Column(columnDefinition = "bit", length = 1)@Type(type = "org.hibernate.type.NumericBooleanType")private Boolean booleanValue;private Double doubleValue;private Date createTime;private Date updateTime;public TagLibrary() {}public TagLibrary(TagConfig tagConfig, Long userId, Date createTime) {this.tagConfig = tagConfig;this.userId = userId;this.createTime = createTime;}public void setValue(Object value, String dataType) {if (value != null && StringUtils.isNoneBlank(dataType)) {if (DataTypeEnum.DATA_TYPE_ENUM_STRING.getCode().equals(dataType)) {this.stringValue = (String) value;}if (DataTypeEnum.DATA_TYPE_ENUM_DATE.getCode().equals(dataType)) {this.dateValue = (Date) value;}if (DataTypeEnum.DATA_TYPE_ENUM_LONG.getCode().equals(dataType)) {this.longValue = (Long) value;}if (DataTypeEnum.DATA_TYPE_ENUM_BOOLEAN.getCode().equals(dataType)) {this.booleanValue = (Boolean) value;}if (DataTypeEnum.DATA_TYPE_ENUM_DOUBLE.getCode().equals(dataType)) {this.doubleValue = (Double) value;}}this.stringValue = value.toString();this.updateTime = new Date();}public Long getId() {return id;}public void setId(Long id) {this.id = id;}public TagConfig getTagConfig() {return tagConfig;}public void setTagConfig(TagConfig tagConfig) {this.tagConfig = tagConfig;}public Long getUserId() {return userId;}public void setUserId(Long userId) {this.userId = userId;}public String getStringValue() {return stringValue;}public void setStringValue(String stringValue) {this.stringValue = stringValue;}public Date getDateValue() {return dateValue;}public void setDateValue(Date dateValue) {this.dateValue = dateValue;}public Long getLongValue() {return longValue;}public void setLongValue(Long longValue) {this.longValue = longValue;}public Boolean getBooleanValue() {return booleanValue;}public void setBooleanValue(Boolean booleanValue) {this.booleanValue = booleanValue;}public Double getDoubleValue() {return doubleValue;}public void setDoubleValue(Double doubleValue) {this.doubleValue = doubleValue;}public Date getCreateTime() {return createTime;}public void setCreateTime(Date createTime) {this.createTime = createTime;}public Date getUpdateTime() {return updateTime;}public void setUpdateTime(Date updateTime) {this.updateTime = updateTime;} }3、controller方法
package com.zhibi.xiuba.controller;import com.alibaba.fastjson.JSON; import com.zhibi.xiuba.model.ControllerResult; import com.zhibi.xiuba.service.ITagService; import com.zhibi.xiuba.user.spi.enums.TagConfigIdEnum; import com.zhibi.xiuba.user.spi.model.TagConfig; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.web.bind.annotation.*;import java.util.List;@Slf4j @RestController @RequestMapping("/user/tag/") public class TagController {private final ITagService tagService;public TagController(ITagService tagService) {this.tagService = tagService;}@PostMapping("/makeTagForShowker")@ResponseBodypublic ControllerResult makeTagForShowker(@RequestParam Long showkerId,@RequestParam String identityTagJsonStr,@RequestParam String hobbyTagJsonStr) {List<Long> idsIdentity = tagService.findByUserIdAndTagParent(showkerId, TagConfigIdEnum.IDENTITY_TAG_ID.getCode());List<Long> idsHobby = tagService.findByUserIdAndTagParent(showkerId, TagConfigIdEnum.HOBBY_TAG_ID.getCode());if ((idsIdentity != null && idsIdentity.size() > 0) || (idsHobby != null && idsHobby.size() > 0)) {return ControllerResult.build(false, "", "您已經打過標簽了!");}if (StringUtils.isNotBlank(identityTagJsonStr)) {List<Long> tagIds = JSON.parseArray(identityTagJsonStr, Long.class);if (tagIds != null) {if (tagIds.size() > 2) {return ControllerResult.build(false, "", "最多可選兩項!");}for (Long tagId : tagIds) {tagService.createTagForUser(showkerId, tagId);}}}if (StringUtils.isNotBlank(hobbyTagJsonStr)) {List<Long> tagIds = JSON.parseArray(hobbyTagJsonStr, Long.class);if (tagIds != null) {if (tagIds.size() > 4) {return ControllerResult.build(false, "", "最多可選四項!");}for (Long tagId : tagIds) {tagService.createTagForUser(showkerId, tagId);}}}return ControllerResult.ok();}@GetMapping("/getIdentityTag")@ResponseBodypublic ControllerResult getIdentityTag(Long categoryId, Boolean enable) {List<TagConfig> list = tagService.getIdentityTag(categoryId, enable);return ControllerResult.ok(list);}}4、業務邏輯層
package com.zhibi.xiuba.service.impl;import com.zhibi.xiuba.repository.TagConfigRepository; import com.zhibi.xiuba.repository.TagLibraryRepository; import com.zhibi.xiuba.service.ITagService; import com.zhibi.xiuba.user.spi.model.TagConfig; import com.zhibi.xiuba.user.spi.model.TagLibrary; import org.springframework.cache.annotation.Cacheable; import org.springframework.data.domain.Example; import org.springframework.stereotype.Service;import java.util.Date; import java.util.List;/*** Created by QinHe on 2018-07-02.*/ @Service public class TagService implements ITagService {private final TagLibraryRepository tagLibraryRepository;private final TagConfigRepository tagConfigRepository;public TagService(TagLibraryRepository tagLibraryRepository, TagConfigRepository tagConfigRepository) {this.tagLibraryRepository = tagLibraryRepository;this.tagConfigRepository = tagConfigRepository;}@Overridepublic List<Long> findByUserIdAndTagParent(Long userId, Long tagParentId) {return tagLibraryRepository.findByUserIdAndTagParent(userId, tagParentId);}@Override@Cacheable(cacheNames = "Tag", key = "'categoryId_' + #categoryId+'_'+#enable")public List<TagConfig> getIdentityTag(Long categoryId, Boolean enable) {TagConfig tagConfig = new TagConfig();TagConfig parent = new TagConfig();parent.setId(categoryId);tagConfig.setParent(parent);if (enable != null) {tagConfig.setEnabled(enable);}return tagConfigRepository.findAll(Example.of(tagConfig));}@Overridepublic void createTagForUser(Long showkerId, Long tagId) {TagLibrary tagLibrary = new TagLibrary();tagLibrary.setCreateTime(new Date());tagLibrary.setUserId(showkerId);tagLibrary.setTagConfig(tagConfigRepository.findOne(tagId));tagLibraryRepository.save(tagLibrary);} }總結
- 上一篇: 思科路由器配置NAT地址转换
- 下一篇: 双硬盘双系统win10+manjaro-