| | |
| | | SysCompany add = Convert.convert(SysCompany.class, bo); |
| | | add.setCompanyStatus(1); |
| | | validEntityBeforeSave(add); |
| | | add.setCompanyStatus(0); |
| | | boolean save = this.save(add); |
| | | addCompanyUser(add, 0); |
| | | if (isAddUser(bo.getCompanyPhone())){ |
| | | addCompanyUser(add, 0); |
| | | } |
| | | return save; |
| | | } |
| | | |
| | |
| | | SysCompany update = Convert.convert(SysCompany.class, bo); |
| | | validEntityBeforeSave(update); |
| | | if (!old.getCompanyPhone().equals(update.getCompanyPhone())){ |
| | | boolean delUser = delCompanyUser(old.getCompanyId()); |
| | | if (!delUser) { |
| | | throw new BaseException("原企业用户清除失败,请联系管理员!"); |
| | | if (this.count(SysCompany::getCompanyPhone, old.getCompanyPhone())==1){ |
| | | boolean delUser = delCompanyUser(old.getCompanyPhone()); |
| | | if (!delUser) { |
| | | throw new BaseException("原企业用户清除失败,请联系管理员!"); |
| | | } |
| | | } |
| | | this.addCompanyUser(update, update.getCompanyStatus()==0 ? 1 : 0); |
| | | if (isAddUser(update.getCompanyPhone())){ |
| | | addCompanyUser(update, update.getCompanyStatus()==0 ? 1 : 0); |
| | | } |
| | | } |
| | | return this.updateById(update); |
| | | } |
| | |
| | | public Boolean deleteByIds(Collection<Long> ids) |
| | | { |
| | | for (Long id : ids) { |
| | | boolean b = delCompanyUser(id); |
| | | boolean b = delCompanyUser(this.getById(id).getCompanyPhone()); |
| | | if (!b) { |
| | | throw new BaseException(String.format("原企业 %1$s 用户清除失败,请联系管理员!", id)); |
| | | } |
| | |
| | | List<SysCompany> companies = Convert.toList(SysCompany.class, resultVo.getVoList()); |
| | | boolean b = this.saveOrUpdateBatch(companies); |
| | | for (SysCompany company : companies) { |
| | | addCompanyUser(company,1); |
| | | if (isAddUser(company.getCompanyPhone())){ |
| | | addCompanyUser(company,1); |
| | | } |
| | | } |
| | | return b; |
| | | } |
| | |
| | | private void validEntityBeforeSave(SysCompany entity) |
| | | { |
| | | entity.setIsImport(0); |
| | | |
| | | if (StringUtils.isEmpty(entity.getCompanyImg())){ |
| | | throw new BaseException(String.format("%1$s,请上传营业执照", entity.getCompanyName())); |
| | | } |
| | |
| | | if (nameCount>0){ |
| | | throw new BaseException(String.format("%1$s,企业名已存在!", entity.getCompanyName())); |
| | | } |
| | | int phoneCount = this.count(lq().eq(SysCompany::getCompanyPhone, entity.getCompanyPhone())); |
| | | if (phoneCount>0){ |
| | | throw new BaseException(String.format("%1$s,企业联系电话已存在!", entity.getCompanyName())); |
| | | } |
| | | SysUser user = new SysUser(); |
| | | user.setPhonenumber(entity.getCompanyPhone()); |
| | | if (UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) { |
| | | throw new BaseException(String.format("%1$s,企业联系电话已存在,请更换手机号!", entity.getCompanyName())); |
| | | } |
| | | } else { |
| | | int codeCount = this.count(lq().eq(SysCompany::getCompanyCode, entity.getCompanyCode()).ne(SysCompany::getCompanyId,entity.getCompanyId())); |
| | | if (codeCount>0){ |
| | |
| | | int nameCount = this.count(lq().eq(SysCompany::getCompanyName, entity.getCompanyName()).ne(SysCompany::getCompanyId,entity.getCompanyId())); |
| | | if (nameCount>0){ |
| | | throw new BaseException(String.format("%1$s,企业名已存在!", entity.getCompanyName())); |
| | | } |
| | | int phoneCount = this.count(lq().eq(SysCompany::getCompanyPhone, entity.getCompanyPhone()).ne(SysCompany::getCompanyId,entity.getCompanyId())); |
| | | if (phoneCount>0){ |
| | | throw new BaseException(String.format("%1$s,企业联系电话已存在!", entity.getCompanyName())); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | if (StringUtils.isEmpty(entity.getCompanyPhone())){ |
| | | errorList.add(new ImportError(3, "请填写企业联系人电话!")); |
| | | } else { |
| | | if (entity.getCompanyPhone().length()!=11){ |
| | | errorList.add(new ImportError(3, "请填写正确手机号!")); |
| | | } |
| | | } |
| | | if (StringUtils.isEmpty(entity.getCompanyAddress())){ |
| | | errorList.add(new ImportError(4, "请填写企业地址!")); |
| | |
| | | if (nameCount>0){ |
| | | errorList.add(new ImportError(0, "企业名已存在!")); |
| | | } |
| | | int phoneCount = this.count(lq().eq(SysCompany::getCompanyPhone, entity.getCompanyPhone())); |
| | | SysUser user = new SysUser(); |
| | | user.setPhonenumber(entity.getCompanyPhone()); |
| | | if (UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) { |
| | | errorList.add(new ImportError(3, "企业联系电话系统中已存在,请更换电话!")); |
| | | } |
| | | if (phoneCount>0){ |
| | | errorList.add(new ImportError(3, "企业联系电话已存在!")); |
| | | } |
| | | entity.setCheckStatus(2); |
| | | } |
| | | |
| | |
| | | * @param entity 企业信息 |
| | | */ |
| | | @Async |
| | | protected void addCompanyUser(SysCompany entity, Integer isImport) |
| | | @Override |
| | | public void addCompanyUser(SysCompany entity, Integer isImport) |
| | | { |
| | | |
| | | SysUser user = new SysUser(); |
| | |
| | | |
| | | /** |
| | | * 删除企业用户 |
| | | * @param companyId 企业id |
| | | * @param companyPhone 企业id |
| | | */ |
| | | protected boolean delCompanyUser(Long companyId) |
| | | protected boolean delCompanyUser(String companyPhone) |
| | | { |
| | | return userService.deleteUserByDeptId(companyId)>0; |
| | | return userService.deleteUserByCompanyPhone(companyPhone)>0; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | return qw; |
| | | } |
| | | |
| | | private Boolean isAddUser(String phone) |
| | | { |
| | | return userService.count(userService.lq().eq(SysUser::getUserName, phone).eq(SysUser::getDelFlag,0))==0; |
| | | } |
| | | } |