| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- package com.goafanti.customer.service.impl;
- import java.lang.reflect.InvocationTargetException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.UUID;
- import org.apache.commons.beanutils.BeanUtils;
- import org.apache.shiro.SecurityUtils;
- import org.apache.shiro.subject.Subject;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import com.goafanti.core.mybatis.BaseMybatisDao;
- import com.goafanti.core.mybatis.page.Pagination;
- import com.goafanti.core.shiro.token.TokenManager;
- import com.goafanti.customer.bo.CustomerIn;
- import com.goafanti.customer.bo.CustomerOut;
- import com.goafanti.customer.service.CustomerService;
- import com.goafanti.common.constant.AFTConstants;
- import com.goafanti.common.dao.AdminMapper;
- import com.goafanti.common.dao.CustomerLogMapper;
- import com.goafanti.common.dao.CustomerMapper;
- import com.goafanti.common.dao.CustomerOrganizationInfoMapper;
- import com.goafanti.common.dao.CustomerUserInfoMapper;
- import com.goafanti.common.dao.FollowUpRecordMapper;
- import com.goafanti.common.enums.CustomerFollowFiled;
- import com.goafanti.common.enums.CustomerIntentionFiled;
- import com.goafanti.common.enums.CustomerStatusFiled;
- import com.goafanti.common.model.Admin;
- import com.goafanti.common.model.Customer;
- import com.goafanti.common.model.CustomerLog;
- import com.goafanti.common.model.CustomerOrganizationInfo;
- import com.goafanti.common.model.CustomerUserInfo;
- import com.goafanti.common.model.FollowUpRecord;
- import com.goafanti.common.utils.StringUtils;
- @Service
- public class CustomerServiceImpl extends BaseMybatisDao<CustomerMapper> implements CustomerService {
- @Autowired
- private CustomerMapper customerMapper ;
- @Autowired
- private AdminMapper adminMapper;
- @Autowired
- private CustomerLogMapper customerLogMapper;
- @Autowired
- private CustomerUserInfoMapper customerUserInfoMapper;
- @Autowired
- private CustomerOrganizationInfoMapper customerOrganizationInfoMapper;
- @Autowired
- private FollowUpRecordMapper followUpRecordMapper;
- @Override
- public int addCustomer(Customer cus,CustomerUserInfo cui,CustomerOrganizationInfo coi,FollowUpRecord fur) {
- //插入 customerUserInfo
- customerUserInfoMapper.insert(cui);
- //插入 customerOrganizationInfo
- customerOrganizationInfoMapper.insert(coi);
- //插入跟进表
- followUpRecordMapper.insert(fur);
- String paid = findLadderIds(TokenManager.getAdminId());//查询上级管理员ID集合
- if(StringUtils.isNotBlank(paid)) paid = paid.substring(0, paid.length()-1);
- cus.setPaid(paid);
- int res = customerMapper.insert(cus);
- return res;
- }
- @Override
- public void deleteCustomer(String id) {
- customerMapper.deleteByPrimaryKey(id);
- }
- @Override
- public String findLadderIds(String adminId) {
- String result = "";
- Admin admin = adminMapper.selectByPrimaryKey(adminId);
- if(admin != null && StringUtils.isNotBlank(admin.getSuperiorId())){
- result += admin.getSuperiorId() + ",";
- result += findLadderIds(admin.getSuperiorId());
- }
- return result;
- }
- @Override
- public void updateLadderIds(String ladderId) {
- List<Customer> customers = customerMapper.selectByLadderId(ladderId);
- if(customers.size()>0){
- String newPaid = "";
- for(Customer c:customers){
- newPaid = findLadderIds(c.getAid());
- if(StringUtils.isNotBlank(newPaid)) newPaid = newPaid.substring(0, newPaid.length()-1);
- c.setPaid(newPaid);
- customerMapper.updateByPrimaryKeySelective(c);
- }
- }
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<CustomerOut> getPrivateCustomer(CustomerIn cin, Integer pageSize, Integer pageNumber) {
- cin.setShareType("0");
- cin.setAid(TokenManager.getAdminId());
- Map<String,Object> params = disposeParams(cin);
- if(pageSize == null || pageSize < 0) pageSize = 10;
- if(pageNumber == null || pageNumber <0 ) pageNumber = 1;
- Pagination<CustomerOut> list = (Pagination<CustomerOut>)findPage("selectCustomer","selectCustomerCount",params, pageNumber, pageSize);
- list.setList(setResult((List<CustomerOut>)list.getList()));
- return list;
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<CustomerOut> getPublicCustomer(CustomerIn cin, Integer pageSize, Integer pageNumber) {
- cin.setShareType("1");
- Map<String,Object> params = disposeParams(cin);
- Pagination<CustomerOut> list = (Pagination<CustomerOut>)findPage("selectCustomer","selectCustomerCount",params, pageNumber, pageSize);
- list.setList(setResult((List<CustomerOut>)list.getList()));
- list.setList(descResult((List<CustomerOut>)list.getList()));
- return list;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<CustomerOut> getTeamCustomer(CustomerIn cin, Integer pageSize, Integer pageNumber) {
- cin.setShareType("0");
- cin.setPaid(TokenManager.getAdminId());
- cin.setAid(TokenManager.getAdminId());
- Map<String,Object> params = disposeParams(cin);
- if(pageSize == null || pageSize < 0) pageSize = 10;
- if(pageNumber == null || pageNumber <0 ) pageNumber = 1;
- Pagination<CustomerOut> list = (Pagination<CustomerOut>)findPage("selectCustomer","selectCustomerCount",params, pageNumber, pageSize);
- list.setList(setResult((List<CustomerOut>)list.getList()));
- list.setList(descResult((List<CustomerOut>)list.getList()));
- return list;
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<CustomerOut> getCompanyCustomer(CustomerIn cin, Integer pageSize, Integer pageNumber) {
- Map<String,Object> params = disposeParams(cin);
- if(pageSize == null || pageSize < 0) pageSize = 10;
- if(pageNumber == null || pageNumber <0 ) pageNumber = 1;
- Pagination<CustomerOut> list = (Pagination<CustomerOut>)findPage("selectCustomer","selectCustomerCount",params, pageNumber, pageSize);
- Subject subject = SecurityUtils.getSubject();
- list.setList(setResult((List<CustomerOut>)list.getList()));
- if(!subject.isPermitted("customer_view_all")&&!subject.hasRole(AFTConstants.SUPERADMIN)) {
- list.setList(descResult((List<CustomerOut>)list.getList()));
- }
- return list;
- }
-
- private Map<String,Object> disposeParams(CustomerIn cin){
- Map<String,Object> params = new HashMap<String,Object>();
- if(StringUtils.isNotBlank(cin.getAdminName())) params.put("adminName", cin.getAdminName());
- if(StringUtils.isNotBlank(cin.getAid())) params.put("aid", cin.getAid());
- if(StringUtils.isNotBlank(cin.getPaid())) params.put("paid", cin.getPaid());
- if(StringUtils.isNotBlank(cin.getCompanyIntention())) params.put("companyIntention", Integer.parseInt(cin.getCompanyIntention()));
- if(StringUtils.isNotBlank(cin.getContactName())) params.put("contactName", cin.getContactName());
- if(StringUtils.isNotBlank(cin.getCustomerStatus())) params.put("customerStauts", Integer.parseInt(cin.getCustomerStatus()));
- if(StringUtils.isNotBlank(cin.getFollowSituation())) params.put("followSituation", Integer.parseInt(cin.getFollowSituation()));
- if(StringUtils.isNotBlank(cin.getShareType())) params.put("shareType", Integer.parseInt(cin.getShareType()));
- if(StringUtils.isNotBlank(cin.getCustomerType())) params.put("customerType", Integer.parseInt(cin.getCustomerType()));
- if(StringUtils.isNotBlank(cin.getContactTel())) params.put("contactTel", cin.getContactTel());
- if(StringUtils.isNotBlank(cin.getLocationProvince())) params.put("locationProvince", cin.getLocationProvince());
- if(StringUtils.isNotBlank(cin.getCompanyName())) params.put("companyName", cin.getCompanyName());
- return params;
- }
- private List<CustomerOut> setResult(List<CustomerOut> list){
- for(CustomerOut co :list){
- setFiled(co);
- }
- return list;
- }
-
- private CustomerOut setFiled(CustomerOut co) {
- switch(co.getCustomerType()){
- case 0 : co.set_customerType("个人客户") ;break;
- case 1 : co.set_customerType("机构单位") ;break;
- case 2 : co.set_customerType("团体单位") ;break;
- }
- switch(co.getCustomerStatus()){
- case 0 : co.set_customerStatus("新客户") ;break;
- case 1 : co.set_customerStatus("意向客户") ;break;
- case 2 : co.set_customerStatus("重点客户") ;break;
- case 3 : co.set_customerStatus("面谈客户") ;break;
- case 4 : co.set_customerStatus("签单客户") ;break;
- case 5 : co.set_customerStatus("被拒绝客户") ;break;
- }
- switch(co.getFollowSituation()){
- case 0 : co.set_followSituation("已发项目介绍资料") ;break;
- case 1 : co.set_followSituation("已约面谈") ;break;
- case 2 : co.set_followSituation("已发合同计划书") ;break;
- case 3 : co.set_followSituation("已报价") ;break;
- case 4 : co.set_followSituation("已发合同") ;break;
- case 5 : co.set_followSituation("已签合同") ;break;
- case 6 : co.set_followSituation("面谈中") ;break;
- case 7 : co.set_followSituation("已面签") ;break;
- case 8 : co.set_followSituation("无进度") ;break;
- }
- String _companyIntention = "";
- if(StringUtils.isNotBlank(co.getCompanyIntention())){
- String[] temp ;
- if(co.getCompanyIntention().contains(",")){
- temp = co.getCompanyIntention().split(",");
- }else{
- temp = new String[]{co.getCompanyIntention()};
- }
- for(String s:temp){
- if(s.equals("0")) _companyIntention += "发明专利-";
- if(s.equals("1")) _companyIntention += "实用型新型专利-";
- if(s.equals("2")) _companyIntention += "外观专利-";
- if(s.equals("3")) _companyIntention += "软件著作权-";
- if(s.equals("4")) _companyIntention += "知识产权贯标-";
- if(s.equals("5")) _companyIntention += "高企认定-";
- if(s.equals("6")) _companyIntention += "技术成果-";
- if(s.equals("7")) _companyIntention += "技术需求-";
- if(s.equals("8")) _companyIntention += "专家咨询-";
- if(s.equals("9")) _companyIntention += "团单合作-";
- if(s.equals("10")) _companyIntention += "商标-";
- if(s.equals("11")) _companyIntention += "系统集成-";
- }
- _companyIntention = _companyIntention.substring(0, _companyIntention.length()-1);
- }
- co.set_companyIntention(_companyIntention);
- if(StringUtils.isNotBlank(co.getFollowDate())) co.setFollowDate(co.getFollowDate().substring(0,19));
- return co;
- }
- /**
- * 获取客户意向
- * @param intentions
- * @return
- */
- private String getCompanyIntention(String intentions){
- String result = "";
- if(StringUtils.isNotBlank(intentions)){
- String[] list;
- if(intentions.contains(",")){
- list = intentions.split(",");
- }else{
- list = new String[]{intentions};
- }
- for(String s:list){
- result += CustomerIntentionFiled.getField(Integer.parseInt(s)).getDesc()+",";
- }
- result = result.substring(0, result.length()-1);
- }
- return result;
- }
-
- @Override
- public void saveCustomerLog(CustomerIn cus,String operatorType){
- /* 记录日志 */
- String cid = cus.getId();
- CustomerLog log = new CustomerLog();
- log.setId(UUID.randomUUID().toString());
- log.setCid(cid);
- log.setOperatorTime(new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS).format(new Date()));
- log.setOperatorName(TokenManager.getAdminToken().getName());
- Customer c = customerMapper.selectByPrimaryKey(cid) ;
-
- if(operatorType.equals(AFTConstants.CUSTOMER_CREATE)){//创建用户
- log.setAfterFollowSituation(CustomerFollowFiled.getField(Integer.parseInt(cus.getFollowSituation())).getDesc()); //跟进状态
- log.setAfterCustomerIntention(getCompanyIntention(cus.getCompanyIntention())); //跟进意向
- log.setAfterCustomerStatus(CustomerStatusFiled.getField(Integer.parseInt(cus.getCustomerStatus())).getDesc()); //客户状态
- log.setAfterAdminName(TokenManager.getAdminToken().getName());
- log.setOperatorType(AFTConstants.CUSTOMER_CREATE);
- }else if(operatorType.equals(AFTConstants.CUSTOMER_MODIFY)){ //修改客户
- String beforeAdminName = adminMapper.selectByPrimaryKey(c.getAid()).getName();
- log.setBeforeAdminName(beforeAdminName);//修改前操作人
- log.setBeforeCustomerIntention(getCompanyIntention(c.getCompanyIntention())); //修改前跟进意向
- log.setBeforeCustomerStatus(CustomerStatusFiled.getField(c.getCustomerStatus()).getDesc()); //修改前跟进状态
- log.setBeforeFollowSituation(CustomerFollowFiled.getField(c.getFollowSituation()).getDesc());//修改前跟进进度
- log.setAfterAdminName(TokenManager.getAdminToken().getName());
- log.setAfterFollowSituation(CustomerFollowFiled.getField(Integer.parseInt(cus.getFollowSituation())).getDesc()); //修改后跟进状态
- log.setAfterCustomerIntention(getCompanyIntention(cus.getCompanyIntention())); //修改后跟进意向
- log.setAfterCustomerStatus(CustomerStatusFiled.getField(Integer.parseInt(cus.getCustomerStatus())).getDesc()); //修改后客户状态
- log.setOperatorType(AFTConstants.CUSTOMER_MODIFY);
- }else if(operatorType.equals(AFTConstants.CUSTOMER_DELETE)){ //删除客户
- String beforeAdminName = adminMapper.selectByPrimaryKey(c.getAid()).getName();
- log.setBeforeAdminName(beforeAdminName); //删除前跟进人
- log.setBeforeCustomerIntention(getCompanyIntention(c.getCompanyIntention())); //删除前跟进意向
- log.setBeforeCustomerStatus(CustomerStatusFiled.getField(c.getCustomerStatus()).getDesc()); //删除前跟进状态
- log.setBeforeFollowSituation(CustomerFollowFiled.getField(c.getFollowSituation()).getDesc());//删除前跟进进度
- log.setOperatorType(AFTConstants.CUSTOMER_DELETE);
- }else if(operatorType.equals(AFTConstants.CUSTOMER_TRANSFER)){ //转交客户
- log.setBeforeAdminName(cus.getBeforeAdminName());//转交前的人
- log.setAfterAdminName(cus.getAdminName());//转交后的人
- log.setBeforeCustomerIntention(getCompanyIntention(c.getCompanyIntention())); //转交前跟进意向
- log.setBeforeCustomerStatus(CustomerStatusFiled.getField(c.getCustomerStatus()).getDesc()); //转交前跟进状态
- log.setBeforeFollowSituation(CustomerFollowFiled.getField(c.getFollowSituation()).getDesc());//转交前跟进进度
- log.setOperatorType(AFTConstants.CUSTOMER_TRANSFER);
- }else if(operatorType.equals(AFTConstants.CUSTOMER_RECEIVE)){ //领取客户
- String beforeAdminName = adminMapper.selectByPrimaryKey(c.getAid()).getName();
- log.setBeforeAdminName(beforeAdminName);//领取前的人
- log.setAfterAdminName(TokenManager.getAdminToken().getName());//领取后跟进人
- log.setBeforeCustomerIntention(getCompanyIntention(c.getCompanyIntention())); //领取前跟进意向
- log.setBeforeCustomerStatus(CustomerStatusFiled.getField(c.getCustomerStatus()).getDesc()); //领取前跟进状态
- log.setBeforeFollowSituation(CustomerFollowFiled.getField(c.getFollowSituation()).getDesc());//领取前跟进进度
- log.setOperatorType(AFTConstants.CUSTOMER_RECEIVE);
- }else if(operatorType.equals(AFTConstants.CUSTOMER_TO_PUBLIC)){ //转为公共客户
- log.setBeforeAdminName(cus.getBeforeAdminName());//转为公共客户前跟进人
- log.setBeforeCustomerIntention(getCompanyIntention(c.getCompanyIntention())); //转换前跟进意向
- log.setBeforeCustomerStatus(CustomerStatusFiled.getField(c.getCustomerStatus()).getDesc()); //转换前跟进状态
- log.setBeforeFollowSituation(CustomerFollowFiled.getField(c.getFollowSituation()).getDesc());//转换前跟进进度
- log.setOperatorType(AFTConstants.CUSTOMER_TO_PUBLIC);
- }else if(operatorType.equals(AFTConstants.CUSTOMER_FOLLOW)){ //跟进客户
- String beforeAdminName = adminMapper.selectByPrimaryKey(c.getAid()).getName();
- log.setBeforeAdminName(beforeAdminName);//跟进前操作人
- log.setBeforeCustomerIntention(getCompanyIntention(c.getCompanyIntention())); //修改前跟进意向
- log.setBeforeCustomerStatus(CustomerStatusFiled.getField(c.getCustomerStatus()).getDesc()); //修改前跟进状态
- log.setBeforeFollowSituation(CustomerFollowFiled.getField(c.getFollowSituation()).getDesc());//修改前跟进进度
- log.setAfterAdminName(TokenManager.getAdminToken().getName());
- log.setAfterFollowSituation(CustomerFollowFiled.getField(Integer.parseInt(cus.getFollowSituation())).getDesc()); //修改后跟进状态
- log.setAfterCustomerIntention(getCompanyIntention(cus.getCompanyIntention())); //修改后跟进意向
- log.setAfterCustomerStatus(CustomerStatusFiled.getField(Integer.parseInt(cus.getCustomerStatus())).getDesc()); //修改后客户状态
- log.setOperatorType(AFTConstants.CUSTOMER_FOLLOW);
- }
- customerLogMapper.insert(log);
- }
- /**
- * 查询客户详情
- * @param intentions
- * @return
- */
- @Override
- public CustomerOut findCustomerDetails(String id) {
- CustomerOut co = customerMapper.selectCustomerById(id);
- if(null !=co) setFiled(co);
- return co;
- }
-
- /**
- * 修改客户信息
- * @param intentions
- * @return
- */
- @Override
- public int updateCustomer(Customer c) {
- //修改主表
- return customerMapper.updateByPrimaryKeySelective(c);
-
- }
-
- /**
- * 查询客户基本信息
- */
- @Override
- public CustomerOut findCustomerBaseInfo(String id) {
- Customer cus = customerMapper.selectByPrimaryKey(id);
- CustomerOut cusOut = new CustomerOut();
- try {
- BeanUtils.copyProperties(cusOut, cus);
- } catch (IllegalAccessException | InvocationTargetException e) {
- e.printStackTrace();
- }
- if(cusOut != null) setFiled(cusOut);
- return cusOut;
- }
-
- /**
- * 客户资料脱敏
- * @param cusOut
- */
- private List<CustomerOut> descResult(List<CustomerOut> outList){
- for(CustomerOut out : outList){
- //out.setAdminName("***");
- //out.set_followSituation("***");
- //out.set_companyIntention("***");
- out.setContactName("***");
- out.setMobile("***");
- out.setTelNum("***");
- }
- return outList;
- }
- @Override
- public List<CustomerLog> listCustomerLog(String customerId) {
-
- return customerLogMapper.listCustomerLog(customerId);
- }
- @Override
- public CustomerOut findCustomerHistory(String customerId) {
-
- return customerMapper.findCustomerHistory(customerId);
- }
- }
|