@@ -10,6 +10,7 @@ import { TenantPageVo, TenantVo } from './vo/tenant.vo';
1010import { AreaEntity } from '../area/entities/area.entity' ;
1111import { mapToObj } from '@src/utils' ;
1212import { AccountEntity } from '../account/entities/account.entity' ;
13+ import { ICurrentUserType } from '@src/decorators' ;
1314
1415@Injectable ( )
1516export class TenantService {
@@ -42,6 +43,32 @@ export class TenantService {
4243 return '创建成功' ;
4344 }
4445
46+ /**
47+ * @Author : 水痕
48+ * @Date : 2023-10-09 20:58:51
49+ * @LastEditors : 水痕
50+ * @Description : 根据id列表批量删除
51+ * @param {number } idList
52+ * @return {* }
53+ */
54+ async batchDeleteTenantByIdListApi (
55+ idList : number [ ] ,
56+ currentUser : ICurrentUserType
57+ ) : Promise < string > {
58+ console . log ( idList , '获取到的数据' , currentUser ) ;
59+ const { tenantId } = currentUser ;
60+ console . log ( tenantId , idList . includes ( tenantId ) , '???' ) ;
61+ if ( idList . includes ( tenantId ) ) {
62+ throw new HttpException ( '自己不能删除自己' , HttpStatus . OK ) ;
63+ }
64+ const { affected } = await this . tenantRepository . softDelete ( idList ) ;
65+ if ( affected ) {
66+ return '删除成功' ;
67+ } else {
68+ return '删除成功' ;
69+ }
70+ }
71+
4572 /**
4673 * @Author : 水痕
4774 * @Date : 2023-10-07 10:50:10
@@ -50,7 +77,11 @@ export class TenantService {
5077 * @param {number } id
5178 * @return {* }
5279 */
53- async deleteTenantByIdApi ( id : number ) : Promise < string > {
80+ async deleteTenantByIdApi ( id : number , currentUser : ICurrentUserType ) : Promise < string > {
81+ const { tenantId } = currentUser ;
82+ if ( tenantId == id ) {
83+ throw new HttpException ( '自己不能删除自己' , HttpStatus . OK ) ;
84+ }
5485 const { affected } = await this . tenantRepository . softDelete ( id ) ;
5586 if ( affected ) {
5687 return '删除成功' ;
@@ -59,6 +90,40 @@ export class TenantService {
5990 }
6091 }
6192
93+ /**
94+ * @Author : 水痕
95+ * @Date : 2023-10-09 22:06:30
96+ * @LastEditors : 水痕
97+ * @Description : 批量修改状态
98+ * @return {* }
99+ */
100+ async batchModifyTenantStatusByIdApi (
101+ idList : number [ ] ,
102+ currentUser : ICurrentUserType
103+ ) : Promise < string > {
104+ const { tenantId } = currentUser ;
105+ if ( idList . includes ( tenantId ) ) {
106+ throw new HttpException ( '自己不能修改自己' , HttpStatus . OK ) ;
107+ }
108+ const tenantEntityList : Pick < TenantEntity , 'status' > [ ] = await this . tenantRepository . find ( {
109+ where : { id : In ( idList ) } ,
110+ select : [ 'status' ] ,
111+ } ) ;
112+ if ( [ ...new Set ( tenantEntityList . map ( ( item ) => item . status ) ) ] . length > 1 ) {
113+ throw new HttpException ( '当前状态不统一,不能批量修改' , HttpStatus . OK ) ;
114+ }
115+ const { affected } = await this . tenantRepository . update ( idList , {
116+ status :
117+ tenantEntityList [ 0 ] ?. status == StatusEnum . FORBIDDEN
118+ ? StatusEnum . NORMAL
119+ : StatusEnum . FORBIDDEN ,
120+ } ) ;
121+ if ( affected ) {
122+ return '修改成功' ;
123+ } else {
124+ return '修改失败' ;
125+ }
126+ }
62127 /**
63128 * @Author : 水痕
64129 * @Date : 2023-10-07 20:51:30
@@ -67,7 +132,11 @@ export class TenantService {
67132 * @param {number } id
68133 * @return {* }
69134 */
70- async modifyTenantStatusByIdApi ( id : number ) : Promise < string > {
135+ async modifyTenantStatusByIdApi ( id : number , currentUser : ICurrentUserType ) : Promise < string > {
136+ const { tenantId } = currentUser ;
137+ if ( tenantId == id ) {
138+ throw new HttpException ( '自己不能修改自己' , HttpStatus . OK ) ;
139+ }
71140 const tenantEntity : Pick < TenantEntity , 'status' > | null = await this . tenantRepository . findOne ( {
72141 where : { id } ,
73142 select : [ 'status' ] ,
0 commit comments