| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649 |
- 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.error.BusinessException;
- 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.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.service.CustomerService;
- @Service
- public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> 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<CustomerListOut> listPrivatePersonalCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
- cli.setType(AFTConstants.USER_TYPE_PERSONAL);
- cli.setAid(TokenManager.getAdminId());
- cli.setShareType(String.valueOf(AFTConstants.SHARE_TYPE_PRIVATE));
- Map<String,Object> params = disposeParams(cli);
- @SuppressWarnings("unchecked")
- Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPersonalCustomerList","selectPersonalCustomerCount",params,pageNo,pageSize);
- return list;
- }
- @Override
- public Pagination<CustomerListOut> listPublicPersonalCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
- cli.setType(AFTConstants.USER_TYPE_PERSONAL);
- cli.setAid(TokenManager.getAdminId());
- cli.setShareType(String.valueOf(AFTConstants.SHARE_TYPE_PUBLIC));
- Map<String,Object> params = disposeParams(cli);
- @SuppressWarnings("unchecked")
- Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPersonalCustomerList","selectPersonalCustomerCount",params,pageNo,pageSize);
- return list;
- }
- @Override
- public Pagination<CustomerListOut> listAllPersonalCustomer(CustomerListIn cli, Integer pageNo, Integer pageSize) {
- cli.setType(AFTConstants.USER_TYPE_PERSONAL);
- Map<String,Object> params = disposeParams(cli);
- @SuppressWarnings("unchecked")
- Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPersonalCustomerList","selectPersonalCustomerCount",params,pageNo,pageSize);
- return list;
- }
- @Override
- public Pagination<CustomerListOut> listPrivateOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
- cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
- cli.setAid(TokenManager.getAdminId());
- cli.setShareType(String.valueOf(AFTConstants.SHARE_TYPE_PRIVATE));
- Map<String,Object> params = disposeParams(cli);
- @SuppressWarnings("unchecked")
- Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectOrganizationCustomerList","selectOrganizationCustomerCount",params,pageNo,pageSize);
- return list;
- }
- @Override
- public Pagination<CustomerListOut> listPublicOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
- cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
- cli.setAid(TokenManager.getAdminId());
- cli.setShareType(String.valueOf(AFTConstants.SHARE_TYPE_PUBLIC));
- Map<String,Object> params = disposeParams(cli);
- @SuppressWarnings("unchecked")
- Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectOrganizationCustomerList","selectOrganizationCustomerCount",params,pageNo,pageSize);
- return list;
- }
- @Override
- public Pagination<CustomerListOut> listAllOrganizationCustomer(CustomerListIn cli, Integer pageNo,Integer pageSize) {
- cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
- Map<String,Object> params = disposeParams(cli);
- @SuppressWarnings("unchecked")
- Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectOrganizationCustomerList","selectOrganizationCustomerCount",params,pageNo,pageSize);
- return list;
- }
- private Map<String,Object> disposeParams(CustomerListIn cli){
- Map<String,Object> params = new HashMap<String, Object>();
- 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.getServiceCertification())) params.put("serviceCertification", Integer.parseInt(cli.getServiceCertification()));
- if(StringUtils.isNotBlank(cli.getUserCertification())) params.put("userCertification", Integer.parseInt(cli.getUserCertification()));
- 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<CustomerSimpleBo> 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(1);
- user.setNickname(name);
- user.setStatus(0);
- user.setShareType(0);
- user.setServiceCertification(0);
- user.setUserCertification(0);
- user.setAid(TokenManager.getAdminId());
- user.setType(type);
- user.setCurrentMemberStatus(0);
- user.setLvl(1);
- user.setSocietyTag(societyTag);
- user.setCreateTime(now);
- user.setUpdateTime(now);
- user.setMobile(contactMobile);
- user.setPassword(AFTConstants.INITIALPASSWORD);
- user.setIsMember(0);
- passwordUtil.encryptPassword(user);
- if(type == 0){
- if(userMapper.checkUser("", "", contactMobile, type).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(0);
- ui.setCelebrity(0);
- ui.setInternational(0);
- ui.setAuditStatus(0);
- userIdentityMapper.insert(ui);
- }else if(type == 1){
- if(userMapper.judgeCustomerByName(name)>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(0);
- oi.setInternational(0);
- oi.setListed(0);
- oi.setAuditStatus(5); //实名企业
- 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);
- 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());
- } 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());
- } catch (InvocationTargetException | IllegalAccessException e) {
- e.printStackTrace();
- }
- userIdentityMapper.updateByPrimaryKeySelective(ui);
- userMapper.updateByPrimaryKeySelective(user);
- return 1;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<FollowListBo> listFollowHistory(Integer pageNo, Integer pageSize,String uid,String businessGlossoryId) {
- Map<String, Object> params = new HashMap<String, Object>();
- if(StringUtils.isNotBlank(uid))params.put("uid", uid);
- if(StringUtils.isNotBlank(businessGlossoryId)) params.put("businessGlossoryId", businessGlossoryId);
- return (Pagination<FollowListBo>)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<OrganizationContactBook> 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(0);
- 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<UserBusiness> 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<OrganizationContactBook> findAllContacts(String uid) {
- Set<OrganizationContactBook> result = new HashSet<OrganizationContactBook>();
- result.addAll(userMapper.findAllContacts(uid));
- return result;
- }
- @Override
- public int updateCustomerContacts(List<OrganizationContactBook> 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(1);
- return userFollowMapper.updateByPrimaryKeySelective(uf);
- }
- @Override
- public void checkCustomer(Set<CustomerExcelBo> boSet, Set<Integer> existRows) {
- List<User> list = null;
- User user = null;
- for (CustomerExcelBo bo : boSet) {
- list = userMapper.checkUser("", bo.getIdentifyName(), "", Integer.parseInt(bo.getCustomerType()));
- if (list.size() > 0) {
- user = list.get(0);
- bo.setUid(user.getId());
- if (userBusinessMapper.judgeBusiness(bo.getUid(), Integer.parseInt(bo.getBusinessGlossoryId()),"") > 0) {
- existRows.add(bo.getRowNumber());
- }
- }
- }
- }
- @Override
- @Transactional
- public int saveUploadData(Set<CustomerExcelBo> boSet) {
- Date now = new Date();
- String uid = "";
- for(CustomerExcelBo bo : boSet){
- if(StringUtils.isBlank(bo.getUid())){ //新建客户
- uid = UUID.randomUUID().toString();
- createUser(bo, uid, now);
- createIdentity(bo, bo.getCustomerType(), uid);
- createBusiness(bo, uid, now);
- createContacts(bo, uid);
- }else{ //新建业务
- uid = bo.getUid();
- 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(1);
- user.setNickname(bo.getIdentifyName());
- user.setStatus(0);
- user.setShareType(0);
- user.setServiceCertification(0);
- user.setUserCertification(0);
- user.setAid(TokenManager.getAdminId());
- user.setType(Integer.parseInt(bo.getCustomerType()));
- user.setCurrentMemberStatus(0);
- user.setLvl(1);
- user.setCreateTime(now);
- user.setUpdateTime(now);
- user.setMobile(bo.getMobile());
- user.setPassword(AFTConstants.INITIALPASSWORD);
- user.setIsMember(0);
- 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(0);
- ui.setCelebrity(0);
- ui.setInternational(0);
- ui.setAuditStatus(0);
- 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(0);
- oi.setInternational(0);
- oi.setListed(0);
- 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());
- 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) {
- User user = new User();
- user.setId(uid);
- if(operatorType.equals(AFTConstants.USER_TRANSFER_TO_PUBLIC)){
- user.setShareType(AFTConstants.SHARE_TYPE_PUBLIC);
- }else if(operatorType.equals(AFTConstants.USER_RECEIVE)){
- user.setAid(TokenManager.getAdminId());
- user.setShareType(AFTConstants.SHARE_TYPE_PRIVATE);
- }else if(operatorType.equals(AFTConstants.USER_DELETE)){
- user.setStatus(AFTConstants.USER_STATUS_CANCEL);
- }
- return userMapper.updateByPrimaryKeySelective(user);
- }
- }
|