import { default as BaseController } from "../../baseController";
|
import { Post } from "egg-shell-decorators";
|
import { AppGoodsView } from "../../../entity/crm/app/appGoodsView";
|
import { MoreThan } from "typeorm";
|
|
export default class AppGoodsViewController extends BaseController {
|
//#region 仓库实物巡查添加
|
/**
|
*仓库实物巡查添加
|
*/
|
@Post()
|
public async save() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
|
try {
|
// 设置账套数据
|
await this.setAccountInfo(body);
|
// 保存数据
|
await this.dbWrite.save(AppGoodsView, body);
|
|
this.info.result = true;
|
this.info.msg = "申请保存成功";
|
|
ctx.body = this.info;
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "申请保存失败" + error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 保存回复
|
/**
|
*保存回复
|
*/
|
@Post()
|
public async submitReplay() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let goodsView_Id = body.goodsView_Id; // 实物巡检ID
|
let replyList = body.replyList; // 回复内容
|
let unRead = body.unRead;
|
|
try {
|
// 修改回复内容
|
await this.dbWrite.update(AppGoodsView, goodsView_Id, {
|
replyList: JSON.stringify(replyList),
|
unRead: unRead + 1,
|
unReads: 2
|
});
|
|
this.info.result = true;
|
this.info.msg = "回复保存成功";
|
|
ctx.body = this.info;
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "回复保存失败" + error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 获得实物巡查信息
|
/**
|
* 获得实物巡查信息
|
*/
|
@Post()
|
public async getList() {
|
let { ctx } = this;
|
|
try {
|
let dataList = await this.dbRead.find(AppGoodsView, {
|
order: {
|
goodsView_Id: "DESC"
|
}
|
});
|
|
this.info.result = true;
|
this.info.data = dataList;
|
} catch (error) {
|
this.info.result = false;
|
this.info.data = error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 获得回复消息
|
/**
|
* 获得回复消息
|
*/
|
@Post()
|
public async getListUnRead() {
|
let { ctx } = this;
|
|
try {
|
let sql = `SELECT SUM(UnRead) AS unRead FROM dbo.App_GoodsView`;
|
let dt = (await this.dbRead.query(sql))[0].unRead;
|
|
this.info.result = true;
|
this.info.data = dt;
|
// let dataList = await this.dbRead.find(AppGoodsView, {
|
// unRead: 0,
|
// userProduct_Id: (await this.userInfo).userProduct_Id
|
// });
|
// this.info.result = true;
|
// this.info.data = dataList;
|
} catch (error) {
|
this.info.result = false;
|
this.info.data = error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
//#region 获得提交申请消息
|
/**
|
* 获得提交申请消息
|
*/
|
@Post()
|
public async getListUnReads() {
|
let { ctx } = this;
|
|
try {
|
let sql = `SELECT SUM(UnReads) AS unReads FROM dbo.App_GoodsView where UnReads=1`;
|
let dt = (await this.dbRead.query(sql))[0].unReads;
|
|
this.info.result = true;
|
this.info.data = dt;
|
// let dataList = await this.dbRead.find(AppGoodsView, {
|
// unRead: 0,
|
// userProduct_Id: (await this.userInfo).userProduct_Id
|
// });
|
// this.info.result = true;
|
// this.info.data = dataList;
|
} catch (error) {
|
this.info.result = false;
|
this.info.data = error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
//#region 标记为已读,只更新自己
|
/**
|
*标记为已读,只更新自己
|
*/
|
@Post()
|
public async submitUnRead() {
|
let { ctx } = this;
|
let userInfo = await this.userInfo;
|
try {
|
if (userInfo.roleName === "货主类") {
|
// 标记为已读,只更新自己
|
await this.dbWrite.update(
|
AppGoodsView,
|
{
|
user_Id: userInfo.user_Id,
|
unRead: MoreThan(0)
|
},
|
{
|
unRead: 0
|
}
|
);
|
}
|
this.info.result = true;
|
ctx.body = this.info;
|
} catch (error) {
|
this.info.result = false;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
}
|