package com.yeshi.makemoney.app.service.impl.goldcorn;
|
|
import java.lang.Exception;
|
import javax.annotation.Resource;
|
|
import org.springframework.stereotype.Service;
|
|
import java.util.Date;
|
|
import org.yeshi.utils.StringUtil;
|
import org.yeshi.utils.TimeUtil;
|
import org.yeshi.utils.bean.BeanUtil;
|
|
import java.util.List;
|
|
import com.yeshi.makemoney.app.dao.goldcorn.GoldCornGetPriceDao;
|
import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetPrice;
|
import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornGetPriceService;
|
import com.yeshi.makemoney.app.service.query.goldcorn.GoldCornGetPriceQuery;
|
import com.yeshi.makemoney.app.dao.goldcorn.GoldCornGetPriceDao.DaoQuery;
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
import org.springframework.data.mongodb.core.query.Query;
|
|
@Service
|
public class GoldCornGetPriceServiceImpl implements GoldCornGetPriceService {
|
|
@Resource
|
private GoldCornGetPriceDao goldCornGetPriceDao;
|
|
@Override
|
public List<GoldCornGetPrice> list(GoldCornGetPriceQuery goldCornGetPriceQuery, int page, int pageSize) {
|
DaoQuery daoQuery = new DaoQuery();
|
daoQuery.type = goldCornGetPriceQuery.getType();
|
if (!StringUtil.isNullOrEmpty(goldCornGetPriceQuery.getStartTime())) {
|
daoQuery.minValidateTime = new Date(TimeUtil.convertToTimeTemp(goldCornGetPriceQuery.getStartTime(), "yyyy-MM-dd"));
|
}
|
if (!StringUtil.isNullOrEmpty(goldCornGetPriceQuery.getEndTime())) {
|
daoQuery.maxValidateTime = new Date(TimeUtil.convertToTimeTemp(goldCornGetPriceQuery.getEndTime(), "yyyy-MM-dd") + 1000 * 60 * 60 * 24L);
|
}
|
|
|
daoQuery.start = (page - 1) * pageSize;
|
daoQuery.count = pageSize;
|
return goldCornGetPriceDao.list(daoQuery);
|
}
|
|
@Override
|
public long count(GoldCornGetPriceQuery goldCornGetPriceQuery) {
|
DaoQuery daoQuery = new DaoQuery();
|
daoQuery.type = goldCornGetPriceQuery.getType();
|
if (!StringUtil.isNullOrEmpty(goldCornGetPriceQuery.getStartTime())) {
|
daoQuery.minValidateTime = new Date(TimeUtil.convertToTimeTemp(goldCornGetPriceQuery.getStartTime(), "yyyy-MM-dd"));
|
}
|
if (!StringUtil.isNullOrEmpty(goldCornGetPriceQuery.getEndTime())) {
|
daoQuery.maxValidateTime = new Date(TimeUtil.convertToTimeTemp(goldCornGetPriceQuery.getEndTime(), "yyyy-MM-dd") + 1000 * 60 * 60 * 24L);
|
}
|
return goldCornGetPriceDao.count(daoQuery);
|
}
|
|
@Override
|
public GoldCornGetPrice get(String id) {
|
Query query = new Query();
|
query.addCriteria(Criteria.where("_id").is(id));
|
return goldCornGetPriceDao.findOne(query);
|
}
|
|
@Override
|
public void add(GoldCornGetPrice goldCornGetPrice) throws Exception {
|
|
|
if (goldCornGetPrice.getCreateTime() == null) {
|
goldCornGetPrice.setCreateTime(new Date());
|
}
|
|
if (goldCornGetPrice.getId() == null) {
|
goldCornGetPrice.setId(goldCornGetPrice.toId());
|
}
|
//查询主键ID是否存在
|
if (goldCornGetPriceDao.get(goldCornGetPrice.getId()) != null) {
|
throw new Exception("已存在");
|
}
|
|
//保存
|
goldCornGetPriceDao.save(goldCornGetPrice);
|
}
|
|
@Override
|
public void update(GoldCornGetPrice goldCornGetPrice) {
|
if (goldCornGetPrice.getUpdateTime() == null) {
|
goldCornGetPrice.setUpdateTime(new Date());
|
}
|
//更新
|
goldCornGetPriceDao.updateSelective(goldCornGetPrice);
|
}
|
|
@Override
|
public void delete(List<String> idList) {
|
for (String id : idList) {
|
goldCornGetPriceDao.delete(id);
|
}
|
}
|
|
|
}
|