zouxuan il y a 5 ans
Parent
commit
84ae8b09b9

+ 8 - 0
mec-auth/mec-auth-api/src/main/java/com/ym/mec/auth/api/client/SysUserFeignService.java

@@ -8,6 +8,8 @@ import com.ym.mec.auth.api.client.fallback.SysUserFeignServiceFallback;
 import com.ym.mec.auth.api.dto.SysUserInfo;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.common.config.FeignConfiguration;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestParam;
 
 @FeignClient(name = "auth-server", configuration = FeignConfiguration.class, fallback = SysUserFeignServiceFallback.class)
 public interface SysUserFeignService {
@@ -15,6 +17,12 @@ public interface SysUserFeignService {
 	@GetMapping(value = "query/{username}")
 	public SysUserInfo getUser(@PathVariable("username") String username);
 
+	@GetMapping(value = "user/queryUserByPhone")
+	public SysUser getUserByMobile(@RequestParam("mobile") String mobile);
+
+	@GetMapping(value = "user/add")
+	public Object addUser(@RequestBody SysUser user);
+
 	@GetMapping(value = "task/test")
 	public Object test();
 

+ 10 - 0
mec-auth/mec-auth-api/src/main/java/com/ym/mec/auth/api/client/fallback/SysUserFeignServiceFallback.java

@@ -5,6 +5,7 @@ import org.springframework.stereotype.Component;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.dto.SysUserInfo;
 import com.ym.mec.auth.api.entity.SysUser;
+import org.springframework.web.bind.annotation.RequestBody;
 
 @Component
 public class SysUserFeignServiceFallback implements SysUserFeignService {
@@ -24,4 +25,13 @@ public class SysUserFeignServiceFallback implements SysUserFeignService {
 		return new SysUser();
 	}
 
+	@Override
+	public SysUser getUserByMobile(String mobile) {
+		return new SysUser();
+	}
+
+	public Object addUser(SysUser user){
+		return false;
+	}
+
 }

+ 1 - 1
mec-auth/mec-auth-api/src/main/java/com/ym/mec/auth/api/dto/MenuQueryInfo.java

@@ -3,7 +3,7 @@ package com.ym.mec.auth.api.dto;
 import com.ym.mec.common.page.QueryInfo;
 import io.swagger.annotations.ApiModelProperty;
 
-public class MenuQueryInfo extends QueryInfo {
+public class MenuQueryInfo{
     @ApiModelProperty(value = "父节点编号,默认0",required = false)
     private Integer parentId = 0;
 

+ 0 - 3
mec-auth/mec-auth-api/src/main/java/com/ym/mec/auth/api/entity/SysUser.java

@@ -41,11 +41,9 @@ public class SysUser {
 	private Integer organId;
 
 	/** 创建时间 */
-//	@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
 	private java.util.Date createTime;
 
 	/** 修改时间 */
-//	@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
 	private java.util.Date updateTime;
 
 	/** 0-正常,9-锁定 */
@@ -74,7 +72,6 @@ public class SysUser {
 	@ApiModelProperty(value = "民族",required = false)
 	private String nation;
 
-//	@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
 	@ApiModelProperty(value = "生日",required = false)
 	private Date birthdate;
 

+ 6 - 7
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/dal/dao/SysMenuDao.java

@@ -41,17 +41,16 @@ public interface SysMenuDao extends BaseDAO<Integer, SysMenu> {
     List<SysMenu> findByParentId(@Param("parentId") Integer menuId,@Param("delFlag") String delFlag,@Param("userId") Integer userId);
 
     /**
-     * count所有菜单列表
-     * @param params
-     * @return
-     */
-    int findCountBySys(Map<String, Object> params);
-
-    /**
      * 获取所有菜单列表
      * @param menuId
      * @param delFlag
      * @return
      */
     List<SysMenu> findList(@Param("parentId") Integer menuId,@Param("delFlag") String delFlag);
+
+    /**
+     * 批量删除菜单列表
+     * @param collect
+     */
+    void batchDel(List<Integer> collect);
 }

+ 7 - 1
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/service/SysMenuService.java

@@ -21,7 +21,7 @@ public interface SysMenuService extends BaseService<Integer, SysMenu> {
      * @param menuQueryInfo
      * @return
      */
-    PageInfo<SysMenu> findByUser(MenuQueryInfo menuQueryInfo);
+    List<SysMenu> findByUser(MenuQueryInfo menuQueryInfo);
 
     /**
      * 根据权限标识查菜单
@@ -29,4 +29,10 @@ public interface SysMenuService extends BaseService<Integer, SysMenu> {
      * @return
      */
     SysMenu findMenuByPermission(String permission);
+
+    /**
+     * 删除菜单列表,包含所有子节点
+     * @param id
+     */
+    void recursiveDel(Integer id);
 }

+ 24 - 25
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/service/impl/SysMenuServiceImpl.java

@@ -4,6 +4,7 @@ import com.ym.mec.auth.api.dto.MenuQueryInfo;
 import com.ym.mec.auth.api.entity.SysMenu;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.auth.api.enums.SysUserType;
+import com.ym.mec.auth.api.enums.YesOrNoEnum;
 import com.ym.mec.auth.dal.dao.SysMenuDao;
 import com.ym.mec.auth.dal.dao.SysUserDao;
 import com.ym.mec.auth.service.SysMenuService;
@@ -18,6 +19,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 @Service
 public class SysMenuServiceImpl extends BaseServiceImpl<Integer, SysMenu>  implements SysMenuService {
@@ -38,37 +40,19 @@ public class SysMenuServiceImpl extends BaseServiceImpl<Integer, SysMenu>  imple
 	}
 
 	@Override
-	public PageInfo<SysMenu> findByUser(MenuQueryInfo menuQueryInfo) {
+	public List<SysMenu> findByUser(MenuQueryInfo menuQueryInfo) {
 		SysUser sysUser = sysUserDao.get(menuQueryInfo.getUserId());
-		PageInfo<SysMenu> pageInfo = null;
+		List<SysMenu> sysMenus = null;
 		if(sysUser.getUserType() == SysUserType.SYSTEM){
-			pageInfo = findBySys(menuQueryInfo);
+			menuQueryInfo.setUserId(null);
+			sysMenus = sysMenuDao.findList(menuQueryInfo.getParentId(),menuQueryInfo.getDelFlag());
 		}else {
-			pageInfo = queryPage(menuQueryInfo);
+			sysMenus = sysMenuDao.findByParentId(menuQueryInfo.getParentId(),menuQueryInfo.getDelFlag(),menuQueryInfo.getUserId());
 		}
-		for (SysMenu menu:pageInfo.getRows()) {
+		for (SysMenu menu:sysMenus) {
 			menu = getTree(menu,menuQueryInfo.getDelFlag(),menuQueryInfo.getUserId());
 		}
-		return pageInfo;
-	}
-
-	private PageInfo<SysMenu> findBySys(MenuQueryInfo menuQueryInfo){
-		PageInfo<SysMenu> pageInfo = new PageInfo<>(menuQueryInfo.getPage(), menuQueryInfo.getRows());
-		Map<String, Object> params = new HashMap<>();
-		MapUtil.populateMap(params, menuQueryInfo);
-
-		List<SysMenu> dataList = null;
-		int count = sysMenuDao.findCountBySys(params);
-		if (count > 0) {
-			pageInfo.setTotal(count);
-			params.put("offset", pageInfo.getOffset());
-			dataList = sysMenuDao.findList(menuQueryInfo.getParentId(),menuQueryInfo.getDelFlag());
-		}
-		if (count == 0) {
-			dataList = new ArrayList<>();
-		}
-		pageInfo.setRows(dataList);
-		return pageInfo;
+		return sysMenus;
 	}
 
 	private SysMenu getTree(SysMenu menu, String delFlag,Integer userId){
@@ -96,4 +80,19 @@ public class SysMenuServiceImpl extends BaseServiceImpl<Integer, SysMenu>  imple
 	public SysMenu findMenuByPermission(String permission){
 		return sysMenuDao.findMenuByPermission(permission);
 	}
+
+	@Override
+	public void recursiveDel(Integer parentId) {
+		List<SysMenu> sysMenus = sysMenuDao.findList(parentId, "0");
+		for (SysMenu menu:sysMenus) {
+			menu = getTree(menu,"0",null);
+		}
+		List<Integer> collect = sysMenus.stream().map(sysMenu -> sysMenu.getId()).collect(Collectors.toList());
+		if(collect == null || collect.size() <= 0){
+			sysMenuDao.delete(parentId);
+			return;
+		}
+		collect.add(parentId);
+		sysMenuDao.batchDel(collect);
+	}
 }

+ 2 - 1
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/web/controller/MenuController.java

@@ -35,7 +35,8 @@ public class MenuController extends BaseController {
     @ApiOperation("根据菜单id删除菜单")
     @DeleteMapping("/del/{id}")
     public Object delMenu(@ApiParam(value = "菜单编号", required = true) @PathVariable("id") Integer id) {
-        return succeed(sysMenuService.delete(id));
+        sysMenuService.recursiveDel(id);
+        return succeed();
     }
 
     @ApiOperation("根据菜单id修改菜单")

+ 5 - 0
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/web/controller/UserController.java

@@ -59,6 +59,11 @@ public class UserController extends BaseController {
 		return failed();
 	}
 
+	@GetMapping("/queryUserByPhone")
+	public SysUser queryUserByPhone(String mobile) {
+		return sysUserService.queryByPhone(mobile);
+	}
+
 	@ApiOperation(value = "新增用户")
 	@PostMapping("/add")
 	public Object add(@RequestBody SysUser sysUser) {

+ 8 - 5
mec-auth/mec-auth-server/src/main/resources/config/mybatis/SysMenuMapper.xml

@@ -91,6 +91,13 @@
 		UPDATE sys_menu SET del_flag_ = 1 WHERE id_ = #{id}
 	</update>
 
+    <update id="batchDel" parameterType="java.util.List">
+        UPDATE sys_menu SET del_flag_ = 1 WHERE id_ IN
+        <foreach collection="list" item="item" open="(" separator="," close=")">
+          #{item}
+        </foreach>
+    </update>
+
     <!-- 分页查询 -->
     <select id="queryPage" resultMap="SysMenu" parameterType="map">
         SELECT sm.* FROM sys_user_role sur
@@ -126,7 +133,7 @@
 
     <!-- 根据权限标识查菜单 -->
     <select id="findMenuByPermission" resultMap="SysMenu">
-        SELECT * FROM `sys_menu` WHERE `permission_` = #{permission}
+        SELECT * FROM `sys_menu` WHERE `permission_` = #{permission} AND del_flag_ = 0
     </select>
     <sql id="queryTree">
         <where>
@@ -151,10 +158,6 @@
         ORDER BY sm.sort_
     </select>
 
-    <select id="findCountBySys" resultType="java.lang.Integer">
-        SELECT COUNT(id_) FROM sys_menu WHERE del_flag_ = #{delFlag} AND parent_id_ = #{parentId}
-    </select>
-
     <select id="findList" resultMap="SysMenu">
         SELECT * FROM sys_menu WHERE del_flag_ = #{delFlag} AND parent_id_ = #{parentId} ORDER BY sort_ DESC
     </select>

+ 2 - 2
mec-auth/mec-auth-server/src/main/resources/config/mybatis/SysUserMapper.xml

@@ -63,8 +63,8 @@
         </selectKey>
         -->
         INSERT INTO sys_user
-        (im_token_,id_,username_,salt_,phone_,avatar_,organ_id_,create_time_,update_time_,lock_flag_,wx_openid_,qq_openid_,user_type_,gender_,nation_,birthdate_,email_)
-        VALUES(#{imToken},#{id},#{username},#{salt},#{phone},#{avatar},#{organId},now(),now(),#{lockFlag},#{wxOpenid},#{qqOpenid},#{userType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{gender, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{nation},#{birthdate},#{email})
+        (im_token_,id_,username_,salt_,phone_,avatar_,organ_id_,create_time_,update_time_,wx_openid_,qq_openid_,user_type_,gender_,nation_,birthdate_,email_)
+        VALUES(#{imToken},#{id},#{username},#{salt},#{phone},#{avatar},#{organId},now(),now(),#{wxOpenid},#{qqOpenid},#{userType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{gender, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{nation},#{birthdate},#{email})
     </insert>
 
     <!-- 根据主键查询一条记录 -->

+ 10 - 12
mec-web/src/main/java/com/ym/mec/web/controller/TeacherController.java

@@ -2,6 +2,7 @@ package com.ym.mec.web.controller;
 
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.security.SecurityUtils;
+import com.ym.mec.web.dal.dto.TeacherUserDto;
 import com.ym.mec.web.dal.entity.Teacher;
 import com.ym.mec.web.dal.page.TeacherQueryInfo;
 import com.ym.mec.web.service.ClassGroupService;
@@ -28,34 +29,31 @@ public class TeacherController extends BaseController {
     @ApiOperation(value = "新增教师")
     @PostMapping("/add")
     public Object add(@RequestBody Teacher teacher) {
-        Teacher teacherServiceByCertificateNum = teacherService.findByCertificateNum(teacher.getCertificateNum());
-        if (teacherServiceByCertificateNum != null) {
-            return failed("系统已存在该证件号的老师,请核查");
-        }
-        Integer organId = SecurityUtils.getUser().getOrganId();
-        if(organId != null){
-            teacher.setOrganId(organId);
+        try {
+            teacherService.add(teacher);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return failed(e.getMessage());
         }
-        teacherService.insert(teacher);
         return succeed();
     }
 
     @ApiOperation(value = "删除教师")
-    @DeleteMapping("/del/{id}")
+    @PostMapping("/del/{id}")
     public Object del(@ApiParam(value = "教师编号", required = true) @PathVariable("id") Integer id) {
         teacherService.delete(id);
         return succeed();
     }
 
     @ApiOperation(value = "修改教师")
-    @PutMapping("/update")
+    @PostMapping("/update")
     public Object update(@RequestBody Teacher teacher) {
         Integer organId = SecurityUtils.getUser().getOrganId();
         if(organId != null){
             teacher.setOrganId(organId);
         }
         Teacher teacherServiceByCertificateNum = teacherService.findByCertificateNum(teacher.getCertificateNum());
-        if (teacherServiceByCertificateNum != null && !teacherServiceByCertificateNum.getUserId().equals(teacher.getUserId())) {
+        if (teacherServiceByCertificateNum != null && !teacherServiceByCertificateNum.getId().equals(teacher.getId())) {
             return failed("系统已存在该证件号的老师,请核查");
         }
         teacher.setUpdateTime(new Date());
@@ -71,7 +69,7 @@ public class TeacherController extends BaseController {
     }
 
     @ApiOperation(value = "分页查询教师列表")
-    @PostMapping("/queryPage")
+    @GetMapping("/queryPage")
     public Object queryPage(@RequestBody(required = false) TeacherQueryInfo queryInfo) {
         if(queryInfo == null){
             queryInfo = new TeacherQueryInfo();

+ 2 - 46
mec-web/src/main/java/com/ym/mec/web/dal/entity/Teacher.java

@@ -1,5 +1,6 @@
 package com.ym.mec.web.dal.entity;
 
+import com.ym.mec.auth.api.entity.SysUser;
 import io.swagger.annotations.ApiModelProperty;
 
 import java.util.Date;
@@ -13,14 +14,7 @@ import com.ym.mec.web.dal.enums.YesOrNoEnum;
 /**
  * 对应数据库表(teacher):
  */
-public class Teacher {
-
-	/**  */
-	private Integer userId;
-
-	/**  */
-	@ApiModelProperty(value = "机构编号", required = false)
-	private Integer organId;
+public class Teacher extends SysUser {
 
 	/** 职务类型(指导老师、教务老师、教学主管) */
 	@ApiModelProperty(value = "职务类型(指导老师 ADVISER、教务老师 ACADEMIC、教学主管 TEACHING)", required = false)
@@ -70,34 +64,12 @@ public class Teacher {
 	@ApiModelProperty(value = "流动范围(多个用|分开)", required = false)
 	private String flowOrganRange;
 
-	/**  */
-	private java.util.Date updateTime;
-
-	/**  */
-	private java.util.Date createTime;
-
 	@ApiModelProperty(value = "老师介绍", required = false)
 	private String introduction;
 	
 	@ApiModelProperty(value = "离职时间", required = false)
 	private Date demissionDate;
 
-	public void setUserId(Integer userId) {
-		this.userId = userId;
-	}
-
-	public Integer getUserId() {
-		return this.userId;
-	}
-
-	public void setOrganId(Integer organId) {
-		this.organId = organId;
-	}
-
-	public Integer getOrganId() {
-		return this.organId;
-	}
-
 	public JobTypeEnum getJobType() {
 		return jobType;
 	}
@@ -194,22 +166,6 @@ public class Teacher {
 		return this.flowOrganRange;
 	}
 
-	public void setUpdateTime(java.util.Date updateTime) {
-		this.updateTime = updateTime;
-	}
-
-	public java.util.Date getUpdateTime() {
-		return this.updateTime;
-	}
-
-	public void setCreateTime(java.util.Date createTime) {
-		this.createTime = createTime;
-	}
-
-	public java.util.Date getCreateTime() {
-		return this.createTime;
-	}
-
 	public String getIntroduction() {
 		return introduction;
 	}

+ 7 - 0
mec-web/src/main/java/com/ym/mec/web/service/TeacherService.java

@@ -1,6 +1,7 @@
 package com.ym.mec.web.service;
 
 import com.ym.mec.common.service.BaseService;
+import com.ym.mec.web.dal.dto.TeacherUserDto;
 import com.ym.mec.web.dal.entity.Teacher;
 
 public interface TeacherService extends BaseService<Integer, Teacher> {
@@ -11,4 +12,10 @@ public interface TeacherService extends BaseService<Integer, Teacher> {
      * @return Teacher 老师信息
      */
     Teacher findByCertificateNum(String certificateNum);
+
+    /**
+     * 新增教师
+     * @param teacher
+     */
+    void add(Teacher teacher) throws Exception;
 }

+ 22 - 3
mec-web/src/main/java/com/ym/mec/web/service/impl/TeacherServiceImpl.java

@@ -1,19 +1,23 @@
 package com.ym.mec.web.service.impl;
 
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
+import com.ym.mec.auth.api.client.SysUserFeignService;
+import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.web.dal.dao.TeacherDao;
 import com.ym.mec.web.dal.entity.Teacher;
 import com.ym.mec.web.service.TeacherService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 @Service
 public class TeacherServiceImpl extends BaseServiceImpl<Integer, Teacher>  implements TeacherService {
 	
 	@Autowired
 	private TeacherDao teacherDao;
+	@Autowired
+	private SysUserFeignService sysUserFeignService;
 
 	@Override
 	public BaseDAO<Integer, Teacher> getDAO() {
@@ -25,4 +29,19 @@ public class TeacherServiceImpl extends BaseServiceImpl<Integer, Teacher>  imple
 		return teacherDao.findByCertificateNum(certificateNum);
 	}
 
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public void add(Teacher teacher) throws Exception {
+		SysUser user = sysUserFeignService.getUserByMobile(teacher.getPhone());
+		if(user != null){
+			throw new Exception("系统已存在该手机号的老师,请核查");
+		}
+		//保存用户表信息
+		sysUserFeignService.addUser(teacher);
+		//注册到融云
+
+		//保存教师表数据
+		teacherDao.insert(teacher);
+	}
+
 }

+ 3 - 3
mec-web/src/main/resources/config/mybatis/TeacherMapper.xml

@@ -7,7 +7,7 @@
 <mapper namespace="com.ym.mec.web.dal.dao.TeacherDao">
 
     <resultMap type="com.ym.mec.web.dal.entity.Teacher" id="Teacher">
-        <result column="user_id_" property="userId"/>
+        <result column="id_" property="id"/>
         <result column="organ_id_" property="organId"/>
         <result column="job_type_" property="jobType"/>
         <result column="job_nature_" property="jobNature"/>
@@ -46,8 +46,8 @@
         </selectKey>
         -->
         INSERT INTO teacher
-        (user_id_,organ_id_,job_type_,job_nature_,is_probation_period_,education_background_,graduate_school_,technical_titles_,work_unit_,subject_id_,entry_date_,demission_date_,certificate_type_,certificate_num_,flow_organ_range_,introduction_,update_time_,create_time_)
-        VALUES(#{userId},#{organId},#{jobType},#{jobNature},#{isProbationPeriod,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{educationBackground},#{graduateSchool},#{technicalTitles},#{workUnit},#{subjectId},#{entryDate},#{demissionDate},#{certificateType},#{certificateNum},#{flowOrganRange},#{introduction},now(),now())
+        (id_,organ_id_,job_type_,job_nature_,is_probation_period_,education_background_,graduate_school_,technical_titles_,work_unit_,subject_id_,entry_date_,demission_date_,certificate_type_,certificate_num_,flow_organ_range_,introduction_,update_time_,create_time_)
+        VALUES(#{id},#{organId},#{jobType},#{jobNature},#{isProbationPeriod,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{educationBackground},#{graduateSchool},#{technicalTitles},#{workUnit},#{subjectId},#{entryDate},#{demissionDate},#{certificateType},#{certificateNum},#{flowOrganRange},#{introduction},now(),now())
     </insert>
 
     <!-- 根据主键查询一条记录 -->