|
@@ -0,0 +1,78 @@
|
|
|
+package com.bosshand.virgo.core.service;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.bosshand.virgo.core.dao.CustomerDao;
|
|
|
+import com.bosshand.virgo.core.model.Customer;
|
|
|
+import com.bosshand.virgo.core.utils.CodeCache;
|
|
|
+import com.bosshand.virgo.core.utils.StringUtil;
|
|
|
+import com.bosshand.virgo.core.utils.WeChatUtil;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Random;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class CustomerService {
|
|
|
+
|
|
|
+ static Logger log = LoggerFactory.getLogger(CustomerService.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CustomerDao customerDao;
|
|
|
+
|
|
|
+ public int getTotalCount(Customer customer) {
|
|
|
+ return customerDao.getTotalCount(customer);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Customer> getLimit(Customer customer, int currPage, int pageSize) {
|
|
|
+ int currIndex = (currPage - 1) * pageSize;
|
|
|
+ return customerDao.getLimit(customer, currIndex, pageSize);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void insert(Customer customer) {
|
|
|
+ if (StringUtil.blank(customer.getAvatarUrl())) {
|
|
|
+ customer.setAvatarUrl(CodeCache.DefaultPortrait);
|
|
|
+ }
|
|
|
+ customer.setCustomerId(getNo());
|
|
|
+ customerDao.insert(customer);
|
|
|
+ String url = "http://git.waywish.com:9120/user/register";
|
|
|
+ JSONObject js = new JSONObject();
|
|
|
+ js.put("userId", customer.getCustomerId());
|
|
|
+ js.put("nickname", customer.getNickName());
|
|
|
+ js.put("avatarUrl", customer.getAvatarUrl());
|
|
|
+ String str = WeChatUtil.httpPost(url, js, null);
|
|
|
+ log.info("addCustomerChatUser=" + str);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 指定用户为客服
|
|
|
+ */
|
|
|
+ public int update(Customer customer) {
|
|
|
+ return customerDao.update(customer);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Customer> getList(Customer customer) {
|
|
|
+ return customerDao.getList(customer);
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getNo() {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
+ String newDate = sdf.format(new Date());
|
|
|
+ String result = "";
|
|
|
+ Random random = new Random();
|
|
|
+ for (int i = 0; i < 3; i++) {
|
|
|
+ result += random.nextInt(10);
|
|
|
+ }
|
|
|
+ return newDate + result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Customer get(long id) {
|
|
|
+ return customerDao.get(id);
|
|
|
+ }
|
|
|
+}
|