浏览代码

教师新增时自动创建账户

chenw 6 年之前
父节点
当前提交
839ed77414

+ 5 - 0
applications/school/school-server/pom.xml

@@ -118,6 +118,11 @@
         <artifactId>auth-dto</artifactId>
         <version>1.0.0-SNAPSHOT</version>
       </dependency>
+      <dependency>
+        <groupId>com.usoftchina.smartschool</groupId>
+        <artifactId>account-api</artifactId>
+        <version>1.0.0-SNAPSHOT</version>
+      </dependency>
     </dependencies>
 
     <build>

+ 19 - 2
applications/school/school-server/src/main/java/com/usoftchina/smartschool/school/basic/service/impl/TeacherServiceImpl.java

@@ -3,6 +3,8 @@ package com.usoftchina.smartschool.school.basic.service.impl;
 import com.alibaba.fastjson.JSONObject;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.usoftchina.smartschool.account.api.AccountApi;
+import com.usoftchina.smartschool.account.dto.AccountRegDTO;
 import com.usoftchina.smartschool.context.BaseContextHolder;
 import com.usoftchina.smartschool.exception.BizException;
 import com.usoftchina.smartschool.page.PageRequest;
@@ -33,9 +35,10 @@ public class TeacherServiceImpl implements TeacherService{
 
     @Autowired
     private SysTeacherMapper sysTeacherMapper;
-
     @Autowired
     private DataImportMapper dataImportMapper;
+    @Autowired
+    private AccountApi accountApi;
 
     @Override
     public PageInfo<SysTeacher> getListData(PageRequest page, ListReqDTO listReqDTO) {
@@ -75,7 +78,9 @@ public class TeacherServiceImpl implements TeacherService{
         //新增教师
         if (StringUtils.isEmpty(formdata.getTeacher_id()) || "0".equals(formdata.getTeacher_id().toString())) {
             sysTeacherMapper.insertSelective(formdata);
-
+            if (!StringUtils.isEmpty(formdata.getTeacher_phone())) {
+                createAccount(formdata);
+            }
         } else {
             //更新教师
             sysTeacherMapper.updateByPrimaryKeySelective(formdata);
@@ -83,6 +88,18 @@ public class TeacherServiceImpl implements TeacherService{
         return new DocBaseDTO(formdata.getTeacher_id(), null, null);
     }
 
+    /**
+     * 新建账户信息
+     */
+    private void createAccount(SysTeacher sysTeacher) {
+        AccountRegDTO accountRegDTO = new AccountRegDTO();
+        accountRegDTO.setUser_phone(sysTeacher.getTeacher_phone());
+        accountRegDTO.setUser_pass("111111");
+        Long roleId = sysTeacherMapper.selectRoleId();
+        accountRegDTO.setRoleId(roleId);
+        accountApi.register(accountRegDTO);
+    }
+
     @Override
     @Transactional
     public void saveToFormal(Integer id, boolean update) {

+ 6 - 0
applications/school/school-server/src/main/java/com/usoftchina/smartschool/school/mapper/SysTeacherMapper.java

@@ -32,4 +32,10 @@ public interface SysTeacherMapper {
     void deleteRelation(Long id);
 
     List<SysTeacher> selectByTeacher(@Param("condition") String condition, @Param("school_id") Long schoolId);
+
+    /**
+     * 查询角色为"教师"的roleId
+     * @return
+     */
+    Long selectRoleId();
 }

+ 3 - 0
applications/school/school-server/src/main/resources/mapper/SysTeacherMapper.xml

@@ -372,4 +372,7 @@ where sys_teacher_clazz.teacher_id=#{id}
       </if>
     </where>
   </select>
+  <select id="selectRoleId" resultType="long">
+    SELECT ROLE_ID FROM SYS_ROLE WHERE ROLE_NAME = '教师'
+  </select>
 </mapper>

+ 6 - 0
base-servers/account/account-api/src/main/java/com/usoftchina/smartschool/account/api/AccountApi.java

@@ -1,9 +1,11 @@
 package com.usoftchina.smartschool.account.api;
 
 import com.usoftchina.smartschool.account.dto.AccountDTO;
+import com.usoftchina.smartschool.account.dto.AccountRegDTO;
 import com.usoftchina.smartschool.base.Result;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestParam;
 
 /**
@@ -21,4 +23,8 @@ public interface AccountApi {
 
     @GetMapping("/account/getUsername")
     Result<String> getUsername(@RequestParam(value = "schoolId") Long schoolId, @RequestParam(value = "userId") Long userId);
+
+    @GetMapping("/account/register")
+    Result<String> register(@RequestBody AccountRegDTO accountRegDTO);
+
 }