package com.goafanti.customer.service.impl; import java.lang.reflect.InvocationTargetException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; import javax.annotation.Resource; import org.apache.commons.beanutils.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.goafanti.common.bo.Error; import com.goafanti.common.constant.AFTConstants; import com.goafanti.common.constant.ErrorConstants; import com.goafanti.common.dao.BusinessGlossoryMapper; import com.goafanti.common.dao.OrganizationContactBookMapper; import com.goafanti.common.dao.OrganizationIdentityMapper; import com.goafanti.common.dao.UserBusinessMapper; import com.goafanti.common.dao.UserFollowBusinessMapper; import com.goafanti.common.dao.UserFollowMapper; import com.goafanti.common.dao.UserIdentityMapper; import com.goafanti.common.dao.UserMapper; import com.goafanti.common.enums.CustomerStatusFiled; import com.goafanti.common.enums.DeleteStatus; import com.goafanti.common.enums.IdentityProcess; import com.goafanti.common.enums.MemberStatus; import com.goafanti.common.enums.UserLevel; import com.goafanti.common.enums.UserType; import com.goafanti.common.error.BusinessException; import com.goafanti.common.model.Admin; import com.goafanti.common.model.OrganizationContactBook; import com.goafanti.common.model.OrganizationIdentity; import com.goafanti.common.model.User; import com.goafanti.common.model.UserBusiness; import com.goafanti.common.model.UserFollow; import com.goafanti.common.model.UserFollowBusiness; import com.goafanti.common.model.UserIdentity; import com.goafanti.common.utils.BeanUtilsExt; import com.goafanti.common.utils.PasswordUtil; import com.goafanti.common.utils.StringUtils; 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.BusinessListBo; import com.goafanti.customer.bo.BussinessFollowBo; import com.goafanti.customer.bo.CustomerExcelBo; import com.goafanti.customer.bo.CustomerListIn; import com.goafanti.customer.bo.CustomerListOut; import com.goafanti.customer.bo.CustomerOrganizationDetailBo; import com.goafanti.customer.bo.CustomerPersonalDetailBo; import com.goafanti.customer.bo.CustomerSimpleBo; import com.goafanti.customer.bo.FollowBusinessBo; import com.goafanti.customer.bo.FollowListBo; import com.goafanti.customer.bo.StatisticBo; import com.goafanti.customer.service.CustomerService; @Service public class CustomerServiceImpl extends BaseMybatisDao implements CustomerService { @Autowired private UserMapper userMapper; @Autowired private UserIdentityMapper userIdentityMapper; @Autowired private OrganizationIdentityMapper organizationIdentityMapper; @Autowired private OrganizationContactBookMapper organizationContactBookMapper; @Resource(name = "passwordUtil") private PasswordUtil passwordUtil; @Resource private UserFollowMapper userFollowMapper; @Resource private UserBusinessMapper userBusinessMapper; @Resource private UserFollowBusinessMapper userFollowBusinessMapper; @Resource private BusinessGlossoryMapper businessGlossoryMapper; @Override public Pagination listPrivatePersonalCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) { cli.setType(AFTConstants.USER_TYPE_PERSONAL); cli.setAid(TokenManager.getAdminId()); cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE)); Map params = disposeParams(cli); @SuppressWarnings("unchecked") Pagination list = (Pagination) findPage("selectPersonalCustomerList","selectPersonalCustomerCount",params,pageNo,pageSize); return list; } @Override public Pagination listPublicPersonalCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) { cli.setType(AFTConstants.USER_TYPE_PERSONAL); cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PUBLIC)); Map params = disposeParams(cli); @SuppressWarnings("unchecked") Pagination list = (Pagination) findPage("selectPersonalCustomerList","selectPersonalCustomerCount",params,pageNo,pageSize); return list; } @Override public Pagination listAllPersonalCustomer(CustomerListIn cli, Integer pageNo, Integer pageSize) { cli.setType(AFTConstants.USER_TYPE_PERSONAL); cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE)); Map params = disposeParams(cli); if(null!=cli.getExpertAudit())params.put("expertAudit", cli.getExpertAudit()); @SuppressWarnings("unchecked") Pagination list = (Pagination) findPage("selectPersonalCustomerList","selectPersonalCustomerCount",params,pageNo,pageSize); return list; } @Override public Pagination listAllManagePersonalCustomer(CustomerListIn cli, Integer pageNo, Integer pageSize) { cli.setType(AFTConstants.USER_TYPE_PERSONAL); cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE)); Map params = disposeParams(cli); @SuppressWarnings("unchecked") Pagination list = (Pagination) findPage("selectManagePersonalCustomerList","selectManagePersonalCustomerCount",params,pageNo,pageSize); return list; } @Override public Pagination listPrivateOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) { cli.setType(AFTConstants.USER_TYPE_ORGANIZATION); cli.setAid(TokenManager.getAdminId()); cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE)); Map params = disposeParams(cli); @SuppressWarnings("unchecked") Pagination list = (Pagination) findPage("selectOrganizationCustomerList","selectOrganizationCustomerCount",params,pageNo,pageSize); return list; } @Override public Pagination listPublicOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) { cli.setType(AFTConstants.USER_TYPE_ORGANIZATION); /*cli.setAid(TokenManager.getAdminId());*/ cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PUBLIC)); Map params = disposeParams(cli); @SuppressWarnings("unchecked") Pagination list = (Pagination) findPage("selectOrganizationCustomerList","selectOrganizationCustomerCount",params,pageNo,pageSize); return list; } @Override public Pagination listAllOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) { cli.setType(AFTConstants.USER_TYPE_ORGANIZATION); Map params = disposeParams(cli); @SuppressWarnings("unchecked") Pagination list = (Pagination) findPage("selectOrganizationCustomerList","selectOrganizationCustomerCount",params,pageNo,pageSize); return list; } @Override public Pagination listAllManageOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) { cli.setType(AFTConstants.USER_TYPE_ORGANIZATION); cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE)); Map params = disposeParams(cli); @SuppressWarnings("unchecked") Pagination list = (Pagination) findPage("selectManageOrganizationCustomerList","selectManageOrganizationCustomerCount",params,pageNo,pageSize); return list; } private Map disposeParams(CustomerListIn cli){ Map params = new HashMap(); if(StringUtils.isNotBlank(cli.getType())) params.put("type", Integer.parseInt(cli.getType())); if(StringUtils.isNotBlank(cli.getShareType())) params.put("shareType", Integer.parseInt(cli.getShareType())); if(StringUtils.isNotBlank(cli.getName())) params.put("name", cli.getName()); if(StringUtils.isNotBlank(cli.getProvince())) params.put("province", Integer.parseInt(cli.getProvince())); if(StringUtils.isNotBlank(cli.getCity())) params.put("city", Integer.parseInt(cli.getCity())); if(StringUtils.isNotBlank(cli.getArea())) params.put("area", Integer.parseInt(cli.getArea())); if(StringUtils.isNotBlank(cli.getContacts())) params.put("contacts", cli.getContacts()); if(StringUtils.isNotBlank(cli.getContactMobile())) params.put("contactMobile", cli.getContactMobile()); if(StringUtils.isNotBlank(cli.getStartDate())) params.put("startDate", cli.getStartDate()); if(StringUtils.isNotBlank(cli.getEndDate())) params.put("endDate", cli.getEndDate()); if(StringUtils.isNotBlank(cli.getExpert())) params.put("expert", Integer.parseInt(cli.getExpert())); if(StringUtils.isNotBlank(cli.getIndustry())) params.put("industry", Integer.parseInt(cli.getIndustry())); if(StringUtils.isNotBlank(cli.getInternational())) params.put("international", Integer.parseInt(cli.getInternational())); if(StringUtils.isNotBlank(cli.getAuditStatus())) params.put("auditStatus", Integer.parseInt(cli.getAuditStatus())); if(StringUtils.isNotBlank(cli.getBusinessAudit())) params.put("businessAudit", Integer.parseInt(cli.getBusinessAudit())); if(StringUtils.isNotBlank(cli.getCurrentMemberStatus())) params.put("currentMemberStatus", Integer.parseInt(cli.getCurrentMemberStatus())); if(StringUtils.isNotBlank(cli.getLvl())) params.put("lvl", Integer.parseInt(cli.getLvl())); if(StringUtils.isNotBlank(cli.getListed())) params.put("listed", Integer.parseInt(cli.getListed())); if(StringUtils.isNotBlank(cli.getHighTechZone())) params.put("highTechZone", Integer.parseInt(cli.getHighTechZone())); if(StringUtils.isNotBlank(cli.getExpert())) params.put("expert", Integer.parseInt(cli.getExpert())); if(StringUtils.isNotBlank(cli.getCelebrity())) params.put("celebrity", Integer.parseInt(cli.getCelebrity())); if(StringUtils.isNotBlank(cli.getAid())) params.put("aid", cli.getAid()); if(StringUtils.isNotBlank(cli.getIsMember())) params.put("isMember", Integer.parseInt(cli.getIsMember())); if(StringUtils.isNotBlank(cli.getStatus())) params.put("status", Integer.parseInt(cli.getStatus())); if(StringUtils.isNotBlank(cli.getSocietyTag())) params.put("societyTag", cli.getSocietyTag()); if(StringUtils.isNotBlank(cli.getStartDate())) params.put("startDate", cli.getStartDate()+" 00:00:00"); if(StringUtils.isNotBlank(cli.getEndDate())) params.put("endDate", cli.getEndDate()+" 23:59:59"); return params; } @Override public List findCustomerByName(String name) { return userMapper.findCustomerByName(name); } @Override public int judgeCustomerByName(String name) { return userMapper.judgeCustomerByName(name); } @Override @Transactional public int addCustomer(String name, String contacts, String contactMobile, Integer type,String societyTag) throws BusinessException{ User user = new User(); Date now = new Date(); String uid = UUID.randomUUID().toString(); String identifyId = UUID.randomUUID().toString(); user.setId(uid); user.setIdentifyName(name); user.setSource(AFTConstants.USER_SOURCE_CREATE); user.setNickname(name); user.setStatus(AFTConstants.USER_STATUS_NORMAL); user.setShareType(AFTConstants.NO); user.setAid(TokenManager.getAdminId()); user.setType(type); user.setCurrentMemberStatus(MemberStatus.NORMAL.getCode()); user.setLvl(UserLevel.CERTIFIED.getCode()); user.setSocietyTag(societyTag); user.setCreateTime(now); user.setUpdateTime(now); user.setMobile(contactMobile); user.setPassword(AFTConstants.INITIALPASSWORD); user.setAuditStatus(AFTConstants.USER_STATUS); user.setIsMember(AFTConstants.NO); user.setBusinessAudit(AFTConstants.NO); passwordUtil.encryptPassword(user); if(type == UserType.PERSONAL.getCode()){ if(userMapper.checkUser("", "", contactMobile, type,null,null).size()>0) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_EXIST, name,"")); UserIdentity ui = new UserIdentity(); ui.setId(identifyId); ui.setUid(uid); ui.setContacts(contacts); ui.setContactMobile(contactMobile); ui.setUsername(name); ui.setExpert(AFTConstants.NO); ui.setCelebrity(AFTConstants.NO); ui.setInternational(AFTConstants.NO); ui.setAuditStatus(IdentityProcess.SUCCESS.getCode());//认证个人 userIdentityMapper.insert(ui); }else if(type == UserType.ORGANIZATION.getCode()){ if(userMapper.checkUser("",name,"",type,null,null).size()>0) throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_EXIST, name,"")); // 创建企业认证信息 OrganizationIdentity oi = new OrganizationIdentity(); oi.setUnitName(name); oi.setId(identifyId); oi.setUid(uid); oi.setContacts(contacts); oi.setContactMobile(contactMobile); oi.setHighTechZone(AFTConstants.NO); oi.setInternational(AFTConstants.NO); oi.setListed(AFTConstants.NO); oi.setAuditStatus(IdentityProcess.SUCCESS.getCode()); //实名企业 organizationIdentityMapper.insert(oi); } userMapper.insert(user); //新增企业联系人 OrganizationContactBook cob = new OrganizationContactBook(); cob.setAid(TokenManager.getAdminId()); cob.setId(UUID.randomUUID().toString()); cob.setUid(uid); cob.setName(contacts); cob.setMobile(contactMobile); cob.setMajor(AFTConstants.NO); organizationContactBookMapper.insert(cob); return 1; } @Override public CustomerPersonalDetailBo findPersonalCustomerDetail(String uid) { return userMapper.findPersonalCustomerDetail(uid); } @Override public CustomerOrganizationDetailBo findOrganizationCustomerDetail(String uid) { return userMapper.findOrganizationCustomerDetail(uid); } @Override @Transactional public int updateOrganizationCustomer(CustomerOrganizationDetailBo bo) { OrganizationIdentity oi = new OrganizationIdentity(); User user = new User(); try { BeanUtilsExt.copyProperties(oi, bo); user.setId(bo.getUid()); user.setSocietyTag(bo.getSocietyTag()); user.setCompanyLogoUrl(bo.getCompanyLogoUrl()); user.setIntroduction(bo.getIntroduction()); user.setUpdateTime(new Date()); user.setBusinessAudit(bo.getBusinessAudit()); } catch (IllegalAccessException |InvocationTargetException e) { e.printStackTrace(); } organizationIdentityMapper.updateByPrimaryKeySelective(oi); userMapper.updateByPrimaryKeySelective(user); return 1; } @Override public int updatePersonalCustomer(CustomerPersonalDetailBo bo) { UserIdentity ui = new UserIdentity(); User user = new User(); try { BeanUtilsExt.copyProperties(ui, bo); user.setId(bo.getUid()); user.setSocietyTag(bo.getSocietyTag()); user.setHeadPortraitUrl(bo.getHeadPortraitUrl()); user.setIntroduction(bo.getIntroduction()); user.setUpdateTime(new Date()); user.setBusinessAudit(bo.getBusinessAudit()); if(null==bo.getExpertAudit()&&bo.getExpert()==1)ui.setExpertAudit(2); } catch (InvocationTargetException | IllegalAccessException e) { e.printStackTrace(); } userIdentityMapper.updateByPrimaryKeySelective(ui); userMapper.updateByPrimaryKeySelective(user); return 1; } @SuppressWarnings("unchecked") @Override public Pagination listFollowHistory(Integer pageNo, Integer pageSize,String uid,String businessGlossoryId) { Map params = new HashMap(); if(StringUtils.isNotBlank(uid))params.put("uid", uid); if(StringUtils.isNotBlank(businessGlossoryId)) params.put("businessGlossoryId", businessGlossoryId); return (Pagination)findPage("selectFollowHistoryList","selectFollowHistoryCount",params, pageNo, pageSize); } @Override public User findUserAccountDetail(String uid) { return userMapper.findUserAccountDetail(uid); } @Override public int updateUserAccount(User user) { return userMapper.updateByPrimaryKeySelective(user); } @Override public List findCustomerContacts(String uid) { return userMapper.findCustomerContacts(uid,TokenManager.getAdminId()); } @Override @Transactional public int addFollow(FollowBusinessBo fbb) throws BusinessException{ if(fbb.getUserBusinessList().size()<1) throw new BusinessException(new Error(ErrorConstants.AT_LEAST_A_BUSINESS,"","")); //更新跟进记录表 SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS); UserFollow userFollow = new UserFollow(); String followId = UUID.randomUUID().toString(); userFollow.setId(followId); userFollow.setAid(TokenManager.getAdminId()); userFollow.setContactType(Integer.parseInt(fbb.getContactType())); userFollow.setEffective(DeleteStatus.UNDELETE.getCode()); try { userFollow.setCreateTime(format.parse(fbb.getFollowTime())); } catch (ParseException e) { e.printStackTrace(); } userFollow.setOcbId(fbb.getOcbId()); userFollow.setResult(fbb.getResult()); userFollow.setUid(fbb.getUid()); int followCount = userBusinessMapper.selectFollowCountByUAid(fbb.getUid(), TokenManager.getAdminId()) + 1; userFollow.setFollowCount(followCount); userFollowMapper.insert(userFollow); String ufbId = ""; UserBusiness userBusiness = null; UserFollowBusiness userFollowBusiness = null; for(UserBusiness ub: fbb.getUserBusinessList()){ userBusiness = new UserBusiness(); userFollowBusiness = new UserFollowBusiness(); ufbId = UUID.randomUUID().toString(); if(StringUtils.isNotBlank(ub.getId())){ //更新业务表 userBusiness.setId(ub.getId()); userBusiness.setBusinessGlossoryId(ub.getBusinessGlossoryId()); userBusiness.setCustomerStatus(ub.getCustomerStatus()); userBusiness.setFollowSituation(ub.getFollowSituation()); userBusiness.setUid(fbb.getUid()); try { userBusiness.setUpdateTime(format.parse(fbb.getFollowTime())); } catch (ParseException e) { e.printStackTrace(); } userBusiness.setAid(TokenManager.getAdminId()); userBusinessMapper.updateByPrimaryKeySelective(userBusiness); //更新业务中间表 userFollowBusiness.setBusinessId(ub.getId()); userFollowBusiness.setCustomerStatus(ub.getCustomerStatus()); userFollowBusiness.setFollowSituation(ub.getFollowSituation()); userFollowBusiness.setId(ufbId); userFollowBusiness.setFollowId(followId); userFollowBusiness.setRemarks(ub.getRemarks()); userFollowBusiness.setBusinessGlossoryId(ub.getBusinessGlossoryId()); userFollowBusinessMapper.insert(userFollowBusiness); }else{ //检测是否可以创建业务 if(userBusinessMapper.judgeBusiness(fbb.getUid(), ub.getBusinessGlossoryId(), "")>0){ String businessName = businessGlossoryMapper.selectByPrimaryKey(ub.getBusinessGlossoryId()).getName(); throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_EXIST,businessName,"")); } String ubId = UUID.randomUUID().toString(); //更新业务表 userBusiness.setId(ubId); userBusiness.setBusinessGlossoryId(ub.getBusinessGlossoryId()); try { userBusiness.setCreateTime(format.parse(fbb.getFollowTime())); userBusiness.setUpdateTime(format.parse(fbb.getFollowTime())); } catch (ParseException e) { e.printStackTrace(); } userBusiness.setCustomerStatus(ub.getCustomerStatus()); userBusiness.setFollowSituation(ub.getFollowSituation()); userBusiness.setUid(fbb.getUid()); userBusiness.setAid(TokenManager.getAdminId()); userBusinessMapper.insert(userBusiness); //更新业务中间表 userFollowBusiness.setBusinessId(ubId); userFollowBusiness.setCustomerStatus(ub.getCustomerStatus()); userFollowBusiness.setFollowSituation(ub.getFollowSituation()); userFollowBusiness.setId(ufbId); userFollowBusiness.setFollowId(followId); userFollowBusiness.setRemarks(ub.getRemarks()); userFollowBusiness.setBusinessGlossoryId(ub.getBusinessGlossoryId()); userFollowBusinessMapper.insert(userFollowBusiness); } } return 1; } @Override public FollowBusinessBo findFollowById(String followId) { return userMapper.findFollowById(followId); } @Override public List findBusinessByFollowId(String followId) { return userMapper.findBusinessByFollowId(followId); } @Override @Transactional public int updateFollow(FollowBusinessBo fbb) throws BusinessException{ UserFollow userFollow = new UserFollow(); SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS); userFollow.setId(fbb.getFollowId()); if(StringUtils.isNotBlank(fbb.getOcbId())) userFollow.setOcbId(fbb.getOcbId()); userFollow.setResult(fbb.getResult()); userFollow.setContactType(Integer.parseInt(fbb.getContactType())); userFollowMapper.updateByPrimaryKeySelective(userFollow); //修改拜访记录表 UserFollowBusiness userFollowBusiness = null; for(UserBusiness ub: fbb.getUserBusinessList()){ userFollowBusiness = new UserFollowBusiness(); if(StringUtils.isNotBlank(ub.getId())){ userFollowBusiness.setId(ub.getId()); userFollowBusiness.setFollowSituation(ub.getFollowSituation()); userFollowBusiness.setCustomerStatus(ub.getCustomerStatus()); userFollowBusiness.setRemarks(ub.getRemarks()); userFollowBusinessMapper.updateByPrimaryKeySelective(userFollowBusiness); //修改拜访记录中间表 }else{ //检测是否可以创建业务 if(userBusinessMapper.judgeBusiness(fbb.getUid(), ub.getBusinessGlossoryId(), "")>0){ String businessName = businessGlossoryMapper.selectByPrimaryKey(ub.getBusinessGlossoryId()).getName(); throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_EXIST,businessName,"")); } String ubId = UUID.randomUUID().toString(); UserBusiness userBusiness = new UserBusiness(); //更新业务表 userBusiness.setId(ubId); userBusiness.setBusinessGlossoryId(ub.getBusinessGlossoryId()); try { userBusiness.setCreateTime(format.parse(fbb.getFollowTime())); userBusiness.setUpdateTime(format.parse(fbb.getFollowTime())); } catch (ParseException e) { e.printStackTrace(); } userBusiness.setCustomerStatus(ub.getCustomerStatus()); userBusiness.setFollowSituation(ub.getFollowSituation()); userBusiness.setUid(fbb.getUid()); userBusiness.setAid(TokenManager.getAdminId()); userBusinessMapper.insert(userBusiness); //更新业务中间表 String ufbId = UUID.randomUUID().toString(); userFollowBusiness.setId(ufbId); userFollowBusiness.setFollowId(fbb.getFollowId()); userFollowBusiness.setBusinessId(ubId); userFollowBusiness.setCustomerStatus(ub.getCustomerStatus()); userFollowBusiness.setFollowSituation(ub.getFollowSituation()); userFollowBusiness.setRemarks(ub.getRemarks()); userFollowBusiness.setBusinessGlossoryId(ub.getBusinessGlossoryId()); userFollowBusinessMapper.insert(userFollowBusiness); } } return 1; } @Override public Set findAllContacts(String uid) { Set result = new HashSet(); result.addAll(userMapper.findAllContacts(uid)); return result; } @Override public int updateCustomerContacts(List ocbList,String uid) { if(ocbList.size()>0){ OrganizationContactBook ocb = null; for(OrganizationContactBook item: ocbList){ ocb = new OrganizationContactBook(); try { BeanUtils.copyProperties(ocb, item); if(StringUtils.isBlank(ocb.getId())){ ocb.setId(UUID.randomUUID().toString()); ocb.setUid(uid); ocb.setAid(TokenManager.getAdminId()); organizationContactBookMapper.insert(ocb); }else{ organizationContactBookMapper.updateByPrimaryKeySelective(ocb); } } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); } } } return 1; } @Override public int deleteFollow(String followId) { UserFollow uf = new UserFollow(); uf.setId(followId); uf.setEffective(DeleteStatus.DELETED.getCode()); return userFollowMapper.updateByPrimaryKeySelective(uf); } @Override public void checkCustomer(Set boSet, Set existRows, Set filterRows) { List list = null; CustomerExcelBo[] bos = (CustomerExcelBo[])boSet.toArray(new CustomerExcelBo[] {}); for (int i=0;i 0) { bo.setUid(list.get(0).getId()); bo.setNewData(false); if (userBusinessMapper.judgeBusiness(bo.getUid(), Integer.parseInt(bo.getBusinessGlossoryId()),"") > 0) { existRows.add(bo.getRowNumber()); } }else{ bo.setUid(UUID.randomUUID().toString()); bo.setNewData(true); } }else{ if (userBusinessMapper.judgeBusiness(bo.getUid(), Integer.parseInt(bo.getBusinessGlossoryId()),"") > 0) { existRows.add(bo.getRowNumber()); } } } } @Override @Transactional public int saveUploadData(Set boSet) { Date now = new Date(); String uid = ""; for(CustomerExcelBo bo : boSet){ uid = bo.getUid(); if(bo.isNewData()){ //新建客户 createUser(bo, uid, now); createIdentity(bo, bo.getCustomerType(), uid); createBusiness(bo, uid, now); createContacts(bo, uid); }else{ //新建业务 createBusiness(bo, uid, now); if(organizationContactBookMapper.checkContacts(uid, bo.getMobile(), TokenManager.getAdminId())<=0){ createContacts(bo, uid); } } } return 1; } private void createUser(CustomerExcelBo bo,String uid,Date now){ User user = new User(); user.setId(uid); user.setIdentifyName(bo.getIdentifyName()); user.setSource(AFTConstants.USER_SOURCE_CREATE); user.setNickname(bo.getIdentifyName()); user.setStatus(AFTConstants.USER_STATUS_NORMAL); user.setAuditStatus(AFTConstants.USER_STATUS); user.setShareType(AFTConstants.USER_SHARE_PRIVATE); user.setAid(TokenManager.getAdminId()); user.setType(Integer.parseInt(bo.getCustomerType())); user.setCurrentMemberStatus(MemberStatus.NORMAL.getCode()); user.setLvl(UserLevel.CERTIFIED.getCode()); user.setCreateTime(now); user.setUpdateTime(now); user.setMobile(bo.getMobile()); user.setPassword(AFTConstants.INITIALPASSWORD); user.setIsMember(AFTConstants.NO); user.setBusinessAudit(AFTConstants.NO); passwordUtil.encryptPassword(user); userMapper.insert(user); } private void createIdentity(CustomerExcelBo bo,String type,String uid){ String identifyId = UUID.randomUUID().toString(); if(type.equals(AFTConstants.USER_TYPE_PERSONAL)){ //新增个人认证信息 UserIdentity ui = new UserIdentity(); ui.setId(identifyId); ui.setUid(uid); ui.setContacts(bo.getContacts()); ui.setContactMobile(bo.getMobile()); ui.setUsername(bo.getIdentifyName()); ui.setExpert(AFTConstants.NO); ui.setCelebrity(AFTConstants.NO); ui.setInternational(AFTConstants.NO); ui.setAuditStatus(5); userIdentityMapper.insert(ui); }else if(type.equals(AFTConstants.USER_TYPE_ORGANIZATION)){ // 创建企业认证信息 OrganizationIdentity oi = new OrganizationIdentity(); oi.setId(identifyId); oi.setUnitName(bo.getIdentifyName()); oi.setUid(uid); oi.setContacts(bo.getContacts()); oi.setContactMobile(bo.getMobile()); oi.setHighTechZone(AFTConstants.NO); oi.setInternational(AFTConstants.NO); oi.setListed(AFTConstants.NO); oi.setAuditStatus(5); //实名企业 organizationIdentityMapper.insert(oi); } } private void createContacts(CustomerExcelBo bo,String uid){ //新增企业联系人 OrganizationContactBook cob = new OrganizationContactBook(); cob.setAid(TokenManager.getAdminId()); cob.setId(UUID.randomUUID().toString()); cob.setUid(uid); cob.setName(bo.getContacts()); cob.setMobile(bo.getMobile()); cob.setMajor(AFTConstants.NO); organizationContactBookMapper.insert(cob); } private void createBusiness(CustomerExcelBo bo,String uid,Date now){ //新增业务 UserBusiness ub = new UserBusiness(); ub.setId(UUID.randomUUID().toString()); ub.setAid(TokenManager.getAdminId()); ub.setBusinessGlossoryId(Integer.parseInt(bo.getBusinessGlossoryId())); ub.setUid(uid); ub.setCreateTime(now); ub.setUpdateTime(now); ub.setCustomerStatus(Integer.parseInt(bo.getCustomerStatus())); ub.setFollowSituation(Integer.parseInt(bo.getFollowSituation())); userBusinessMapper.insert(ub); } @Override public int updateByOperatorType(String uid, String operatorType,Object... params) { User user = new User(); user.setId(uid); if(operatorType.equals(AFTConstants.USER_TRANSFER_TO_PUBLIC)){ user.setShareType(AFTConstants.USER_SHARE_PUBLIC); user.setAid(""); }else if(operatorType.equals(AFTConstants.USER_RECEIVE)){ user.setAid(TokenManager.getAdminId()); user.setShareType(AFTConstants.USER_SHARE_PRIVATE); }else if(operatorType.equals(AFTConstants.USER_DELETE)){ user.setStatus(AFTConstants.USER_STATUS_CANCEL); }else if(operatorType.equals(AFTConstants.USER_TRANSFER_TO_OTHER)){ user.setAid(String.valueOf(params[0])); } return userMapper.updateByPrimaryKeySelective(user); } @SuppressWarnings("unchecked") @Override public Pagination customerStatistics(Date sDate, Date eDate, String depNo, String businessGlossoryId, Integer pageNo, Integer pageSize) { Map params = new HashMap(); if(null != sDate) params.put("sDate", sDate); if(null != eDate) params.put("eDate", eDate); if(StringUtils.isNotBlank(depNo)) params.put("depNo", depNo); if(StringUtils.isNotBlank(businessGlossoryId)) params.put("businessGlossoryId", businessGlossoryId); Pagination page = (Pagination)findPage("customerStatisticsList", "customerStatisticsCount", params, pageNo, pageSize); return page; } @SuppressWarnings("unchecked") @Override public Pagination businessStatistic(Date sDate, Date eDate,String depNo, String businessGlossoryId,Integer pageNo, Integer pageSize) { Map params = new HashMap(); if(null != sDate) params.put("sDate", sDate); if(null != eDate) params.put("eDate", eDate); if(StringUtils.isNotBlank(depNo)) params.put("depNo", depNo); if(StringUtils.isNotBlank(businessGlossoryId)) params.put("businessGlossoryId", businessGlossoryId); Pagination page = (Pagination)findPage("businessStatisticList", "businessStatisticCount", params, pageNo, pageSize); return page; } @SuppressWarnings("unchecked") @Override public Pagination followStatistic(Date sDate, Date eDate, String depNo, Integer pageNo, Integer pageSize) { Map params = new HashMap(); if(null != sDate) params.put("sDate", sDate); if(null != eDate) params.put("eDate", eDate); if(StringUtils.isNotBlank(depNo)) params.put("depNo", depNo); Pagination page = (Pagination)findPage("followStatisticList", "followStatisticCount", params, pageNo, pageSize); return page; } @SuppressWarnings("unchecked") @Override public Pagination listBusiness(BusinessListBo blo,Integer pageNo,Integer pageSize) { blo.setAid(TokenManager.getAdminId()); return (Pagination) findPage("selectBusinessList", "selectBusinessCount", disposeParams(blo), pageNo, pageSize); } @SuppressWarnings("unchecked") @Override public Pagination listAllBusiness(BusinessListBo blo, Integer pageNo, Integer pageSize) { return (Pagination) findPage("selectBusinessList", "selectBusinessCount", disposeParams(blo), pageNo, pageSize); } @SuppressWarnings("unchecked") @Override public Pagination listManageBusiness(BusinessListBo blo,Integer pageNo,Integer pageSize) { blo.setAid(TokenManager.getAdminId()); return (Pagination) findPage("selectBusinessManageList", "selectBusinessManageCount", disposeParams(blo), pageNo, pageSize); } private Map disposeParams(BusinessListBo blo){ Map params = new HashMap(); if(StringUtils.isNotBlank(blo.getUid())) params.put("uid", blo.getUid()); if(StringUtils.isNotBlank(blo.getAid())) params.put("aid", blo.getAid()); if(StringUtils.isNotBlank(blo.getAdminName())) params.put("adminName", blo.getAdminName()); if(StringUtils.isNotBlank(blo.getBusinessGlossoryId())) params.put("businessGlossoryId", blo.getBusinessGlossoryId()); if(StringUtils.isNotBlank(blo.getStartDate())) params.put("startDate", blo.getStartDate()+" 00:00:00"); if(StringUtils.isNotBlank(blo.getEndDate())) params.put("endDate", blo.getEndDate()+ " 23:59:59"); if(StringUtils.isNotBlank(blo.getIdentifyName())) params.put("identifyName", blo.getIdentifyName()); if(StringUtils.isNoneBlank(blo.getFollowSituation())) params.put("followSituation", blo.getFollowSituation()); if(StringUtils.isNotBlank(blo.getCustomerStatus())) params.put("customerStatus", blo.getCustomerStatus()); return params; } @Override public List findBusinessGlossory() { return userBusinessMapper.findBusinessGlossory(); } @Override public int judgeBusiness(String uid, Integer businessGlossoryId) { return userBusinessMapper.judgeBusiness(uid,businessGlossoryId,""); } @Override @Transactional public void addBusinessAndFollow(BussinessFollowBo bfb) throws ParseException { UserBusiness ub = new UserBusiness(); String ubId = UUID.randomUUID().toString(); SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS); ub.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus())); ub.setFollowSituation(Integer.parseInt(bfb.getFollowSituation())); ub.setId(ubId); ub.setUid(bfb.getUid()); ub.setAid(TokenManager.getAdminId()); ub.setRemarks(bfb.getRemarks()); ub.setBusinessGlossoryId(Integer.parseInt(bfb.getBusinessGlossoryId())); ub.setUpdateTime(format.parse(bfb.getCreateTime())); ub.setCreateTime(format.parse(bfb.getCreateTime())); userBusinessMapper.insert(ub); if (StringUtils.isNotBlank(bfb.getOcbId())) { // 跟进联系人不为空则添加跟进记录 UserFollow uf = new UserFollow(); String ufId = UUID.randomUUID().toString(); uf.setId(ufId); uf.setUid(bfb.getUid()); uf.setCreateTime(format.parse(bfb.getFollowTime())); uf.setOcbId(bfb.getOcbId()); uf.setResult(bfb.getResult()); uf.setContactType(Integer.parseInt(bfb.getContactType())); uf.setAid(TokenManager.getAdminId()); uf.setEffective(0); int followCount = userBusinessMapper.selectFollowCountByUAid(bfb.getUid(), TokenManager.getAdminId()) + 1; uf.setFollowCount(followCount); userFollowMapper.insert(uf); UserFollowBusiness ufb = new UserFollowBusiness(); ufb.setId(UUID.randomUUID().toString()); ufb.setBusinessId(ubId); ufb.setFollowId(ufId); ufb.setCustomerStatus(ub.getCustomerStatus()); ufb.setFollowSituation(ub.getFollowSituation()); ufb.setBusinessGlossoryId(Integer.parseInt(bfb.getBusinessGlossoryId())); userFollowBusinessMapper.insert(ufb); } } @Override public List findBusinessByUAid(String uid, String aid) { return userBusinessMapper.findBusinessByUAid(uid,aid); } @Override public BussinessFollowBo findBusinessDetail(String businessId) { return userBusinessMapper.findBusinessDetail(businessId); } @Override public int updateBusiness(BussinessFollowBo bfb) { UserBusiness userBusiness = new UserBusiness(); userBusiness.setId(bfb.getBusinessId()); userBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus())); userBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation())); userBusiness.setRemarks(bfb.getRemarks()); userBusiness.setUpdateTime(new Date()); return userBusinessMapper.updateByPrimaryKeySelective(userBusiness); } @Override @Transactional public int addFollowOneBusiness(BussinessFollowBo bfb) throws ParseException { Date updateTime = new Date(); SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS); UserBusiness userBusiness = new UserBusiness(); userBusiness.setId(bfb.getBusinessId()); userBusiness.setUpdateTime(updateTime); userBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus())); userBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation())); userBusinessMapper.updateByPrimaryKeySelective(userBusiness); UserFollow userFollow = new UserFollow(); String followId = UUID.randomUUID().toString(); int followCount = userBusinessMapper.selectFollowCountByUAid(bfb.getUid(), TokenManager.getAdminId()) + 1; userFollow.setId(followId); userFollow.setResult(bfb.getResult()); userFollow.setCreateTime(format.parse(bfb.getFollowTime())); userFollow.setEffective(0); userFollow.setOcbId(bfb.getOcbId()); userFollow.setFollowCount(followCount); userFollow.setContactType(Integer.parseInt(bfb.getContactType())); userFollow.setAid(TokenManager.getAdminId()); userFollow.setUid(bfb.getUid()); userFollowMapper.insert(userFollow); UserFollowBusiness userFollowBusiness = new UserFollowBusiness(); String ufbId = UUID.randomUUID().toString(); userFollowBusiness.setId(ufbId); userFollowBusiness.setFollowId(followId); userFollowBusiness.setBusinessGlossoryId(Integer.parseInt(bfb.getBusinessGlossoryId())); userFollowBusiness.setBusinessId(bfb.getBusinessId()); userFollowBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus())); userFollowBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation())); userFollowBusiness.setRemarks(bfb.getRemarks()); userFollowBusinessMapper.insert(userFollowBusiness); return 1; } @Override public BussinessFollowBo findFollowOneBusiness(String ufbId) { return userBusinessMapper.findFollowOneBusiness(ufbId); } @Override public int updateFollowOneBusiness(BussinessFollowBo bfb) { //修改业务跟进中间表 UserFollowBusiness userFollowBusiness = new UserFollowBusiness(); userFollowBusiness.setId(bfb.getUfbId()); userFollowBusiness.setRemarks(bfb.getRemarks()); userFollowBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus())); userFollowBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation())); userFollowBusinessMapper.updateByPrimaryKeySelective(userFollowBusiness); //修改跟进记录表 UserFollow userFollow = new UserFollow(); userFollow.setId(bfb.getFollowId()); userFollow.setContactType(Integer.parseInt(bfb.getContactType())); userFollow.setResult(bfb.getResult()); if(StringUtils.isNotBlank(bfb.getOcbId())) userFollow.setOcbId(bfb.getOcbId()); userFollowMapper.updateByPrimaryKeySelective(userFollow); return 1; } @Override public int addOneContact(OrganizationContactBook ocb) { ocb.setAid(TokenManager.getAdminId()); ocb.setId(UUID.randomUUID().toString()); ocb.setMajor(AFTConstants.NO); return organizationContactBookMapper.insert(ocb); } @Override public int deleteBusiness(String businessId) { return userBusinessMapper.deleteByPrimaryKey(businessId); } @Override public int updateBusinessToStop(String businessId) { UserBusiness ub = new UserBusiness(); ub.setId(businessId); ub.setCustomerStatus(CustomerStatusFiled.STATUS_STOP.getCode()); return userBusinessMapper.updateByPrimaryKeySelective(ub); } @Override public int deleteFollowOneBusiness(String ufbId) { UserFollowBusiness ufb = new UserFollowBusiness(); ufb.setId(ufbId); return userFollowBusinessMapper.deleteByPrimaryKey(ufbId); } @Override public int deleteOneContact(String ocbId) { return organizationContactBookMapper.deleteByPrimaryKey(ocbId); } @Override public List findAdminName() { String aid=TokenManager.getAdminId(); return userMapper.findAdminName(aid); } @Override public int updatePersonalCustomerz(CustomerPersonalDetailBo bo) { UserIdentity ui = new UserIdentity(); User user = new User(); try { BeanUtilsExt.copyProperties(ui, bo); user.setId(bo.getUid()); user.setSocietyTag(bo.getSocietyTag()); user.setHeadPortraitUrl(bo.getHeadPortraitUrl()); user.setIntroduction(bo.getIntroduction()); user.setUpdateTime(new Date()); user.setBusinessAudit(bo.getBusinessAudit()); if(!StringUtils.isBlank(bo.getAid())){ user.setAid(bo.getAid()); user.setShareType(0); } } catch (InvocationTargetException | IllegalAccessException e) { e.printStackTrace(); } userMapper.updateByPrimaryKeySelective(user); return 1; } @Override public Pagination findEnteringAudit(CustomerListOut clo, Integer pageNo, Integer pageSize) { Map params = disposeParams(clo); if(!StringUtils.isBlank(clo.getAdminName()))params.put("adminName", clo.getAdminName()); @SuppressWarnings("unchecked") Pagination list = (Pagination) findPage("findEnteringAuditList","findEnteringAuditCount",params,pageNo,pageSize); return list; } @Override public Pagination findEnteringAuditIsNo(CustomerListOut clo, Integer pageNo, Integer pageSize) { clo.setAid(TokenManager.getAdminId()); Map params = disposeParams(clo); if(!StringUtils.isBlank(clo.getAdminName()))params.put("adminName", clo.getAdminName()); @SuppressWarnings("unchecked") Pagination list = (Pagination) findPage("findEnteringAuditIsNoList","findEnteringAuditIsNoCount",params,pageNo,pageSize); return list; } @Override public int updateEnteringAudit(User bo) { String[] ary=bo.getId().split(","); for (String s : ary) { String id=s; Integer auditStatus=bo.getAuditStatus(); String auditOpinion=bo.getAuditOpinion(); userMapper.updateEnteringAudit(id,auditStatus,auditOpinion); } return 1; } @Override public int updateMainContact(String ocbId,String uid) { organizationContactBookMapper.updateSubContact(uid); organizationContactBookMapper.updateMainContact(ocbId); return 1; } @Override public int updateRefusedCustomer(String id,String nickname, String mobile, String societyTag) { User u=userMapper.selectByPrimaryKey(id); u.setNickname(nickname); u.setMobile(mobile); u.setSocietyTag(societyTag); return userMapper.updateRefusedCustomer(id, nickname, mobile, societyTag); } }