| | |
| | | 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.dao.MongodbBaseDao;
|
| | | import com.yeshi.fanli.dto.user.ThreeSaleFocusDTO;
|
| | | import com.yeshi.fanli.entity.bus.user.TeamFansInfo;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | |
|
| | | @Repository
|
| | | public class TeamFansInfoDao {
|
| | | public class TeamFansInfoDao extends MongodbBaseDao<TeamFansInfo> {
|
| | |
|
| | | @Resource
|
| | | private MongoTemplate mongoTemplate;
|
| | |
|
| | | /**
|
| | | * 新增
|
| | | * |
| | | * 选择性更新
|
| | | * @param record
|
| | | */
|
| | | public void save(TeamFansInfo record) {
|
| | | if (record == null) {
|
| | | return;
|
| | | }
|
| | | mongoTemplate.save(record);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 更新标签
|
| | | * |
| | | * @param record
|
| | | */
|
| | | public void updateMemoName(Long workerId, int type, String memoName) {
|
| | | if (memoName == null) {
|
| | | memoName = "";
|
| | | }
|
| | |
|
| | | public void updateSelective(TeamFansInfo record) {
|
| | | Query query = new Query();
|
| | | query.addCriteria(Criteria.where("workerId").is(workerId));
|
| | | query.addCriteria(Criteria.where("id").is(record.getId()));
|
| | |
|
| | | Update update = null;
|
| | | if (type == 1) {
|
| | | update = Update.update("memoName", memoName);
|
| | | } else {
|
| | | update = Update.update("memoNameSup", memoName);
|
| | | }
|
| | | mongoTemplate.updateFirst(query, update, TeamFansInfo.class);
|
| | | 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.getWeixinId() != null)
|
| | | update.set("weixinId", record.getWeixinId());
|
| | | if (record.getWeixinIdExist() != null)
|
| | | update.set("weixinIdExist", record.getWeixinIdExist());
|
| | | 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);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 更新标签
|
| | | * |
| | | * @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, TeamFansInfo.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, TeamFansInfo.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, TeamFansInfo.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, TeamFansInfo.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, TeamFansInfo.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, TeamFansInfo.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, TeamFansInfo.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, TeamFansInfo.class);
|
| | | }
|
| | |
|
| | | |
| | | |
| | | /**
|
| | | * 统计
|
| | | *
|
| | |
| | | Query query = createQuery(type, uid, focusDTO);
|
| | | query.skip(start).limit(count);
|
| | | query.with(new Sort(Sort.Direction.DESC, "weight"));
|
| | | return mongoTemplate.find(query, TeamFansInfo.class);
|
| | | return findList(query);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | */
|
| | | public long count(int type, Long uid, ThreeSaleFocusDTO focusDTO) {
|
| | | Query query = createQuery(type, uid, focusDTO);
|
| | | return mongoTemplate.count(query, TeamFansInfo.class);
|
| | | 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("taobaoBind").is(focusDTO.getTaobaoBind()));
|
| | |
|
| | | if (focusDTO.getWeixinBind() != null)
|
| | | list.add(Criteria.where("weixinBind").is(focusDTO.getWeixinBind()));
|
| | | list.add(Criteria.where("weixinIdExist").is(focusDTO.getWeixinBind()));
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(focusDTO.getLevel()))
|
| | | list.add(Criteria.where("level").is(focusDTO.getLevel()));
|
| | |
| | | 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 (focusDTO.getMinIncome() != null) {
|
| | | int income = focusDTO.getMinIncome().multiply(BigDecimal.valueOf(100)).setScale(2, BigDecimal.ROUND_DOWN).intValue();
|
| | | list.add(Criteria.where("income").gte(income));
|
| | | }
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(focusDTO.getMaxJoinTime()))
|
| | | list.add(Criteria.where("joinTime").lte(focusDTO.getMaxJoinTime()));
|
| | | if (focusDTO.getMaxIncome() != null) {
|
| | | int income = focusDTO.getMaxIncome().multiply(BigDecimal.valueOf(100)).setScale(2, BigDecimal.ROUND_DOWN).intValue();
|
| | | list.add(Criteria.where("income").lte(income));
|
| | | }
|
| | | |
| | | if (!StringUtil.isNullOrEmpty(focusDTO.getMinJoinTime())) {
|
| | | Date date = TimeUtil.parseDotYYYYMMDD(focusDTO.getMinJoinTime());
|
| | | list.add(Criteria.where("joinTime").gte(date));
|
| | | }
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(focusDTO.getMinActiveTime()))
|
| | | list.add(Criteria.where("activeTime").gte(focusDTO.getMinActiveTime()));
|
| | | if (!StringUtil.isNullOrEmpty(focusDTO.getMaxJoinTime())) {
|
| | | Date date = TimeUtil.parseDotCommon(focusDTO.getMaxJoinTime() + " 23:59:59");
|
| | | list.add(Criteria.where("joinTime").lte(date));
|
| | | }
|
| | | |
| | | if (!StringUtil.isNullOrEmpty(focusDTO.getMinActiveTime())) {
|
| | | Date date = TimeUtil.parseDotYYYYMMDD(focusDTO.getMinActiveTime());
|
| | | list.add(Criteria.where("activeTime").gte(date));
|
| | | }
|
| | |
|
| | | 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.getMaxActiveTime())) {
|
| | | Date date = TimeUtil.parseDotCommon(focusDTO.getMaxActiveTime() + " 23:59:59");
|
| | | list.add(Criteria.where("activeTime").lte(date));
|
| | | }
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(focusDTO.getKey())) {
|
| | | if (type == 1) {
|
| | |
| | | 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 {
|
| | |
| | | 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)))));
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | Query query = new Query();
|
| | | if (list.size() > 0) {
|
| | |
|
| | | Criteria[] cas = new Criteria[list.size()];
|
| | | for (int i = 0; i < list.size(); i++)
|
| | | cas[i] = list.get(i);
|