From ec21251764082bebde0f68966332751c288d786c Mon Sep 17 00:00:00 2001 From: admin <2780501319@qq.com> Date: 星期一, 22 十一月 2021 00:13:52 +0800 Subject: [PATCH] 接口编写 --- app/src/main/java/com/yeshi/location/app/service/impl/location/LocationUsersServiceImpl.java | 155 +++++++++++++++++++++++++++++++++------------------ 1 files changed, 99 insertions(+), 56 deletions(-) diff --git a/app/src/main/java/com/yeshi/location/app/service/impl/location/LocationUsersServiceImpl.java b/app/src/main/java/com/yeshi/location/app/service/impl/location/LocationUsersServiceImpl.java index fec9113..02a702f 100644 --- a/app/src/main/java/com/yeshi/location/app/service/impl/location/LocationUsersServiceImpl.java +++ b/app/src/main/java/com/yeshi/location/app/service/impl/location/LocationUsersServiceImpl.java @@ -8,8 +8,11 @@ import java.util.Arrays; import java.util.Date; + import org.yeshi.utils.bean.BeanUtil; + import java.util.List; + import com.yeshi.location.app.dao.location.LocationUsersDao; import com.yeshi.location.app.entity.location.LocationUsers; import com.yeshi.location.app.service.inter.location.LocationUsersService; @@ -20,72 +23,112 @@ import org.springframework.data.mongodb.core.query.Query; @Service -public class LocationUsersServiceImpl implements LocationUsersService{ +public class LocationUsersServiceImpl implements LocationUsersService { - @Resource - private LocationUsersDao locationUsersDao; + @Resource + private LocationUsersDao locationUsersDao; - @Override - public List<LocationUsers> list(LocationUsersQuery locationUsersQuery, int page, int pageSize) { - DaoQuery daoQuery = new DaoQuery(); - try { - BeanUtil.copyProperties(locationUsersQuery, daoQuery); - } catch (IllegalAccessException e) { - e.printStackTrace(); + @Override + public List<LocationUsers> list(LocationUsersQuery locationUsersQuery, int page, int pageSize) { + DaoQuery daoQuery = new DaoQuery(); + try { + BeanUtil.copyProperties(locationUsersQuery, daoQuery); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + daoQuery.start = (page - 1) * pageSize; + daoQuery.count = pageSize; + daoQuery.sortList = Arrays.asList(new Sort.Order[]{Sort.Order.desc("createTime")}); + return locationUsersDao.list(daoQuery); } - daoQuery.start=(page-1)*pageSize; - daoQuery.count=pageSize; - daoQuery.sortList= Arrays.asList(new Sort.Order[]{Sort.Order.desc("createTime")}); - return locationUsersDao.list(daoQuery); - } - @Override - public long count(LocationUsersQuery locationUsersQuery) { - DaoQuery daoQuery = new DaoQuery(); - try { - BeanUtil.copyProperties(locationUsersQuery, daoQuery); - } catch (IllegalAccessException e) { - e.printStackTrace(); + @Override + public long count(LocationUsersQuery locationUsersQuery) { + DaoQuery daoQuery = new DaoQuery(); + try { + BeanUtil.copyProperties(locationUsersQuery, daoQuery); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return locationUsersDao.count(daoQuery); } - return locationUsersDao.count(daoQuery); - } - @Override - public LocationUsers get(String id) { - Query query=new Query(); - query.addCriteria(Criteria.where("_id").is(id)); - return locationUsersDao.findOne(query); - } + @Override + public LocationUsers get(String id) { + Query query = new Query(); + query.addCriteria(Criteria.where("_id").is(id)); + return locationUsersDao.findOne(query); + } - @Override - public void add(LocationUsers locationUsers) throws Exception { - //鏌ヨ涓婚敭ID鏄惁瀛樺湪 - if(locationUsersDao.get(locationUsers.getId())!=null){ - throw new Exception("宸插瓨鍦�"); - } + @Override + public void add(LocationUsers locationUsers) throws Exception { - if(locationUsers.getCreateTime()==null){ - locationUsers.setCreateTime(new Date()); - } - //淇濆瓨 - locationUsersDao.save(locationUsers); - } + if (locationUsers.getId() == null) { + locationUsers.setId(LocationUsers.createId(locationUsers.getUid(), locationUsers.getTargetUid())); + } - @Override - public void update(LocationUsers locationUsers) { - if(locationUsers.getUpdateTime()==null){ - locationUsers.setUpdateTime(new Date()); - } - //鏇存柊 - locationUsersDao.updateSelective(locationUsers); - } + //鏌ヨ涓婚敭ID鏄惁瀛樺湪 + if (locationUsersDao.get(locationUsers.getId()) != null) { + throw new Exception("宸插瓨鍦�"); + } - @Override - public void delete(List<String> idList) { - for (String id : idList){ - locationUsersDao.delete(id); - } - } + if (locationUsers.getStatus() == null) { + locationUsers.setStatus(LocationUsers.LocationInviteStatus.sentInvite); + } + + if (locationUsers.getSentCount() == null) { + locationUsers.setSentCount(0); + } + if (locationUsers.getCreateTime() == null) { + locationUsers.setCreateTime(new Date()); + } + //淇濆瓨 + locationUsersDao.save(locationUsers); + } + + @Override + public void update(LocationUsers locationUsers) { + if (locationUsers.getUpdateTime() == null) { + locationUsers.setUpdateTime(new Date()); + } + //鏇存柊 + locationUsersDao.updateSelective(locationUsers); + } + + @Override + public void delete(List<String> idList) { + for (String id : idList) { + locationUsersDao.delete(id); + } + } + + @Override + public List<LocationUsers> listMyLocationUser(Long uid, LocationUsers.LocationInviteStatus status, int page, int pageSize) { + DaoQuery daoQuery = new DaoQuery(); + daoQuery.start = (page - 1) * pageSize; + daoQuery.count = pageSize; + daoQuery.status = status; + daoQuery.uid = uid; + return locationUsersDao.list(daoQuery); + } + + @Override + public long countMyLocationUser(Long uid, LocationUsers.LocationInviteStatus status) { + DaoQuery daoQuery = new DaoQuery(); + daoQuery.uid = uid; + daoQuery.status = status; + return locationUsersDao.count(daoQuery); + } + + @Override + public LocationUsers selectByUidAndTargetUid(Long uid, Long targetUid) { + DaoQuery daoQuery = new DaoQuery(); + daoQuery.uid = uid; + daoQuery.targetUid = targetUid; + daoQuery.count = 1; + List<LocationUsers> list = locationUsersDao.list(daoQuery); + return list != null && list.size() > 0 ? list.get(0) : null; + } } \ No newline at end of file -- Gitblit v1.8.0