Forráskód Böngészése

增加对优软云账户中心的支持

yingp 7 éve
szülő
commit
036d701e74

+ 10 - 0
base-servers/account/account-api/src/main/java/com/usoftchina/saas/account/api/AccountApi.java

@@ -3,6 +3,7 @@ package com.usoftchina.saas.account.api;
 import com.usoftchina.saas.account.dto.AccountCopyDTO;
 import com.usoftchina.saas.account.dto.AccountDTO;
 import com.usoftchina.saas.account.dto.AccountRegDTO;
+import com.usoftchina.saas.account.dto.AccountUpdateDTO;
 import com.usoftchina.saas.base.Result;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.*;
@@ -68,4 +69,13 @@ public interface AccountApi {
      */
     @PostMapping("/account/register/copy")
     Result copyRegistration(@RequestBody AccountCopyDTO accountSyncDTO);
+
+    /**
+     * 修改
+     *
+     * @param accountUpdateDTO
+     * @return
+     */
+    @PostMapping("/update")
+    Result update(@RequestBody AccountUpdateDTO accountUpdateDTO);
 }

+ 13 - 0
base-servers/account/account-dto/src/main/java/com/usoftchina/saas/account/dto/AccountRegDTO.java

@@ -19,6 +19,10 @@ public class AccountRegDTO implements Serializable {
      * 账号类型 0 - 管理员
      */
     private Integer type;
+    /**
+     * 头像
+     */
+    private String avatarUrl;
     private Long companyId;
 
     public String getUsername() {
@@ -69,6 +73,14 @@ public class AccountRegDTO implements Serializable {
         this.type = type;
     }
 
+    public String getAvatarUrl() {
+        return avatarUrl;
+    }
+
+    public void setAvatarUrl(String avatarUrl) {
+        this.avatarUrl = avatarUrl;
+    }
+
     public Long getCompanyId() {
         return companyId;
     }
@@ -86,6 +98,7 @@ public class AccountRegDTO implements Serializable {
                 ", email='" + email + '\'' +
                 ", mobile='" + mobile + '\'' +
                 ", type=" + type +
+                ", avatarUrl='" + avatarUrl + '\'' +
                 ", companyId=" + companyId +
                 '}';
     }

+ 105 - 0
base-servers/account/account-dto/src/main/java/com/usoftchina/saas/account/dto/AccountUpdateDTO.java

@@ -0,0 +1,105 @@
+package com.usoftchina.saas.account.dto;
+
+import io.swagger.annotations.ApiModel;
+
+import java.io.Serializable;
+
+/**
+ * @author yingp
+ * @date 2018/10/2
+ */
+@ApiModel(value = "AccountSave", description = "账户信息修改")
+public class AccountUpdateDTO implements Serializable {
+    private Long id;
+    private String username;
+    private String realname;
+    private String email;
+    private String mobile;
+    /**
+     * 账号类型 0 - 管理员
+     */
+    private Integer type;
+    /**
+     * 头像
+     */
+    private String avatarUrl;
+    private Long uu;
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public String getRealname() {
+        return realname;
+    }
+
+    public void setRealname(String realname) {
+        this.realname = realname;
+    }
+
+    public String getEmail() {
+        return email;
+    }
+
+    public void setEmail(String email) {
+        this.email = email;
+    }
+
+    public String getMobile() {
+        return mobile;
+    }
+
+    public void setMobile(String mobile) {
+        this.mobile = mobile;
+    }
+
+    public Integer getType() {
+        return type;
+    }
+
+    public void setType(Integer type) {
+        this.type = type;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getAvatarUrl() {
+        return avatarUrl;
+    }
+
+    public void setAvatarUrl(String avatarUrl) {
+        this.avatarUrl = avatarUrl;
+    }
+
+    public Long getUu() {
+        return uu;
+    }
+
+    public void setUu(Long uu) {
+        this.uu = uu;
+    }
+
+    @Override
+    public String toString() {
+        return "AccountUpdateDTO{" +
+                "id=" + id +
+                ", username='" + username + '\'' +
+                ", realname='" + realname + '\'' +
+                ", email='" + email + '\'' +
+                ", mobile='" + mobile + '\'' +
+                ", type=" + type +
+                ", avatarUrl='" + avatarUrl + '\'' +
+                ", uu=" + uu +
+                '}';
+    }
+}

+ 46 - 5
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/controller/AccountController.java

@@ -1,9 +1,6 @@
 package com.usoftchina.saas.account.controller;
 
-import com.usoftchina.saas.account.dto.AccountDTO;
-import com.usoftchina.saas.account.dto.AccountRegDTO;
-import com.usoftchina.saas.account.dto.CompanyBaseDTO;
-import com.usoftchina.saas.account.dto.RoleBaseDTO;
+import com.usoftchina.saas.account.dto.*;
 import com.usoftchina.saas.account.po.Account;
 import com.usoftchina.saas.account.po.RoleResource;
 import com.usoftchina.saas.account.service.AccountService;
@@ -73,6 +70,50 @@ public class AccountController {
         return Result.success();
     }
 
+    /**
+     * 从其他平台复制已注册用户信息
+     * 区别于普通注册:密码已经是加密后的密文
+     *
+     * @param accountCopyDTO
+     * @return
+     */
+    @PostMapping("/register/copy")
+    @IgnoreAuth
+    public Result copyRegistration(@RequestBody AccountCopyDTO accountCopyDTO) {
+        // 判断是否已注册
+        Account account = accountService.findByUsername(accountCopyDTO.getUsername());
+        if (null != account) {
+            return Result.error(ExceptionCode.USER_NAME_EXIST);
+        }
+        account = accountService.findByMobile(accountCopyDTO.getMobile());
+        if (null != account) {
+            return Result.error(ExceptionCode.USER_MOBILE_EXIST);
+        }
+        account = accountService.findByEmail(accountCopyDTO.getEmail());
+        if (null != account) {
+            return Result.error(ExceptionCode.USER_EMAIL_EXIST);
+        }
+
+        account = BeanMapper.map(accountCopyDTO, Account.class);
+        account.setEnabled(true);
+        accountService.save(account);
+
+        return Result.success();
+    }
+
+    /**
+     * 修改
+     *
+     * @param accountUpdateDTO
+     * @return
+     */
+    @PostMapping("/update")
+    public Result update(@RequestBody AccountUpdateDTO accountUpdateDTO) {
+        Account account = BeanMapper.map(accountUpdateDTO, Account.class);
+        accountService.updateByPrimaryKeySelective(account);
+        return Result.success();
+    }
+
     /**
      * 校验用户和密码
      *
@@ -114,7 +155,7 @@ public class AccountController {
         }
 
         account.setPassword(accountService.getEncryptedPassword(password, account.getSalt()));
-        accountService.updateByPrimaryKey(account);
+        accountService.updateByPrimaryKeySelective(account);
         return Result.success();
     }
 

+ 25 - 0
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/controller/CompanyController.java

@@ -1,5 +1,6 @@
 package com.usoftchina.saas.account.controller;
 
+import com.usoftchina.saas.account.dto.CompanyCopyDTO;
 import com.usoftchina.saas.account.dto.CompanyDTO;
 import com.usoftchina.saas.account.dto.CompanyRegDTO;
 import com.usoftchina.saas.account.po.Company;
@@ -46,6 +47,30 @@ public class CompanyController {
         return Result.success();
     }
 
+    /**
+     * 从其他平台复制已注册企业信息
+     *
+     * @param companyCopyDTO
+     * @return
+     */
+    @PostMapping("/company/register/copy")
+    public Result copyRegistration(@RequestBody CompanyCopyDTO companyCopyDTO) {
+        // 判断是否已注册
+        Company company = companyService.findByName(companyCopyDTO.getName());
+        if (null != company) {
+            return Result.error(ExceptionCode.COMPANY_NAME_EXIST);
+        }
+        company = companyService.findByBusinessCode(companyCopyDTO.getBusinessCode());
+        if (null != company) {
+            return Result.error(ExceptionCode.COMPANY_CODE_EXIST);
+        }
+
+        company = BeanMapper.map(companyCopyDTO, Company.class);
+        companyService.save(company);
+
+        return Result.success();
+    }
+
     /**
      * 按名称查找
      *

+ 2 - 2
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/service/AccountService.java

@@ -20,12 +20,12 @@ public interface AccountService {
     boolean save(Account account);
 
     /**
-     * 更新
+     * 更新(非空字段)
      *
      * @param account
      * @return
      */
-    boolean updateByPrimaryKey(Account account);
+    boolean updateByPrimaryKeySelective(Account account);
 
     /**
      * 按用户名查找

+ 1 - 1
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/service/impl/AccountServiceImpl.java

@@ -53,7 +53,7 @@ public class AccountServiceImpl implements AccountService {
     }
 
     @Override
-    public boolean updateByPrimaryKey(Account account) {
+    public boolean updateByPrimaryKeySelective(Account account) {
         account.setUpdateTime(new Date());
         account.setUpdaterId(BaseContextHolder.getUserId());
         return accountMapper.updateByPrimaryKeySelective(account) > 0;

+ 14 - 3
base-servers/account/account-server/src/main/resources/mapper/AccountMapper.xml

@@ -10,6 +10,7 @@
         <result column="email" jdbcType="VARCHAR" property="email"/>
         <result column="mobile" jdbcType="VARCHAR" property="mobile"/>
         <result column="type" jdbcType="INTEGER" property="type"/>
+        <result column="uu" jdbcType="BIGINT" property="uu"/>
         <result column="enabled" jdbcType="BOOLEAN" property="enabled"/>
         <result column="creator_id" jdbcType="BIGINT" property="creatorId"/>
         <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
@@ -18,14 +19,14 @@
     </resultMap>
     <sql id="baseColumns">
         ac_account.id,ac_account.username,ac_account.password,ac_account.salt,ac_account.realname,ac_account.email,
-        ac_account.mobile,ac_account.type,ac_account.enabled,ac_account.creator_id,ac_account.create_time,
+        ac_account.mobile,ac_account.type,ac_account.uu,ac_account.enabled,ac_account.creator_id,ac_account.create_time,
         ac_account.updater_id,ac_account.update_time
     </sql>
     <insert id="insert" parameterType="com.usoftchina.saas.account.po.Account"
             useGeneratedKeys="true" keyProperty="id">
-        insert into ac_account(username,password,salt,realname,email,mobile,type,enabled,creator_id,create_time,updater_id,update_time)
+        insert into ac_account(username,password,salt,realname,email,mobile,type,uu,enabled,creator_id,create_time,updater_id,update_time)
         values (#{username,jdbcType=VARCHAR},#{password,jdbcType=VARCHAR}, #{salt,jdbcType=VARCHAR},
-        #{realname,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER}, #{enabled,jdbcType=BOOLEAN},
+        #{realname,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER}, #{uu,jdbcType=BIGINT}, #{enabled,jdbcType=BOOLEAN},
         #{creatorId,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}, #{updaterId,jdbcType=BIGINT}, #{updateTime,jdbcType=TIMESTAMP})
     </insert>
     <insert id="insertSelective" parameterType="com.usoftchina.saas.account.po.Account"
@@ -53,6 +54,9 @@
             <if test="type != null">
                 type,
             </if>
+            <if test="uu != null">
+                uu,
+            </if>
             <if test="enabled != null">
                 enabled,
             </if>
@@ -91,6 +95,9 @@
             <if test="type != null">
                 #{type,jdbcType=INTEGER},
             </if>
+            <if test="uu != null">
+                #{uu,jdbcType=BIGINT},
+            </if>
             <if test="enabled != null">
                 #{enabled,jdbcType=BOOLEAN},
             </if>
@@ -117,6 +124,7 @@
         email=#{email,jdbcType=VARCHAR},
         mobile=#{mobile,jdbcType=VARCHAR},
         type=#{type,jdbcType=INTEGER},
+        uu=#{uu,jdbcType=BIGINT},
         enabled=#{enabled,jdbcType=BOOLEAN},
         creator_id=#{creatorId,jdbcType=BIGINT},
         create_time=#{createTime,jdbcType=TIMESTAMP},
@@ -148,6 +156,9 @@
             <if test="type != null">
                 type=#{type,jdbcType=INTEGER},
             </if>
+            <if test="uu != null">
+                uu=#{uu,jdbcType=BIGINT},
+            </if>
             <if test="enabled != null">
                 enabled=#{enabled,jdbcType=BOOLEAN},
             </if>

+ 1 - 1
base-servers/account/account-server/src/main/resources/mapper/CompanyMapper.xml

@@ -19,7 +19,7 @@
         <result column="logo_url" jdbcType="VARCHAR" property="logoUrl"/>
     </resultMap>
     <sql id="baseColumns">
-        id,name,business_code,address,creator_id,create_time,updater_id,update_time
+        id,name,business_code,address,uu,creator_id,create_time,updater_id,update_time
     </sql>
     <insert id="insert" parameterType="com.usoftchina.saas.account.po.Company"
             useGeneratedKeys="true" keyProperty="id">

+ 6 - 0
base-servers/auth/auth-common/pom.xml

@@ -38,6 +38,12 @@
             <groupId>org.springframework.cloud</groupId>
             <artifactId>spring-cloud-starter-bus-amqp</artifactId>
         </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>javax.servlet-api</artifactId>
+            <scope>compile</scope>
+            <optional>true</optional>
+        </dependency>
     </dependencies>
 
 </project>

+ 64 - 0
base-servers/auth/auth-server/src/main/java/com/usoftchina/saas/auth/controller/AuthController.java

@@ -2,7 +2,11 @@ package com.usoftchina.saas.auth.controller;
 
 import com.github.pagehelper.PageInfo;
 import com.usoftchina.saas.account.api.AccountApi;
+import com.usoftchina.saas.account.constant.AccountType;
+import com.usoftchina.saas.account.dto.AccountCopyDTO;
 import com.usoftchina.saas.account.dto.AccountDTO;
+import com.usoftchina.saas.account.dto.AccountUpdateDTO;
+import com.usoftchina.saas.auth.common.cookie.CookieInfo;
 import com.usoftchina.saas.auth.common.jwt.JwtHelper;
 import com.usoftchina.saas.auth.common.jwt.JwtInfo;
 import com.usoftchina.saas.auth.common.jwt.JwtToken;
@@ -13,6 +17,7 @@ import com.usoftchina.saas.auth.po.AuthorizeLog;
 import com.usoftchina.saas.auth.service.AuthorizeCountService;
 import com.usoftchina.saas.auth.service.AuthorizeLogService;
 import com.usoftchina.saas.base.Result;
+import com.usoftchina.saas.exception.BizException;
 import com.usoftchina.saas.exception.ExceptionCode;
 import com.usoftchina.saas.page.PageDefault;
 import com.usoftchina.saas.page.PageRequest;
@@ -99,6 +104,65 @@ public class AuthController {
         return Result.error(result.getCode(), result.getMessage());
     }
 
+    /**
+     * 账户中心登录回调
+     *
+     * @param info
+     * @return
+     */
+    @PostMapping("/sso/callback")
+    public Result ssoCallback(CookieInfo info) {
+        if (null != info && null != info.getMobile()) {
+            Result<AccountDTO> result = accountApi.getAccount(info.getMobile());
+            if (!result.isSuccess()) {
+                if (ExceptionCode.USER_NOT_EXIST.getCode() == result.getCode()) {
+                    // 新用户,自动注册
+                    createAccountByCookieInfo(info);
+                } else {
+                    return Result.error(result.getCode(), result.getMessage());
+                }
+            } else {
+                AccountDTO accountDTO = result.getData();
+                // 检测uu是否正确
+                if (null == accountDTO.getUu() || !info.getUserUU().equals(accountDTO.getUu())) {
+                    accountDTO.setUu(info.getUserUU());
+                    Result updateResult = accountApi.update(BeanMapper.map(accountDTO, AccountUpdateDTO.class));
+                    if (!updateResult.isSuccess()) {
+                        return Result.error(updateResult.getCode(), updateResult.getMessage());
+                    }
+                }
+            }
+            return Result.success();
+        }
+        return Result.error(ExceptionCode.COOKIE_ILLEGAL_ARGUMENT);
+    }
+
+    /**
+     * 如果在本平台不存在,就自动创建
+     *
+     * @param info
+     */
+    private AccountDTO createAccountByCookieInfo(CookieInfo info) {
+        AccountCopyDTO copyDTO = new AccountCopyDTO();
+        copyDTO.setUsername(info.getMobile());
+        copyDTO.setPassword(info.getPassword());
+        copyDTO.setSalt(info.getSalt());
+        copyDTO.setEmail(info.getEmail());
+        copyDTO.setMobile(info.getMobile());
+        copyDTO.setRealname(info.getVipName());
+        copyDTO.setType(AccountType.ADMIN.getType());
+        copyDTO.setUu(info.getUserUU());
+        Result result = accountApi.copyRegistration(copyDTO);
+        if (!result.isSuccess()) {
+            throw new BizException(result.getCode(), result.getMessage());
+        }
+        Result<AccountDTO> accountDTOResult = accountApi.getAccountByUu(info.getUserUU());
+        if (!accountDTOResult.isSuccess()) {
+            throw new BizException(accountDTOResult.getCode(), accountDTOResult.getMessage());
+        }
+        return accountDTOResult.getData();
+    }
+
     /**
      * 切换公司
      *