BusinessServiceImpl.java 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. package com.goafanti.customer.service.impl;
  2. import java.text.ParseException;
  3. import java.text.SimpleDateFormat;
  4. import java.util.Date;
  5. import java.util.HashMap;
  6. import java.util.List;
  7. import java.util.Map;
  8. import java.util.UUID;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import org.springframework.transaction.annotation.Transactional;
  12. import com.goafanti.common.constant.AFTConstants;
  13. import com.goafanti.common.dao.UserBusinessMapper;
  14. import com.goafanti.common.dao.UserFollowBusinessMapper;
  15. import com.goafanti.common.dao.UserFollowMapper;
  16. import com.goafanti.common.model.UserBusiness;
  17. import com.goafanti.common.model.UserFollow;
  18. import com.goafanti.common.model.UserFollowBusiness;
  19. import com.goafanti.common.utils.StringUtils;
  20. import com.goafanti.core.mybatis.BaseMybatisDao;
  21. import com.goafanti.core.mybatis.page.Pagination;
  22. import com.goafanti.core.shiro.token.TokenManager;
  23. import com.goafanti.customer.bo.BusinessListBo;
  24. import com.goafanti.customer.bo.BussinessFollowBo;
  25. import com.goafanti.customer.service.BusinessService;
  26. @Service
  27. public class BusinessServiceImpl extends BaseMybatisDao<UserBusinessMapper> implements BusinessService {
  28. @Autowired
  29. private UserBusinessMapper userBusinessMapper;
  30. @Autowired
  31. private UserFollowMapper userFollowMapper;
  32. @Autowired
  33. private UserFollowBusinessMapper userFollowBusinessMapper;
  34. @SuppressWarnings("unchecked")
  35. @Override
  36. public Pagination<BusinessListBo> listBusiness(BusinessListBo blo,Integer pageNo,Integer pageSize) {
  37. blo.setAid(TokenManager.getAdminId());
  38. return (Pagination<BusinessListBo>) findPage("selectBusinessList", "selectBusinessCount", disposeParams(blo), pageNo, pageSize);
  39. }
  40. private Map<String,Object> disposeParams(BusinessListBo blo){
  41. Map<String, Object> params = new HashMap<String, Object>();
  42. if(StringUtils.isNotBlank(blo.getAid())) params.put("aid", blo.getAid());
  43. if(StringUtils.isNotBlank(blo.getAdminName())) params.put("adminName", blo.getAdminName());
  44. if(StringUtils.isNotBlank(blo.getBusinessId())) params.put("businessId", blo.getBusinessId());
  45. if(StringUtils.isNotBlank(blo.getStartDate())) params.put("startDate", blo.getStartDate()+" 00:00:00");
  46. if(StringUtils.isNotBlank(blo.getEndDate())) params.put("endDate", blo.getEndDate()+ " 23:59:59");
  47. if(StringUtils.isNotBlank(blo.getIdentifyName())) params.put("identity", blo.getIdentifyName());
  48. if(StringUtils.isNoneBlank(blo.getFollowSituation())) params.put("followSituation", blo.getFollowSituation());
  49. if(StringUtils.isNotBlank(blo.getCustomerStatus())) params.put("customerStatus", blo.getCustomerStatus());
  50. return params;
  51. }
  52. @Override
  53. public List<BusinessListBo> findBusinessGlossory() {
  54. return userBusinessMapper.findBusinessGlossory();
  55. }
  56. @Override
  57. public int judgeBusiness(String uid, Integer businessGlossoryId) {
  58. return userBusinessMapper.judgeBusiness(uid,businessGlossoryId,"");
  59. }
  60. @Override
  61. @Transactional
  62. public void addBusinessAndFollow(BussinessFollowBo bfb) throws ParseException {
  63. UserBusiness ub = new UserBusiness();
  64. String ubId = UUID.randomUUID().toString();
  65. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  66. ub.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  67. ub.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  68. ub.setId(ubId);
  69. ub.setUid(bfb.getUid());
  70. ub.setAid(TokenManager.getAdminId());
  71. ub.setRemarks(bfb.getRemarks());
  72. ub.setBusinessGlossoryId(Integer.parseInt(bfb.getBusinessGlossoryId()));
  73. ub.setUpdateTime(format.parse(bfb.getCreateTime()));
  74. ub.setCreateTime(format.parse(bfb.getCreateTime()));
  75. userBusinessMapper.insert(ub);
  76. if (StringUtils.isNotBlank(bfb.getOcbId())) { // 跟进联系人不为空则添加跟进记录
  77. UserFollow uf = new UserFollow();
  78. String ufId = UUID.randomUUID().toString();
  79. uf.setId(ufId);
  80. uf.setUid(bfb.getUid());
  81. uf.setCreateTime(format.parse(bfb.getFollowTime()));
  82. uf.setOcbId(bfb.getOcbId());
  83. uf.setResult(bfb.getResult());
  84. uf.setContactType(Integer.parseInt(bfb.getContactType()));
  85. uf.setAid(TokenManager.getAdminId());
  86. uf.setEffective(0);
  87. int followCount = userBusinessMapper.judgeBusiness(bfb.getUid(), null, TokenManager.getAdminId()) + 1;
  88. uf.setFollowCount(followCount);
  89. userFollowMapper.insert(uf);
  90. UserFollowBusiness ufb = new UserFollowBusiness();
  91. ufb.setId(UUID.randomUUID().toString());
  92. ufb.setBusinessId(ubId);
  93. ufb.setFollowId(ufId);
  94. ufb.setCustomerStatus(ub.getCustomerStatus());
  95. ufb.setFollowSituation(ub.getFollowSituation());
  96. userFollowBusinessMapper.insert(ufb);
  97. }
  98. }
  99. @Override
  100. public List<UserBusiness> findBusinessByUAid(String uid, String aid) {
  101. return userBusinessMapper.findBusinessByUAid(uid,aid);
  102. }
  103. @Override
  104. public BussinessFollowBo findBusinessDetail(String businessId) {
  105. return userBusinessMapper.findBusinessDetail(businessId);
  106. }
  107. @Override
  108. public int updateBusiness(BussinessFollowBo bfb) {
  109. UserBusiness userBusiness = new UserBusiness();
  110. userBusiness.setId(bfb.getBusinessId());
  111. userBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  112. userBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  113. userBusiness.setRemarks(bfb.getRemarks());
  114. userBusiness.setUpdateTime(new Date());
  115. userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
  116. return 1;
  117. }
  118. @Override
  119. @Transactional
  120. public int followOneBusiness(BussinessFollowBo bfb) throws ParseException {
  121. Date updateTime = new Date();
  122. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  123. UserBusiness userBusiness = new UserBusiness();
  124. userBusiness.setId(bfb.getBusinessId());
  125. userBusiness.setUpdateTime(updateTime);
  126. userBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  127. userBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  128. userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
  129. UserFollow userFollow = new UserFollow();
  130. String followId = UUID.randomUUID().toString();
  131. int followCount = userBusinessMapper.judgeBusiness(bfb.getUid(), null, TokenManager.getAdminId()) + 1;
  132. userFollow.setId(followId);
  133. userFollow.setResult(bfb.getResult());
  134. userFollow.setCreateTime(format.parse(bfb.getFollowTime()));
  135. userFollow.setEffective(0);
  136. userFollow.setOcbId(bfb.getOcbId());
  137. userFollow.setFollowCount(followCount);
  138. userFollow.setContactType(Integer.parseInt(bfb.getContactType()));
  139. userFollow.setAid(TokenManager.getAdminId());
  140. userFollowMapper.insert(userFollow);
  141. UserFollowBusiness userFollowBusiness = new UserFollowBusiness();
  142. String ufbId = UUID.randomUUID().toString();
  143. userFollowBusiness.setId(ufbId);
  144. userFollowBusiness.setFollowId(followId);
  145. userFollowBusiness.setBusinessGlossoryId(Integer.parseInt(bfb.getBusinessGlossoryId()));
  146. userFollowBusiness.setBusinessId(bfb.getBusinessId());
  147. userFollowBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
  148. userFollowBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
  149. userFollowBusiness.setRemarks(bfb.getRemarks());
  150. userFollowBusinessMapper.insert(userFollowBusiness);
  151. return 1;
  152. }
  153. }