更新项目管理模块中合同管理、项目安装、项目验收、回访记录等功能
This commit is contained in:
1 parent
307e9cf1b9
commit
b3cef22a54
32 files changed
+6094
-2600
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { Provide } from "@midwayjs/core";
|
||||
import { Provide, Inject } from "@midwayjs/core";
|
||||
import { InjectRepository } from "@midwayjs/sequelize";
|
||||
import { Repository } from "sequelize-typescript";
|
||||
import { Op, UniqueConstraintError } from "sequelize";
|
||||
@@ -8,6 +8,7 @@ import ProjectPlanDetail from "../entity/project_plan_detail.entity";
|
||||
import Customer from "../entity/customer.entity";
|
||||
import SysUserRole from "../entity/sysUserRole.entity";
|
||||
import SysRole from "../entity/sysRole.entity";
|
||||
import { LogService } from "./log.service";
|
||||
|
||||
@Provide()
|
||||
export class ProjectPlanService {
|
||||
@@ -26,6 +27,9 @@ export class ProjectPlanService {
|
||||
@InjectRepository(SysRole)
|
||||
roleModel!: Repository<SysRole>;
|
||||
|
||||
@Inject()
|
||||
logService!: LogService;
|
||||
|
||||
private async isAdmin(userId: number): Promise<boolean> {
|
||||
const userRoles = await this.userRoleModel.findAll({ where: { userId }, include: [this.roleModel] });
|
||||
return userRoles.some((ur) => (ur as any).role?.roleCode === "ADMIN");
|
||||
@@ -61,10 +65,19 @@ export class ProjectPlanService {
|
||||
const where: any = {};
|
||||
|
||||
if (query.keyword) {
|
||||
where[Op.or] = [{ registrar: { [Op.like]: `%${query.keyword}%` } }, { planDesc: { [Op.like]: `%${query.keyword}%` } }];
|
||||
where[Op.or] = [
|
||||
{ planNo: { [Op.like]: `%${query.keyword}%` } },
|
||||
{ registrar: { [Op.like]: `%${query.keyword}%` } },
|
||||
{ planDesc: { [Op.like]: `%${query.keyword}%` } }
|
||||
];
|
||||
}
|
||||
if (query.customerId !== undefined) where.customerId = query.customerId;
|
||||
if (query.status !== undefined) where.status = query.status;
|
||||
if (query.registerStartDate || query.registerEndDate) {
|
||||
where.registerTime = {};
|
||||
if (query.registerStartDate) where.registerTime[Op.gte] = query.registerStartDate;
|
||||
if (query.registerEndDate) where.registerTime[Op.lte] = query.registerEndDate;
|
||||
}
|
||||
|
||||
if (!(await this.isAdmin(userId))) {
|
||||
const myCustomers = await this.customerModel.findAll({ where: { salesmanId: userId }, attributes: ["id"] });
|
||||
@@ -99,6 +112,7 @@ export class ProjectPlanService {
|
||||
await this.detailModel.bulkCreate(details.map((d: any) => ({ ...d, planId: created.id, customerId: created.customerId })));
|
||||
}
|
||||
const result = await this.planModel.findByPk(created.id, { include: [this.detailModel] });
|
||||
await this.logService.logAction(ctx, "项目方案", "创建", data.planNo, `创建项目方案 ${data.planNo}`);
|
||||
return { code: 200, message: "创建项目方案成功", data: result?.toJSON() };
|
||||
} catch (err: any) {
|
||||
if (err instanceof UniqueConstraintError) {
|
||||
@@ -133,6 +147,7 @@ export class ProjectPlanService {
|
||||
}
|
||||
}
|
||||
const result = await this.planModel.findByPk(id, { include: [this.detailModel] });
|
||||
await this.logService.logAction(ctx, "项目方案", "更新", record.planNo, `更新项目方案 ${record.planNo}`);
|
||||
return { code: 200, message: "更新项目方案成功", data: result?.toJSON() };
|
||||
}
|
||||
|
||||
@@ -140,8 +155,10 @@ export class ProjectPlanService {
|
||||
const record = await this.planModel.findByPk(id);
|
||||
if (!record) return { code: 404, message: "项目方案不存在", data: null };
|
||||
if (!(await this.isCustomerOwner(ctx.state.user.userId, record.customerId))) return { code: 403, message: "无权限删除该方案", data: null };
|
||||
const planNo = record.planNo;
|
||||
await this.detailModel.destroy({ where: { planId: id } });
|
||||
await record.destroy();
|
||||
await this.logService.logAction(ctx, "项目方案", "删除", planNo, `删除项目方案 ${planNo}`);
|
||||
return { code: 200, message: "删除项目方案成功", data: null };
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user