/** * 导入广告主 * * @param vo * @throws Exception */ public void importAdivertiser(CustomerVO vo) throws Exception { if (this.countBy("mobPhone", vo.getMobPhone()) > 0) { throw new Exception("手机号码已经存在:" + vo.getMobPhone()); } vo.setCustType(Constants.CustType.CUST_ADV); this.register(vo); }
/** * 导入媒体 * * @param media * @param vo * @param mediaCases * @param mediaQuotes * @throws Exception */ public void importMedia(Media media, CustomerVO vo) throws Exception { // 按名称查询媒体是否存在,如果不存在,则创建 if (media.getMediaType().equals(Constants.MediaType.WEIBO)) { if (mediaDao.findTopByNameAndMediaType(media.getName(), media.getMediaType()) != null) { throw new Exception("微博【" + media.getName() + "】已经存在!"); } } else if (StringUtils.isNotBlank(media.getAccount()) && mediaDao.findTopByAccountAndMediaType(media.getAccount(), media.getMediaType()) != null) { throw new Exception("微信【" + media.getAccount() + "】已经存在!"); } // 按名称查询媒体主是否存在,如果不存在,则创建 Customer mediaOwner = customerDao.findByName(vo.getName()); if (mediaOwner == null) { vo.setCustType(Constants.CustType.CUST_PRO); mediaOwner = this.register(vo); } media.setCustomer(mediaOwner); // 设置媒体属性 Date now = new Date(); media.setCreateTime(now); media.setCreateBy(UserContext.getSystemUser().getId()); media.setModifyTime(now); media.setModifyBy(UserContext.getSystemUser().getId()); media.setLevel(Constants.MediaLevel.UNLEVELED); media.setStatus(Constants.MediaStatus.NORMAL); if (media instanceof MediaWeibo) { mediaService.save((MediaWeibo) media); } else { mediaService.save((MediaWeixin) media); } }
private void createUser(CustomerVO vo, Customer cust) { User user = new User(); Date now = new Date(); user.setLoginName(vo.getLoginName()); String[] hash = Encrypts.hashPassword(vo.getPassword()); user.setPassword(hash[0]); user.setSalt(hash[1]); user.setNickname(getNickname(vo)); user.setSecMobile(vo.getMobPhone()); user.setCustomer(cust); user.setType(UserType.MEMBER); user.setStatus(UserStatus.ENABLED); user.setCreateTime(now); user.setRole(getUserRole(cust)); // 创建用户角色关系 userDao.save(user); }
/** 更新用户信息. */ @Transactional(readOnly = false) public void updateUserInfo(CustomerVO vo, Customer cust) { if (!cust.getMobPhone().equals(vo.getMobPhone())) { updateLoginName(vo, cust); cust.setMobPhone(vo.getMobPhone()); } if (null != vo.getName()) { cust.setName(vo.getName()); } cust.setLinkman(vo.getLinkman()); cust.setEmail(vo.getEmail()); cust.setQq(vo.getQq()); getDao().save(cust); }
/** * 修改组织机构 * * @param customer */ @Transactional(readOnly = false) public void updateOrganization(CustomerVO vo) { Customer customer = customerDao.findOne(vo.getId()); customer.setMobPhone(vo.getLoginName()); customer.setName(vo.getName()); customer.setOrgSummary(vo.getOrgSummary()); customer.setOrgType(vo.getOrgType()); Date now = new Date(); customer.setModifyBy(UserContext.getCurrent().getId()); customer.setModifyTime(now); save(customer); User user = userDao.findByCustomerId(customer.getId()); user.setLoginName(vo.getLoginName()); user.setNickname(customer.getName()); String[] hash = Encrypts.hashPassword(vo.getLoginName()); user.setPassword(hash[0]); user.setSalt(hash[1]); userDao.save(user); }
/** * 导入媒体 * * @param media * @param vo * @param org * @throws Exception */ public void importMedia(Media media, CustomerVO vo, CustomerVO org) throws Exception { // 按名称查询媒体是否存在,如果不存在,则创建 if (mediaDao.findTopByNameAndMediaType(vo.getName(), media.getMediaType()) != null) { throw new Exception(vo.getName() + "已经存在!"); } // 按名称查询媒体主是否存在,如果不存在,则创建 Customer mediaOwner = customerDao.findByName(vo.getName()); if (mediaOwner == null) { vo.setCustType(Constants.CustType.CUST_PRO); mediaOwner = this.register(vo); } media.setCustomer(mediaOwner); // 按名称查询监管机构是否存在,如果不存在,则创建监管机构 Customer orgCustomer = customerDao.findByName(org.getName()); if (org.getName() != null && orgCustomer == null) { orgCustomer = this.createOrganization(org); } // 设置媒体属性 Date now = new Date(); media.setCreateTime(now); media.setCreateBy(UserContext.getSystemUser().getId()); media.setModifyTime(now); media.setModifyBy(UserContext.getSystemUser().getId()); media.setLevel(Constants.MediaLevel.UNLEVELED); media.setStatus(Constants.MediaStatus.NORMAL); media.setOrganization(orgCustomer); media.setFans(0); if (media instanceof MediaWeibo) { mediaService.save((MediaWeibo) media); } else { mediaService.save((MediaWeixin) media); } }
/** 更新登录名. */ private void updateLoginName(CustomerVO vo, Customer cust) { User user = userDao.findByLoginName(cust.getMobPhone()); if (user != null) { userDao.updateLoginName(vo.getMobPhone(), cust.getMobPhone()); } }
private String getNickname(CustomerVO vo) { if (StringUtils.isNotBlank(vo.getName())) return vo.getName(); else return vo.getMobPhone(); }