package com.yeshi.fanli.dao.user;
|
|
import java.math.BigDecimal;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.regex.Pattern;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.data.domain.Sort;
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
import org.springframework.data.mongodb.core.query.Criteria;
|
import org.springframework.data.mongodb.core.query.Query;
|
import org.springframework.data.mongodb.core.query.Update;
|
import org.springframework.stereotype.Repository;
|
|
import com.yeshi.fanli.dto.user.ThreeSaleFocusDTO;
|
import com.yeshi.fanli.entity.bus.user.ThreeSaleFocusInfo;
|
import com.yeshi.fanli.util.StringUtil;
|
|
@Repository
|
public class ThreeSaleFocusInfoDao {
|
|
@Resource
|
private MongoTemplate mongoTemplate;
|
|
/**
|
* 新增
|
*
|
* @param record
|
*/
|
public void save(ThreeSaleFocusInfo record) {
|
if (record == null) {
|
return;
|
}
|
mongoTemplate.save(record);
|
}
|
|
|
/**
|
* 更新标签
|
*
|
* @param record
|
*/
|
public void updateMemoName(Long workerId, int type, String memoName) {
|
if (memoName == null) {
|
memoName = "";
|
}
|
|
Query query = new Query();
|
query.addCriteria(Criteria.where("workerId").is(workerId));
|
|
Update update = null;
|
if (type == 1) {
|
update = Update.update("memoName", memoName);
|
} else {
|
update = Update.update("memoNameSup", memoName);
|
}
|
mongoTemplate.updateFirst(query, update, ThreeSaleFocusInfo.class);
|
}
|
|
/**
|
* 更新标签
|
*
|
* @param record
|
*/
|
public void updateTags(Long workerId, int type, String tags) {
|
if (tags == null) {
|
tags = "";
|
}
|
|
Query query = new Query();
|
query.addCriteria(Criteria.where("workerId").is(workerId));
|
|
Update update = null;
|
if (type == 1) {
|
update = Update.update("tags", tags);
|
} else {
|
update = Update.update("tagsSup", tags);
|
}
|
mongoTemplate.updateFirst(query, update, ThreeSaleFocusInfo.class);
|
}
|
|
/**
|
* 更新昵称
|
* @param workerId
|
* @param nickName
|
*/
|
public void updateNickName(Long workerId, String nickName) {
|
if (nickName == null) {
|
nickName = "";
|
}
|
|
Query query = new Query();
|
query.addCriteria(Criteria.where("workerId").is(workerId));
|
Update update = Update.update("nickName", nickName);
|
mongoTemplate.updateFirst(query, update, ThreeSaleFocusInfo.class);
|
}
|
|
|
/**
|
* 更新是否有效粉丝
|
* @param workerId
|
* @param stateValid
|
*/
|
public void updateStateValid(Long workerId, boolean stateValid) {
|
Query query = new Query();
|
query.addCriteria(Criteria.where("workerId").is(workerId));
|
Update update = Update.update("stateValid", stateValid);
|
mongoTemplate.updateFirst(query, update, ThreeSaleFocusInfo.class);
|
}
|
|
/**
|
* 更新淘宝绑定
|
* @param workerId
|
* @param taobaoBind
|
*/
|
public void updateTaobaoBind(Long workerId, boolean taobaoBind) {
|
Query query = new Query();
|
query.addCriteria(Criteria.where("workerId").is(workerId));
|
Update update = Update.update("taobaoBind", taobaoBind);
|
mongoTemplate.updateFirst(query, update, ThreeSaleFocusInfo.class);
|
}
|
|
/**
|
* 更新微信绑定
|
* @param workerId
|
* @param weixinBind
|
*/
|
public void updateWeixinBind(Long workerId, boolean weixinBind) {
|
Query query = new Query();
|
query.addCriteria(Criteria.where("workerId").is(workerId));
|
Update update = Update.update("weixinBind", weixinBind);
|
mongoTemplate.updateFirst(query, update, ThreeSaleFocusInfo.class);
|
}
|
|
/**
|
* 更新活跃时间
|
* @param workerId
|
* @param activeTime
|
*/
|
public void updateActiveTime(Long workerId, Date activeTime) {
|
Query query = new Query();
|
query.addCriteria(Criteria.where("workerId").is(workerId));
|
Update update = Update.update("activeTime", activeTime);
|
mongoTemplate.updateFirst(query, update, ThreeSaleFocusInfo.class);
|
}
|
|
/**
|
* 更新粉丝数量
|
* @param workerId
|
* @param fansNum
|
*/
|
public void updateFansNum(Long workerId, int fansNum) {
|
Query query = new Query();
|
query.addCriteria(Criteria.where("workerId").is(workerId));
|
Update update = Update.update("fansNum", fansNum);
|
mongoTemplate.updateFirst(query, update, ThreeSaleFocusInfo.class);
|
}
|
|
|
/**
|
* 更新收入
|
* @param workerId
|
* @param income
|
*/
|
public void updateIncome(Long workerId, BigDecimal income) {
|
Query query = new Query();
|
query.addCriteria(Criteria.where("workerId").is(workerId));
|
Update update = Update.update("income", income).set("incomeTime", new Date());
|
mongoTemplate.updateMulti(query, update, ThreeSaleFocusInfo.class);
|
}
|
|
|
/**
|
* 统计
|
* @return
|
*/
|
public ThreeSaleFocusInfo getbyWorkerId(Long workerId) {
|
Query query = new Query();
|
query.addCriteria(Criteria.where("workerId").is(workerId));
|
return mongoTemplate.findOne(query, ThreeSaleFocusInfo.class);
|
}
|
|
/**
|
* 查询
|
*
|
* @return
|
*/
|
public List<ThreeSaleFocusInfo> query(int start, int count, int type, Long uid, ThreeSaleFocusDTO focusDTO) {
|
Query query = createQuery(type, uid, focusDTO);
|
query.skip(start).limit(count);
|
query.with(new Sort(Sort.Direction.DESC,"weight"));
|
return mongoTemplate.find(query, ThreeSaleFocusInfo.class);
|
}
|
|
/**
|
* 统计
|
* @return
|
*/
|
public long count(int type, Long uid, ThreeSaleFocusDTO focusDTO) {
|
Query query = createQuery(type, uid, focusDTO);
|
return mongoTemplate.count(query, ThreeSaleFocusInfo.class);
|
}
|
|
|
private Query createQuery(int type, Long uid, ThreeSaleFocusDTO focusDTO) {
|
Query query = new Query();
|
if (type == 1) {
|
query.addCriteria(Criteria.where("bossId").is(uid));
|
} else {
|
query.addCriteria(Criteria.where("bossSuperId").is(uid));
|
}
|
|
if (focusDTO == null) {
|
return query;
|
}
|
|
if (focusDTO.getStateValid() != null)
|
query.addCriteria(Criteria.where("stateValid").is(focusDTO.getStateValid()));
|
|
if (focusDTO.getTaobaoBind() != null)
|
query.addCriteria(Criteria.where("taobaoBind").is(focusDTO.getTaobaoBind()));
|
|
if (focusDTO.getWeixinBind() != null)
|
query.addCriteria(Criteria.where("weixinBind").is(focusDTO.getWeixinBind()));
|
|
if (focusDTO.getMinFansNum() != null)
|
query.addCriteria(Criteria.where("fansNum").lte(focusDTO.getMinFansNum()));
|
|
if (focusDTO.getMinFansNum() != null)
|
query.addCriteria(Criteria.where("fansNum").gte(focusDTO.getMinFansNum()));
|
|
if (focusDTO.getMinActiveTime() != null)
|
query.addCriteria(Criteria.where("activeTime").lte(focusDTO.getMinActiveTime()));
|
|
if (focusDTO.getMaxActiveTime() != null)
|
query.addCriteria(Criteria.where("activeTime").gte(focusDTO.getMaxActiveTime()));
|
|
if (focusDTO.getMinIncome() != null)
|
query.addCriteria(Criteria.where("income").lte(focusDTO.getMinIncome()));
|
|
if (focusDTO.getMaxIncome() != null)
|
query.addCriteria(Criteria.where("income").gte(focusDTO.getMaxIncome()));
|
|
|
if (!StringUtil.isNullOrEmpty(focusDTO.getKey())) {
|
if (type == 1) {
|
query.addCriteria(new Criteria().orOperator(
|
Criteria.where("nickName").regex(Pattern.compile("^.*" + focusDTO.getKey() + ".*$", Pattern.CASE_INSENSITIVE)),
|
new Criteria().andOperator(Criteria.where("memoName").regex(Pattern.compile("^.*" + focusDTO.getKey() + ".*$", Pattern.CASE_INSENSITIVE))),
|
new Criteria().andOperator(Criteria.where("tags").regex(Pattern.compile("^.*" + focusDTO.getKey() + ".*$", Pattern.CASE_INSENSITIVE)))
|
));
|
} else {
|
query.addCriteria(new Criteria().orOperator(
|
Criteria.where("nickName").regex(Pattern.compile("^.*" + focusDTO.getKey() + ".*$", Pattern.CASE_INSENSITIVE)),
|
new Criteria().andOperator(Criteria.where("memoNameSup").regex(Pattern.compile("^.*" + focusDTO.getKey() + ".*$", Pattern.CASE_INSENSITIVE))),
|
new Criteria().andOperator(Criteria.where("tagsSup").regex(Pattern.compile("^.*" + focusDTO.getKey() + ".*$", Pattern.CASE_INSENSITIVE)))
|
));
|
}
|
}
|
return query;
|
}
|
|
|
|
}
|