|  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.scheduling.annotation.Async; | 
|---|
|  |  |  | import org.springframework.stereotype.Indexed; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.util.CollectionUtils; | 
|---|
|  |  |  | 
|---|
|  |  |  | private boolean debugModel; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CompanyMapper companyMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CompanyDepartmentMapper companyDepartmentMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SystemUserMapper systemUserMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | 
|---|
|  |  |  | companyMapper.insert(company); | 
|---|
|  |  |  | company.setEditDate(company.getCreateDate()); | 
|---|
|  |  |  | company.setEditor(user.getId()); | 
|---|
|  |  |  | //新建默认组织 | 
|---|
|  |  |  | CompanyDepartment department = createDefaultDepart(company); | 
|---|
|  |  |  | //处理登陆账号信息 | 
|---|
|  |  |  | dealSystemUserData(company); | 
|---|
|  |  |  | SystemUser sysuser = dealSystemUserData(company,department.getId()); | 
|---|
|  |  |  | //处理附件信息 | 
|---|
|  |  |  | dealFileData(company); | 
|---|
|  |  |  | //处理关联方案 | 
|---|
|  |  |  | dealSolutionsData(company); | 
|---|
|  |  |  | return company; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private CompanyDepartment createDefaultDepart(Company company) { | 
|---|
|  |  |  | CompanyDepartment depart = new CompanyDepartment(); | 
|---|
|  |  |  | depart.setCompanyId(company.getId()); | 
|---|
|  |  |  | depart.setCreator(company.getCreator()); | 
|---|
|  |  |  | depart.setCreateDate(company.getCreateDate()); | 
|---|
|  |  |  | depart.setType(Constants.equalsInteger(company.getType(),Constants.ZERO)?Constants.ONE:Constants.TWO); | 
|---|
|  |  |  | depart.setName(company.getName()); | 
|---|
|  |  |  | depart.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | depart.setNamePath(company.getName()); | 
|---|
|  |  |  | depart.setStatus(Constants.ZERO); | 
|---|
|  |  |  | depart.setRemark("默认根组织"); | 
|---|
|  |  |  | companyDepartmentMapper.insert(depart); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | depart.setIdPath(company.getId()+"/"); | 
|---|
|  |  |  | companyDepartmentMapper.updateById(depart);//更新路径 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return depart; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public Company createShop(Company company) { | 
|---|
|  |  |  | 
|---|
|  |  |  | company.setSignStatus(Constants.ZERO); | 
|---|
|  |  |  | company.setSignIdStatus(Constants.ZERO); | 
|---|
|  |  |  | companyMapper.insert(company); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | company.setEditDate(company.getCreateDate()); | 
|---|
|  |  |  | company.setEditor(user.getId()); | 
|---|
|  |  |  | //处理登陆账号信息 | 
|---|
|  |  |  | dealSystemUserData(company); | 
|---|
|  |  |  | dealSystemUserData(company,createDefaultDepart(company).getId()); | 
|---|
|  |  |  | //处理附件信息 | 
|---|
|  |  |  | dealFileData(company); | 
|---|
|  |  |  | return company; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void  updateSolutions(Company company) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void dealSystemUserData(Company company) { | 
|---|
|  |  |  | private SystemUser dealSystemUserData(Company company, Integer departId) { | 
|---|
|  |  |  | if(systemUserMapper.selectCount(new QueryWrapper<SystemUser>().lambda() | 
|---|
|  |  |  | .eq(SystemUser::getDeleted,Boolean.TRUE) | 
|---|
|  |  |  | .eq(SystemUser::getUsername,company.getUsername()))>0){ | 
|---|
|  |  |  | 
|---|
|  |  |  | user.setRealname(company.getLegalName()); | 
|---|
|  |  |  | user.setMobile(company.getPhone()); | 
|---|
|  |  |  | user.setCreateUser(company.getCreator()); | 
|---|
|  |  |  | user.setDepartmentId(departId); | 
|---|
|  |  |  | user.setCreateTime(company.getCreateDate()); | 
|---|
|  |  |  | user.setStatus(Constants.ZERO); | 
|---|
|  |  |  | systemUserMapper.insert(user); | 
|---|
|  |  |  | return user; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | private void dealSystemUserDataForUpdate (Company company,String oldUserName) { | 
|---|
|  |  |  | if(systemUserMapper.selectCount(new QueryWrapper<SystemUser>().lambda() | 
|---|