package com.yeshi.fanli.service.impl.customerservice;
|
|
import java.util.Collections;
|
import java.util.Comparator;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.stereotype.Service;
|
|
import com.yeshi.fanli.dao.mybatis.customerservice.CustomerServiceCommonQuestionMapper;
|
import com.yeshi.fanli.entity.customerservice.CustomerServiceCommonQuestion;
|
import com.yeshi.fanli.exception.CustomerServiceCommonQuestionException;
|
import com.yeshi.fanli.service.inter.customerservice.CustomerServiceCommonQuestionService;
|
import org.yeshi.utils.StringUtil;
|
|
@Service
|
public class CustomerServiceCommonQuestionServiceImpl implements CustomerServiceCommonQuestionService {
|
|
@Resource
|
private CustomerServiceCommonQuestionMapper customerServiceCommonQuestionMapper;
|
|
@Override
|
public CustomerServiceCommonQuestion searchByKey(String key) {
|
List<CustomerServiceCommonQuestion> list = customerServiceCommonQuestionMapper.selectByKey(key);
|
if (list == null || list.size() == 0)
|
return null;
|
Comparator<CustomerServiceCommonQuestion> cm = new Comparator<CustomerServiceCommonQuestion>() {
|
|
@Override
|
public int compare(CustomerServiceCommonQuestion o1, CustomerServiceCommonQuestion o2) {
|
return o1.getKey().replace(key, "").length() - o2.getKey().replace(key, "").length();
|
}
|
};
|
Collections.sort(list, cm);
|
return list.get(0);
|
}
|
|
@Override
|
public CustomerServiceCommonQuestion searchByKeyCache(String key) {
|
return searchByKey(key);
|
}
|
|
@Override
|
public void addCustomerServiceCommonQuestion(CustomerServiceCommonQuestion question)
|
throws CustomerServiceCommonQuestionException {
|
if (question == null || StringUtil.isNullOrEmpty(question.getKey())
|
|| StringUtil.isNullOrEmpty(question.getContent())
|
|| StringUtil.isNullOrEmpty(question.getContentType()))
|
throw new CustomerServiceCommonQuestionException(1, "问题信息不完整");
|
|
CustomerServiceCommonQuestion oldQuestion = searchByKey(question.getKey());
|
if (oldQuestion != null && oldQuestion.getKey().equalsIgnoreCase(question.getKey()))
|
throw new CustomerServiceCommonQuestionException(2, "已有该问题");
|
customerServiceCommonQuestionMapper.insertSelective(question);
|
}
|
|
@Override
|
public void updateCustomerServiceCommonQuestion(CustomerServiceCommonQuestion question)
|
throws CustomerServiceCommonQuestionException {
|
if (question == null || question.getId() == null)
|
return;
|
customerServiceCommonQuestionMapper.updateByPrimaryKeySelective(question);
|
}
|
|
@Override
|
public void deleteCustomerServiceCommonQuestion(Long id) {
|
customerServiceCommonQuestionMapper.deleteByPrimaryKey(id);
|
}
|
|
@Override
|
public List<String> listKeysCache() {
|
return customerServiceCommonQuestionMapper.selectKeys();
|
}
|
|
@Override
|
public List<CustomerServiceCommonQuestion> listCustomerServiceCommonQuestion(int page, int pageSize) {
|
return customerServiceCommonQuestionMapper.selectOrderByUpdateTime((page - 1) * pageSize, pageSize);
|
}
|
|
@Override
|
public Long countCustomerServiceCommonQuestion() {
|
return customerServiceCommonQuestionMapper.selectCount();
|
}
|
|
}
|