Commit e2274c43 authored by renjie's avatar renjie

企业认证

子用户密码显示
parent aa06e733
package com.edgec.browserbackend.account.controller; package com.edgec.browserbackend.account.controller;
import com.edgec.browserbackend.account.domain.*; import com.edgec.browserbackend.account.domain.*;
import com.edgec.browserbackend.account.dto.MobileDto; import com.edgec.browserbackend.account.dto.*;
import com.edgec.browserbackend.account.dto.ResultDto; import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.account.dto.BillQueryCriteriaDto;
import com.edgec.browserbackend.account.dto.UserPrePaidBillingRequestDto;
import com.edgec.browserbackend.common.auth.Securitys; import com.edgec.browserbackend.common.auth.Securitys;
import com.edgec.browserbackend.common.commons.error.ClientRequestException; import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import com.edgec.browserbackend.common.commons.utils.DateConverter; import com.edgec.browserbackend.common.commons.utils.DateConverter;
...@@ -21,6 +19,7 @@ import org.springframework.data.domain.PageRequest; ...@@ -21,6 +19,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
...@@ -397,4 +396,47 @@ public class AccountController { ...@@ -397,4 +396,47 @@ public class AccountController {
return accountService.deletePreOrder(username); return accountService.deletePreOrder(username);
} }
@RequestMapping(path = "/authorize", method = RequestMethod.POST)
public ResultDto companyAuthorize(Principal principal,
@RequestParam(value = "type", defaultValue = "0") int type,
@RequestParam(value = "companyName") String companyName,
@RequestParam(value = "registerNumber") String registerNumber,
@RequestParam(value = "companyLicense") MultipartFile companyLicense,
@RequestParam(value = "coporationPlace") String coporationPlace,
@RequestParam(value = "coporationLicense") MultipartFile coporationLicense,
@RequestParam(value = "realController", defaultValue = "0") int realController,
@RequestParam(value = "writePerson", defaultValue = "0") int writePerson,
@RequestParam(value = "agency", required = false) MultipartFile agency) {
ResultDto resultDto = new ResultDto();
try {
CompanyAuthorizeDto companyAuthorizeDto = new CompanyAuthorizeDto();
companyAuthorizeDto.setUsername(principal.getName());
companyAuthorizeDto.setType(type);
companyAuthorizeDto.setCompanyName(companyName);
companyAuthorizeDto.setRegisterNumber(registerNumber);
if (companyLicense == null)
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
companyAuthorizeDto.setCompanyLicense(companyLicense);
companyAuthorizeDto.setCoporationPlace(coporationPlace);
if (coporationLicense == null)
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
companyAuthorizeDto.setCoporationLicense(coporationLicense);
companyAuthorizeDto.setRealController(realController);
companyAuthorizeDto.setWritePerson(writePerson);
if (agency != null)
companyAuthorizeDto.setAgency(agency);
if (writePerson == 1 && agency == null)
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
accountService.authorizeCompany(principal.getName(), companyAuthorizeDto);
resultDto.setStatus(0);
}catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
}
} }
...@@ -19,6 +19,9 @@ public class Account { ...@@ -19,6 +19,9 @@ public class Account {
private String parent; private String parent;
//子用户使用
private String password;
private Date lastSeen; private Date lastSeen;
private Date signupDate = new Date(); private Date signupDate = new Date();
...@@ -264,4 +267,12 @@ public class Account { ...@@ -264,4 +267,12 @@ public class Account {
public void setAuthorized(int authorized) { public void setAuthorized(int authorized) {
this.authorized = authorized; this.authorized = authorized;
} }
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
} }
package com.edgec.browserbackend.account.domain; package com.edgec.browserbackend.account.domain;
import com.edgec.browserbackend.account.dto.CompanyAuthorizeDto;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
...@@ -7,9 +8,120 @@ import org.springframework.data.mongodb.core.mapping.Document; ...@@ -7,9 +8,120 @@ import org.springframework.data.mongodb.core.mapping.Document;
public class CompanyAuthorize { public class CompanyAuthorize {
@Id @Id
private String id; private String id;
private String username;
private int type; //0 -- 企业, 1 -- 个体工商户 private int type; //0 -- 企业, 1 -- 个体工商户
private String name; private String companyName;
private String signUpNumber; private String registerNumber;
private String licensePhotoId; private String companyLicenseId;
private String coporationPlace;
private String coporationLicenseId;
private int realController;//0 -- 法定代表人, 1 -- 非法定代表人
private int writePerson; //0 -- 法定代表人, 1 -- 代理人
private String agencyId;
public CompanyAuthorize() {
}
public CompanyAuthorize(CompanyAuthorizeDto companyAuthorizeDto) {
if (companyAuthorizeDto.getUsername() != null)
this.username = companyAuthorizeDto.getUsername();
this.type = companyAuthorizeDto.getType();
if (companyAuthorizeDto.getCompanyName() != null)
this.companyName = companyAuthorizeDto.getCompanyName();
if (companyAuthorizeDto.getRegisterNumber() != null)
this.registerNumber = companyAuthorizeDto.getRegisterNumber();
this.realController = companyAuthorizeDto.getRealController();
this.writePerson = companyAuthorizeDto.getWritePerson();
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public int getRealController() {
return realController;
}
public void setAgencyId(String agencyId) {
this.agencyId = agencyId;
}
public int getWritePerson() {
return writePerson;
}
public void setCoporationLicenseId(String coporationLicenseId) {
this.coporationLicenseId = coporationLicenseId;
}
public String getAgencyId() {
return agencyId;
}
public void setCoporationPlace(String coporationPlace) {
this.coporationPlace = coporationPlace;
}
public String getCoporationLicenseId() {
return coporationLicenseId;
}
public String getCompanyLicenseId() {
return companyLicenseId;
}
public String getCoporationPlace() {
return coporationPlace;
}
public void setRealController(int realController) {
this.realController = realController;
}
public void setCompanyLicenseId(String companyLicenseId) {
this.companyLicenseId = companyLicenseId;
}
public String getRegisterNumber() {
return registerNumber;
}
public void setRegisterNumber(String registerNumber) {
this.registerNumber = registerNumber;
}
public void setWritePerson(int writePerson) {
this.writePerson = writePerson;
}
} }
package com.edgec.browserbackend.account.dto;
import com.edgec.browserbackend.account.domain.CompanyAuthorize;
import org.springframework.data.annotation.Id;
import org.springframework.web.multipart.MultipartFile;
public class CompanyAuthorizeDto {
private String username;
private int type; //0 -- 企业, 1 -- 个体工商户
private String companyName;
private String registerNumber;
private MultipartFile companyLicense;
private String coporationPlace;
private MultipartFile coporationLicense;
private int realController;//0 -- 法定代表人, 1 -- 非法定代表人
private int writePerson; //0 -- 法定代表人, 1 -- 代理人
private MultipartFile agency;
public CompanyAuthorizeDto() {
}
public CompanyAuthorizeDto(CompanyAuthorize companyAuthorize) {
if (companyAuthorize.getUsername() != null)
this.username = companyAuthorize.getUsername();
this.type = companyAuthorize.getType();
if (companyAuthorize.getCompanyName() != null)
this.companyName = companyAuthorize.getCompanyName();
if (companyAuthorize.getRegisterNumber() != null)
this.registerNumber = companyAuthorize.getRegisterNumber();
this.realController = companyAuthorize.getRealController();
this.writePerson = companyAuthorize.getWritePerson();
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getRegisterNumber() {
return registerNumber;
}
public void setWritePerson(int writePerson) {
this.writePerson = writePerson;
}
public void setRegisterNumber(String registerNumber) {
this.registerNumber = registerNumber;
}
public String getCoporationPlace() {
return coporationPlace;
}
public void setRealController(int realController) {
this.realController = realController;
}
public void setCoporationPlace(String coporationPlace) {
this.coporationPlace = coporationPlace;
}
public int getWritePerson() {
return writePerson;
}
public int getRealController() {
return realController;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public MultipartFile getAgency() {
return agency;
}
public void setAgency(MultipartFile agency) {
this.agency = agency;
}
public MultipartFile getCoporationLicense() {
return coporationLicense;
}
public void setCoporationLicense(MultipartFile coporationLicense) {
this.coporationLicense = coporationLicense;
}
public MultipartFile getCompanyLicense() {
return companyLicense;
}
public void setCompanyLicense(MultipartFile companyLicense) {
this.companyLicense = companyLicense;
}
}
...@@ -19,7 +19,8 @@ public class SubUsersDto { ...@@ -19,7 +19,8 @@ public class SubUsersDto {
this.nickname = account.getNickname(); this.nickname = account.getNickname();
this.username = account.getName(); this.username = account.getName();
this.comment = account.getComment(); this.comment = account.getComment();
this.passoword = password; if (password != null)
this.passoword = password;
} }
public String getComment() { public String getComment() {
......
package com.edgec.browserbackend.account.repository;
import com.edgec.browserbackend.account.domain.CompanyAuthorize;
import com.edgec.browserbackend.account.dto.CompanyAuthorizeDto;
import org.springframework.data.mongodb.repository.MongoRepository;
public interface CompanyAuthorizeRepository extends MongoRepository<CompanyAuthorize, String>, CompanyAuthorizeRepositoryCustom {
}
package com.edgec.browserbackend.account.repository;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
public interface CompanyAuthorizeRepositoryCustom {
String saveFile(String collectionName, MultipartFile file, String filename);
}
package com.edgec.browserbackend.account.repository;
import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import com.mongodb.DB;
import com.mongodb.client.gridfs.GridFSBucket;
import com.mongodb.gridfs.GridFS;
import com.mongodb.gridfs.GridFSInputFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.gridfs.GridFsOperations;
import org.springframework.data.mongodb.gridfs.GridFsTemplate;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.InputStream;
public class CompanyAuthorizeRepositoryCustomImpl implements CompanyAuthorizeRepositoryCustom {
private final Logger logger = LoggerFactory.getLogger(CompanyAuthorizeRepositoryCustomImpl.class);
@Autowired
private GridFsTemplate gridFsTemplate;
@Autowired
private GridFsOperations operations;
@Autowired
private GridFSBucket gridFSBucket;
@Autowired
private MongoTemplate mongoTemplate;
@Override
public String saveFile(String collectionName, MultipartFile file, String filename) {
try {
GridFS gridFS = new GridFS((DB) mongoTemplate.getDb());
InputStream in = file.getInputStream();
GridFSInputFile gridFSInputFile = gridFS.createFile(in);
gridFSInputFile.setFilename(filename);
gridFSInputFile.setContentType(file.getContentType());
gridFSInputFile.save();
return (String) gridFSInputFile.getId();
} catch (Exception e) {
logger.error("存储文件时发生错误!!!", e);
throw new ClientRequestException(BrowserErrorCode.UNKNOWN);
}
}
}
...@@ -100,4 +100,6 @@ public interface AccountService { ...@@ -100,4 +100,6 @@ public interface AccountService {
void updateUserToken(String username, String token); void updateUserToken(String username, String token);
void authorizeCompany(String username, CompanyAuthorizeDto companyAuthorizeDto);
} }
...@@ -22,6 +22,12 @@ import com.edgec.browserbackend.browser.service.IpResourceService; ...@@ -22,6 +22,12 @@ import com.edgec.browserbackend.browser.service.IpResourceService;
import com.edgec.browserbackend.browser.service.ShopService; import com.edgec.browserbackend.browser.service.ShopService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException; import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import com.edgec.browserbackend.common.commons.utils.CommonStringUtils; import com.edgec.browserbackend.common.commons.utils.CommonStringUtils;
import com.mongodb.DB;
import com.mongodb.client.gridfs.GridFSBucket;
import com.mongodb.client.gridfs.GridFSDownloadStream;
import com.mongodb.client.gridfs.model.GridFSFile;
import com.mongodb.gridfs.GridFS;
import com.mongodb.gridfs.GridFSInputFile;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -30,12 +36,19 @@ import org.springframework.data.domain.Page; ...@@ -30,12 +36,19 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.gridfs.GridFsOperations;
import org.springframework.data.mongodb.gridfs.GridFsResource;
import org.springframework.data.mongodb.gridfs.GridFsTemplate;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.thymeleaf.util.StringUtils; import org.thymeleaf.util.StringUtils;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.Instant; import java.time.Instant;
import java.time.YearMonth; import java.time.YearMonth;
...@@ -46,6 +59,9 @@ import java.util.concurrent.CompletableFuture; ...@@ -46,6 +59,9 @@ import java.util.concurrent.CompletableFuture;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.springframework.data.mongodb.core.query.Query.query;
import static org.springframework.data.mongodb.gridfs.GridFsCriteria.whereFilename;
@Service @Service
@Transactional @Transactional
@ComponentScan("com.edgec.browserbackend.account.repository") @ComponentScan("com.edgec.browserbackend.account.repository")
...@@ -97,6 +113,9 @@ public class AccountServiceImpl implements AccountService { ...@@ -97,6 +113,9 @@ public class AccountServiceImpl implements AccountService {
@Autowired @Autowired
private WhiteSiteRepository whiteSiteRepository; private WhiteSiteRepository whiteSiteRepository;
@Autowired
private CompanyAuthorizeRepository companyAuthorizeRepository;
@Override @Override
public List<UserBillList> getUserBills0(String name) { public List<UserBillList> getUserBills0(String name) {
...@@ -555,8 +574,7 @@ public class AccountServiceImpl implements AccountService { ...@@ -555,8 +574,7 @@ public class AccountServiceImpl implements AccountService {
List<SubUsersDto> subUsersDtoList = new ArrayList<>(); List<SubUsersDto> subUsersDtoList = new ArrayList<>();
accounts.getContent().forEach(x -> { accounts.getContent().forEach(x -> {
com.edgec.browserbackend.auth.domain.User user = userRepository.findById(x.getName()).orElse(null); subUsersDtoList.add(new SubUsersDto(x, x.getPassword()));
subUsersDtoList.add(new SubUsersDto(x, user.getPassword()));
}); });
subUserPageResultDto.setUserList(subUsersDtoList); subUserPageResultDto.setUserList(subUsersDtoList);
...@@ -686,6 +704,10 @@ public class AccountServiceImpl implements AccountService { ...@@ -686,6 +704,10 @@ public class AccountServiceImpl implements AccountService {
if (user.getWhiteList() != null && user.getWhiteList().size() > 0) if (user.getWhiteList() != null && user.getWhiteList().size() > 0)
whiteList.addAll(user.getWhiteList()); whiteList.addAll(user.getWhiteList());
account.setWhiteList(whiteList); account.setWhiteList(whiteList);
if (org.apache.commons.lang3.StringUtils.isNotBlank(subUsersRequestDto.getPassword()))
account.setPassword(subUsersRequestDto.getPassword());
else
account.setPassword(makeRandomPassword(8));
repository.save(account); repository.save(account);
// emailService.sendEmailVerification(user.getUsername(), user.getEmail(), user.getVerificationCode()); // emailService.sendEmailVerification(user.getUsername(), user.getEmail(), user.getVerificationCode());
...@@ -739,6 +761,10 @@ public class AccountServiceImpl implements AccountService { ...@@ -739,6 +761,10 @@ public class AccountServiceImpl implements AccountService {
if (subUsersRequestDto.getWhiteList() != null && subUsersRequestDto.getWhiteList().size() > 0) if (subUsersRequestDto.getWhiteList() != null && subUsersRequestDto.getWhiteList().size() > 0)
whiteList.addAll(subUsersRequestDto.getWhiteList()); whiteList.addAll(subUsersRequestDto.getWhiteList());
childAccount.setWhiteList(whiteList); childAccount.setWhiteList(whiteList);
if (org.apache.commons.lang3.StringUtils.isNotBlank(subUsersRequestDto.getPassword()))
childAccount.setPassword(subUsersRequestDto.getPassword());
else
childAccount.setPassword(makeRandomPassword(8));
repository.save(childAccount); repository.save(childAccount);
} }
...@@ -981,4 +1007,27 @@ public class AccountServiceImpl implements AccountService { ...@@ -981,4 +1007,27 @@ public class AccountServiceImpl implements AccountService {
repository.save(byName); repository.save(byName);
} }
@Override
public void authorizeCompany(String username, CompanyAuthorizeDto companyAuthorizeDto) {
Account account = repository.findByName(username);
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
String companyLicenseName = "companyLicense-" + username;
String companyLicenseId = companyAuthorizeRepository.saveFile("companylicense", companyAuthorizeDto.getCompanyLicense(), companyLicenseName);
String coporationLicenseName = "coporationLicense-" + username;
String coporationLicenseId = companyAuthorizeRepository.saveFile("coporationlicense", companyAuthorizeDto.getCoporationLicense(), companyLicenseName);
String agencyId = null;
if (companyAuthorizeDto.getAgency() != null) {
String agencyName = "agencyLicense-" + username;
agencyId = companyAuthorizeRepository.saveFile("coporationlicense", companyAuthorizeDto.getAgency(), agencyName);
}
CompanyAuthorize companyAuthorize = new CompanyAuthorize(companyAuthorizeDto);
companyAuthorize.setUsername(username);
companyAuthorize.setCompanyLicenseId(companyLicenseId);
companyAuthorize.setCoporationLicenseId(coporationLicenseId);
if (agencyId != null)
companyAuthorize.setAgencyId(agencyId);
companyAuthorizeRepository.save(companyAuthorize);
}
} }
...@@ -17,6 +17,7 @@ import com.edgec.browserbackend.common.commons.error.ClientRequestException; ...@@ -17,6 +17,7 @@ import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import com.edgec.browserbackend.common.utils.FileUtil; import com.edgec.browserbackend.common.utils.FileUtil;
import com.edgec.browserbackend.common.utils.PollerUtils; import com.edgec.browserbackend.common.utils.PollerUtils;
import com.edgec.browserbackend.common.utils.ThreadPoolUtils; import com.edgec.browserbackend.common.utils.ThreadPoolUtils;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -170,6 +171,8 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -170,6 +171,8 @@ public class IpResourceServiceImpl implements IpResourceService {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION); throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
Map<String, List<String>> priceList = ipOptionsRepository.findAll().get(0).getIpPlatForm(); Map<String, List<String>> priceList = ipOptionsRepository.findAll().get(0).getIpPlatForm();
if (ipResourceRequestDto.getRegion() == null)
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
if (ipResourceRequestDto.getRegionCn() == null) if (ipResourceRequestDto.getRegionCn() == null)
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE); throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
List<String> vendorPrices = priceList.get(ipResourceRequestDto.getRegionCn()); List<String> vendorPrices = priceList.get(ipResourceRequestDto.getRegionCn());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment