package com.yeshi.fanli.service.impl.brand;
|
|
import java.util.Date;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import com.yeshi.fanli.dao.mybatis.brand.BrandInfoRecordMapper;
|
import com.yeshi.fanli.entity.brand.BrandInfo;
|
import com.yeshi.fanli.entity.brand.BrandInfoRecord;
|
import com.yeshi.fanli.service.inter.brand.BrandInfoRecordService;
|
import com.yeshi.fanli.util.StringUtil;
|
|
@Service
|
public class BrandInfoRecordServiceImpl implements BrandInfoRecordService {
|
|
@Resource
|
private BrandInfoRecordMapper brandInfoRecordMapper;
|
|
|
@Override
|
@Transactional
|
public void deleteRecord(List<String> list, Long uid, String device) {
|
if (list == null || list.size() == 0)
|
return;
|
|
if ((uid == null || uid == 0) && StringUtil.isNullOrEmpty(device))
|
return;
|
|
// 优先用户为主
|
if (uid != null && uid > 0)
|
device = null;
|
|
for (String brandId: list) {
|
brandInfoRecordMapper.updateState(Long.parseLong(brandId), uid, device);
|
}
|
}
|
|
@Async()
|
@Override
|
public void addRecord(Long brandId, Long uid, String device) {
|
if (brandId == null || brandId == 0)
|
return;
|
|
if ((uid == null || uid == 0) && StringUtil.isNullOrEmpty(device))
|
return;
|
|
// 优先用户为主
|
if (uid != null && uid > 0)
|
device = null;
|
|
BrandInfoRecord record = brandInfoRecordMapper.getRecord(brandId, uid, device);
|
if (record != null) {
|
BrandInfoRecord update = new BrandInfoRecord();
|
update.setState(0);
|
update.setId(record.getId());
|
update.setUpdateTime(new Date());
|
brandInfoRecordMapper.updateByPrimaryKeySelective(update);
|
} else {
|
record = new BrandInfoRecord();
|
record.setUid(uid);
|
record.setDevice(device);
|
record.setBrandInfo(new BrandInfo(brandId));
|
record.setCreateTime(new Date());
|
record.setUpdateTime(new Date());
|
brandInfoRecordMapper.insertSelective(record);
|
}
|
}
|
|
@Override
|
public List<BrandInfoRecord> listRecord(long start, int count, Long uid, String device) {
|
if ((uid == null || uid == 0) && StringUtil.isNullOrEmpty(device))
|
return null;
|
|
// 优先用户为主
|
if (uid != null && uid > 0)
|
device = null;
|
|
return brandInfoRecordMapper.listRecord(start, count, uid, device);
|
}
|
|
@Override
|
public long countRecord(Long uid, String device) {
|
if ((uid == null || uid == 0) && StringUtil.isNullOrEmpty(device))
|
return 0;
|
|
// 优先用户为主
|
if (uid != null && uid > 0)
|
device = null;
|
return brandInfoRecordMapper.countRecord(uid, device);
|
}
|
|
}
|