Просмотр исходного кода

用户删除功能优化,添加是否主库字段

admin лет назад: 5
Родитель
Сommit
f9fa99e52d

+ 2 - 0
src/main/java/com/chinaitop/depot/DepotSystemApplication.java

@@ -6,11 +6,13 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
6 6
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
7 7
 import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
8 8
 import org.springframework.cloud.openfeign.EnableFeignClients;
9
+import org.springframework.transaction.annotation.EnableTransactionManagement;
9 10
 
10 11
 @EnableEurekaClient
11 12
 @EnableDiscoveryClient
12 13
 @SpringBootApplication
13 14
 @EnableFeignClients
15
+@EnableTransactionManagement
14 16
 @MapperScan(basePackages = {"com.chinaitop.depot.system.mapper"})
15 17
 public class DepotSystemApplication {
16 18
 

+ 6 - 4
src/main/java/com/chinaitop/depot/system/controller/UserInfoController.java

@@ -603,11 +603,13 @@ public class UserInfoController {
603 603
 	public Map<String, Object> remove(Integer userId) {
604 604
 		Map<String, Object> modelMap = new HashMap<>();
605 605
 		if (userId != null) {
606
-			userInfoService.remove(userId);
607
-			userRoleService.deleteById(userId);//删除用户角色信息
608
-			userOrgService.deleteById(userId);//删除用户机构权限信息
606
+			try {
607
+				userInfoService.deleteAll(userId);
608
+				modelMap.put("status", "success");
609
+			} catch (Exception e) {
610
+				e.printStackTrace();
611
+			}
609 612
 		}
610
-		modelMap.put("status", "success");
611 613
 		return modelMap;
612 614
 	}
613 615
 	

+ 20 - 5
src/main/java/com/chinaitop/depot/system/mapper/OrgInfoMapper.xml

@@ -61,6 +61,7 @@
61 61
     <result column="frlxfs" property="frlxfs" jdbcType="VARCHAR" />
62 62
     <result column="yxgr" property="yxgr" jdbcType="DECIMAL" />
63 63
     <result column="kqbm" property="kqbm" jdbcType="VARCHAR" />
64
+    <result column="sfzk" property="sfzk" jdbcType="VARCHAR" />
64 65
   </resultMap>
65 66
   <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.chinaitop.depot.system.model.OrgInfo">
66 67
     <result column="wjl" jdbcType="LONGVARCHAR" property="wjl" />
@@ -132,7 +133,7 @@
132 133
     parent_id, status, del_flag, birds_eye, birds_Remote, brief_introduction, invoice_title, 
133 134
     regist_number, bank_name, account_name, account_number,level_code,total_assets,corporate_capacity,
134 135
     office_phone,registered_address,mail_box,official_website,house_number,tank_number,depot_property,
135
-    updatetime,frlxfs,yxgr,kqbm
136
+    updatetime,frlxfs,yxgr,kqbm,sfzk
136 137
   </sql>
137 138
   <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.chinaitop.depot.system.model.OrgInfoExample" >
138 139
     select
@@ -182,7 +183,7 @@
182 183
       regist_number, bank_name, account_name, 
183 184
       account_number,total_assets,corporate_capacity,
184 185
       office_phone,registered_address,mail_box,official_website,
185
-      house_number,tank_number,depot_property,level_code,wjl,frlxfs,yxgr,kqbm)
186
+      house_number,tank_number,depot_property,level_code,wjl,frlxfs,yxgr,kqbm,sfzk)
186 187
     values (#{orgId,jdbcType=INTEGER}, #{orgName,jdbcType=VARCHAR}, #{shortName,jdbcType=VARCHAR}, 
187 188
       #{orgCode,jdbcType=VARCHAR}, #{orgClassId,jdbcType=INTEGER}, #{companyNature,jdbcType=INTEGER}, 
188 189
       #{busiType,jdbcType=INTEGER}, #{address,jdbcType=VARCHAR}, #{contact,jdbcType=VARCHAR}, 
@@ -202,7 +203,7 @@
202 203
       #{officePhone,jdbcType=VARCHAR}, #{registeredAddress,jdbcType=VARCHAR}, #{mailBox,jdbcType=VARCHAR}, 
203 204
       #{officialWebsite,jdbcType=VARCHAR}, #{houseNumber,jdbcType=INTEGER}, #{tankNumber,jdbcType=INTEGER}, 
204 205
       #{depotProperty,jdbcType=VARCHAR}, #{levelCode,jdbcType=VARCHAR}, #{wjl,jdbcType=LONGVARCHAR},
205
-      #{frlxfs,jdbcType=VARCHAR}, #{yxgr,jdbcType=DECIMAL}, #{kqbm,jdbcType=VARCHAR})
206
+      #{frlxfs,jdbcType=VARCHAR}, #{yxgr,jdbcType=DECIMAL}, #{kqbm,jdbcType=VARCHAR}, #{sfzk,jdbcType=VARCHAR})
206 207
   </insert>
207 208
   <insert id="insertSelective" parameterType="com.chinaitop.depot.system.model.OrgInfo" useGeneratedKeys="true" keyProperty="orgId">
208 209
     insert into org_info
@@ -354,6 +355,9 @@
354 355
       <if test="kqbm != null">
355 356
       	kqbm,
356 357
       </if>
358
+      <if test="sfzk != null">
359
+        sfzk,
360
+      </if>
357 361
     </trim>
358 362
     <trim prefix="values (" suffix=")" suffixOverrides="," >
359 363
       <if test="orgId != null" >
@@ -503,6 +507,9 @@
503 507
       <if test="kqbm != null">
504 508
       	#{kqbm,jdbcType=VARCHAR},
505 509
       </if>
510
+      <if test="sfzk != null">
511
+        #{sfzk,jdbcType=VARCHAR},
512
+      </if>
506 513
     </trim>
507 514
   </insert>
508 515
   <select id="countByExample" parameterType="com.chinaitop.depot.system.model.OrgInfoExample" resultType="java.lang.Integer" >
@@ -664,6 +671,9 @@
664 671
       <if test="record.kqbm != null">
665 672
       	kqbm = #{record.kqbm,jdbcType=VARCHAR},
666 673
       </if>
674
+      <if test="record.sfzk != null">
675
+        sfzk = #{record.sfzk,jdbcType=VARCHAR},
676
+      </if>
667 677
     </set>
668 678
     <if test="_parameter != null" >
669 679
       <include refid="Update_By_Example_Where_Clause" />
@@ -719,7 +729,8 @@
719 729
       wjl = #{record.wjl,jdbcType=LONGVARCHAR},
720 730
       frlxfs = #{record.frlxfs,jdbcType=VARCHAR},
721 731
       yxgr = #{record.yxgr,jdbcType=DECIMAL},
722
-      kqbm = #{record.kqbm,jdbcType=VARCHAR}
732
+      kqbm = #{record.kqbm,jdbcType=VARCHAR},
733
+      sfzk = #{record.sfzk,jdbcType=VARCHAR}
723 734
     <if test="_parameter != null" >
724 735
       <include refid="Update_By_Example_Where_Clause" />
725 736
     </if>
@@ -901,6 +912,9 @@
901 912
       <if test="kqbm != null">
902 913
       	kqbm = #{kqbm,jdbcType=VARCHAR},
903 914
       </if>
915
+      <if test="sfzk !=null">
916
+        sfzk = #{sfzk,jdbcType=VARCHAR},
917
+      </if>
904 918
     </set>
905 919
     where org_id = #{orgId,jdbcType=INTEGER}
906 920
   </update>
@@ -963,7 +977,8 @@
963 977
       wjl = #{wjl,jdbcType=LONGVARCHAR},
964 978
       frlxfs = #{frlxfs,jdbcType=VARCHAR},
965 979
       yxgr = #{yxgr,jdbcType=DECIMAL},
966
-      kqbm = #{kqbm,jdbcType=VARCHAR}
980
+      kqbm = #{kqbm,jdbcType=VARCHAR},
981
+      sfzk = #{sfzk,jdbcType=VARCHAR}
967 982
     where org_id = #{orgId,jdbcType=INTEGER}
968 983
   </update>
969 984
   <update id="updateOrgLevel" parameterType="map" statementType="CALLABLE" >

+ 22 - 0
src/main/java/com/chinaitop/depot/system/mapper/UserInfoMapper.java

@@ -45,4 +45,26 @@ public interface UserInfoMapper {
45 45
     List<UserInfo> queryAllByOrgClass(Map<Object, Object> map);
46 46
 
47 47
 	List<UserInfo> getUserInfoByRole(Integer orgId);
48
+
49
+	/**
50
+     * 查询当前用户对应的员工信息
51
+     * 
52
+     * @param userId 员工ID
53
+     * @return
54
+     */
55
+    List<Map<String, Object>> findKeeper(@Param("userId") Integer userId);
56
+
57
+    /**
58
+     * 删除当前用对应的员工信息
59
+     * 
60
+     * @param userId 员工ID
61
+     */
62
+	void deleteKeeperObj(@Param("userId") Integer userId);
63
+
64
+	/**
65
+	 * 删除当前用户对应的员工所保管的仓房信息
66
+	 * 
67
+	 * @param keepid 员工ID集合
68
+	 */
69
+	void deleteKeeperHouseObj(@Param("keepid") Integer keepid);
48 70
 }

+ 12 - 0
src/main/java/com/chinaitop/depot/system/mapper/UserInfoMapper.xml

@@ -558,4 +558,16 @@
558 558
 	) 
559 559
 	ORDER BY user_id 
560 560
   </select>
561
+  <!-- 查询当前用户对应的员工信息 -->
562
+  <select id="findKeeper" resultType="java.util.Map" parameterType="java.lang.Integer">
563
+	SELECT id FROM basic_keeper WHERE user_Id= ${userId}
564
+  </select>
565
+  <!-- 删除当前用户对应的员工信息 -->
566
+  <delete id="deleteKeeperObj" parameterType="java.lang.Integer">
567
+	delete FROM basic_keeper WHERE user_Id= ${userId}
568
+  </delete>
569
+  <!-- 删除当前用户对应的员工所保管的仓房信息 -->
570
+  <delete id="deleteKeeperHouseObj" parameterType="java.lang.Integer">
571
+	DELETE FROM basic_keeper_house WHERE keeper_id = ${keepid}
572
+  </delete>
561 573
 </mapper>

+ 10 - 0
src/main/java/com/chinaitop/depot/system/model/OrgInfo.java

@@ -131,6 +131,8 @@ public class OrgInfo implements Serializable {
131 131
     
132 132
     private String kqbm;
133 133
 
134
+    private String sfzk;
135
+
134 136
     public Integer getOrgId() {
135 137
         return orgId;
136 138
     }
@@ -618,4 +620,12 @@ public class OrgInfo implements Serializable {
618 620
 	public void setKqbm(String kqbm) {
619 621
 		this.kqbm = kqbm == null ? null : kqbm.trim();
620 622
 	}
623
+
624
+	public String getSfzk() {
625
+		return sfzk;
626
+	}
627
+
628
+	public void setSfzk(String sfzk) {
629
+		this.sfzk = sfzk == null ? null : sfzk.trim();
630
+	}
621 631
 }

+ 8 - 0
src/main/java/com/chinaitop/depot/system/service/UserInfoService.java

@@ -119,4 +119,12 @@ public interface UserInfoService {
119 119
 	List<UserInfo> queryAllByOrgClass(Map<Object, Object> map);
120 120
 
121 121
 	List<UserInfo> getUserInfoByRole(Integer orgId);
122
+
123
+	/**
124
+	 * 删除当前用户数据和当前用户关联的部分数据
125
+	 * 
126
+	 * @param userId
127
+	 * @throws Exception
128
+	 */
129
+	void deleteAll(Integer userId) throws Exception;
122 130
 }

+ 32 - 0
src/main/java/com/chinaitop/depot/system/service/impl/UserInfoServiceImpl.java

@@ -12,7 +12,10 @@ import com.chinaitop.depot.system.model.UserInfoExample.Criteria;
12 12
 import com.chinaitop.depot.system.model.UserRole;
13 13
 import com.chinaitop.depot.system.model.UserRoleExample;
14 14
 import com.chinaitop.depot.system.service.UserInfoService;
15
+import com.chinaitop.depot.system.service.UserOrgService;
16
+
15 17
 import org.springframework.stereotype.Service;
18
+import org.springframework.transaction.annotation.Transactional;
16 19
 
17 20
 import javax.annotation.Resource;
18 21
 
@@ -38,6 +41,9 @@ public class UserInfoServiceImpl implements UserInfoService {
38 41
 	@Resource
39 42
 	private RoleInfoMapper roleInfoMapper;
40 43
 
44
+	@Resource
45
+	private UserOrgService userOrgService;
46
+
41 47
 	@Override
42 48
 	public UserInfo valid(String UserInfoName, String password) {
43 49
 		// 获取MD5加密后的字符串
@@ -281,4 +287,30 @@ public class UserInfoServiceImpl implements UserInfoService {
281 287
 		return UserInfoMapper.getUserInfoByRole(orgId);
282 288
 	}
283 289
 
290
+	@Override
291
+	@Transactional
292
+	public void deleteAll(Integer userId) throws Exception {
293
+
294
+		UserInfoMapper.deleteByPrimaryKey(userId);//删除当前人
295
+		userRoleMapper.deleteById(userId);//删除用户角色信息
296
+		userOrgService.deleteById(userId);//删除用户机构权限信息
297
+
298
+		//删除用对应的员工信息
299
+		/* 查询当前用户对应的员工信息ID */
300
+		List<Map<String, Object>> list = UserInfoMapper.findKeeper(userId);
301
+
302
+		if (null != list && list.size() > 0) {
303
+			/* 删除当前用户对应的员工所保管的仓房信息 */
304
+			//Map<String, Object> map = null;
305
+			for (Map<String, Object> map : list) {
306
+				Integer id = Integer.parseInt(map.get("id")+"");
307
+				UserInfoMapper.deleteKeeperHouseObj(id);
308
+			}
309
+
310
+			/* 删除当前用户对应的员工信息 */
311
+			UserInfoMapper.deleteKeeperObj(userId);
312
+		}
313
+
314
+	}
315
+
284 316
 }