package com.yeshi.fanli.dao.user.invite;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.regex.Pattern;
|
|
import org.springframework.data.domain.Sort;
|
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.dao.MongodbBaseDao;
|
import com.yeshi.fanli.dto.user.ThreeSaleFocusDTO;
|
import com.yeshi.fanli.entity.bus.user.TeamFansInfo;
|
import com.yeshi.fanli.util.StringUtil;
|
|
@Repository
|
public class TeamFansInfoDao extends MongodbBaseDao<TeamFansInfo> {
|
|
|
/**
|
* 选择性更新
|
* @param record
|
*/
|
public void updateSelective(TeamFansInfo record) {
|
Query query = new Query();
|
query.addCriteria(Criteria.where("id").is(record.getId()));
|
|
Update update = new Update();
|
if (record.getNickName() != null)
|
update.set("nickName", record.getNickName());
|
if (record.getLevel() != null)
|
update.set("level", record.getLevel().name());
|
if (record.getStateValid() != null)
|
update.set("stateValid", record.getStateValid());
|
if (record.getTaobaoBind() != null)
|
update.set("taobaoBind", record.getTaobaoBind());
|
if (record.getWeixinBind() != null)
|
update.set("weixinBind", record.getWeixinBind());
|
if (record.getWeixinId() != null)
|
update.set("weixinId", record.getWeixinId());
|
if (record.getPhone() != null)
|
update.set("phone", record.getPhone());
|
if (record.getPhoneOpen() != null)
|
update.set("phoneOpen", record.getPhoneOpen());
|
if (record.getInviteCode() != null)
|
update.set("inviteCode", record.getInviteCode());
|
if (record.getActiveTime() != null)
|
update.set("activeTime", record.getActiveTime());
|
if (record.getFansNum() != null)
|
update.set("fansNum", record.getFansNum());
|
if (record.getIncome() != null)
|
update.set("income", record.getIncome());
|
if (record.getIncomeTime() != null)
|
update.set("incomeTime", record.getIncomeTime());
|
if (record.getMemoName() != null)
|
update.set("memoName", record.getMemoName());
|
if (record.getTags() != null)
|
update.set("tags", record.getTags());
|
if (record.getMemoNameSup() != null)
|
update.set("memoNameSup", record.getMemoNameSup());
|
if (record.getTagsSup() != null)
|
update.set("tagsSup", record.getTagsSup());
|
update.set("updateTime", new Date());
|
update(query, update);
|
}
|
|
|
|
/**
|
* 统计
|
*
|
* @return
|
*/
|
public TeamFansInfo getbyWorkerId(Long workerId) {
|
Query query = new Query();
|
query.addCriteria(Criteria.where("workerId").is(workerId));
|
return mongoTemplate.findOne(query, TeamFansInfo.class);
|
}
|
|
/**
|
* 查询
|
*
|
* @return
|
*/
|
public List<TeamFansInfo> 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 findList(query);
|
}
|
|
/**
|
* 统计
|
*
|
* @return
|
*/
|
public long count(int type, Long uid, ThreeSaleFocusDTO focusDTO) {
|
Query query = createQuery(type, uid, focusDTO);
|
return count(query);
|
}
|
|
private Query createQuery(int type, Long uid, ThreeSaleFocusDTO focusDTO) {
|
Query query = new Query();
|
List<Criteria> list = new ArrayList<Criteria>();
|
|
if (type == 1) {
|
list.add(Criteria.where("bossId").is(uid));
|
} else {
|
list.add(Criteria.where("bossSuperId").is(uid));
|
}
|
|
if (focusDTO != null) {
|
if (focusDTO.getStateValid() != null)
|
list.add(Criteria.where("stateValid").is(focusDTO.getStateValid()));
|
|
if (focusDTO.getTaobaoBind() != null)
|
list.add(Criteria.where("taobaoBind").is(focusDTO.getTaobaoBind()));
|
|
if (focusDTO.getWeixinBind() != null)
|
list.add(Criteria.where("weixinBind").is(focusDTO.getWeixinBind()));
|
|
if (!StringUtil.isNullOrEmpty(focusDTO.getLevel()))
|
list.add(Criteria.where("level").is(focusDTO.getLevel()));
|
|
if (focusDTO.getMinFansNum() != null)
|
list.add(Criteria.where("fansNum").gte(focusDTO.getMinFansNum()));
|
|
if (focusDTO.getMaxFansNum() != null)
|
list.add(Criteria.where("fansNum").lte(focusDTO.getMaxFansNum()));
|
|
if (!StringUtil.isNullOrEmpty(focusDTO.getMinJoinTime()))
|
list.add(Criteria.where("joinTime").gte(focusDTO.getMinJoinTime()));
|
|
if (!StringUtil.isNullOrEmpty(focusDTO.getMaxJoinTime()))
|
list.add(Criteria.where("joinTime").lte(focusDTO.getMaxJoinTime()));
|
|
if (!StringUtil.isNullOrEmpty(focusDTO.getMinActiveTime()))
|
list.add(Criteria.where("activeTime").gte(focusDTO.getMinActiveTime()));
|
|
if (!StringUtil.isNullOrEmpty(focusDTO.getMaxActiveTime()))
|
list.add(Criteria.where("activeTime").lte(focusDTO.getMaxActiveTime()));
|
|
if (focusDTO.getMinIncome() != null)
|
list.add(Criteria.where("income").gte(focusDTO.getMinIncome()));
|
|
if (focusDTO.getMaxIncome() != null)
|
list.add(Criteria.where("income").lte(focusDTO.getMaxIncome()));
|
|
if (!StringUtil.isNullOrEmpty(focusDTO.getKey())) {
|
if (type == 1) {
|
list.add(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("weixinId")
|
.regex(Pattern.compile("^.*" + focusDTO.getKey() + ".*$",
|
Pattern.CASE_INSENSITIVE))),
|
new Criteria().andOperator(Criteria.where("inviteCode")
|
.regex(Pattern.compile("^.*" + focusDTO.getKey() + ".*$",
|
Pattern.CASE_INSENSITIVE))),
|
new Criteria().andOperator(Criteria.where("phone")
|
.regex(Pattern.compile("^.*" + focusDTO.getKey() + ".*$",
|
Pattern.CASE_INSENSITIVE)).andOperator(Criteria.where("phoneOpen").is(true))),
|
new Criteria().andOperator(Criteria.where("tags").regex(Pattern
|
.compile("^.*" + focusDTO.getKey() + ".*$", Pattern.CASE_INSENSITIVE)))));
|
} else {
|
list.add(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("weixinId")
|
.regex(Pattern.compile("^.*" + focusDTO.getKey() + ".*$",
|
Pattern.CASE_INSENSITIVE))),
|
new Criteria().andOperator(Criteria.where("inviteCode")
|
.regex(Pattern.compile("^.*" + focusDTO.getKey() + ".*$",
|
Pattern.CASE_INSENSITIVE))),
|
new Criteria().andOperator(Criteria.where("phone")
|
.regex(Pattern.compile("^.*" + focusDTO.getKey() + ".*$",
|
Pattern.CASE_INSENSITIVE)).andOperator(Criteria.where("phoneOpen").is(true))),
|
new Criteria().andOperator(Criteria.where("tagsSup").regex(Pattern
|
.compile("^.*" + focusDTO.getKey() + ".*$", Pattern.CASE_INSENSITIVE)))));
|
}
|
}
|
}
|
|
if (list.size() > 0) {
|
Criteria[] cas = new Criteria[list.size()];
|
for (int i = 0; i < list.size(); i++)
|
cas[i] = list.get(i);
|
query.addCriteria(new Criteria().andOperator(cas));
|
}
|
|
return query;
|
}
|
|
}
|