mh_jy_safe/APT.MicroApi/APT.PF.WebApi/Controllers/Api/PFBititleController.cs

123 lines
4.6 KiB
C#
Raw Normal View History

using APT.BaseData.Domain.Entities;
using APT.BaseData.Domain.IServices;
using APT.Infrastructure.Core;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using APT.Utility;
using APT.Infrastructure.Api;
using APT.Migrations;
using APT.BaseData.Domain.Entities.OP;
using APT.BaseData.Domain.Enums.OP;
using APT.BaseData.Domain.Enums.PF;
using APT.BaseData.Domain.IServices.OP;
using Microsoft.Data.SqlClient;
namespace APT.PF.WebApiControllers.Api.PF
{
/// <summary>
///
/// </summary>
[Route("api/PF/PFBititle")]
public class PFBititleController : AuthorizeApiController<T_PF_BITITLE>
{
IOPTenantDBConnService OPTenantDBConnService { get; set; }
/// <summary>
///
/// </summary>
/// <param name="opTenantDBConnService"></param>
public PFBititleController(IOPTenantDBConnService opTenantDBConnService)
{
OPTenantDBConnService = opTenantDBConnService;
}
/// <summary>
/// 更新或新增数据
/// </summary>
/// <param name="entity">对象实体</param>
/// <returns></returns>
[HttpPost, Route("FullUpdate")]
public JsonActionResult<bool> FullUpdate([FromBody] T_PF_BITITLE entity)
{
return SafeExecute(() =>
{
T_PF_BITITLE check = null;
T_PF_BITITLE ModelUpdateOld = null;
2026-04-23 11:07:26 +08:00
if (entity.VERSION == 0)
{
entity.VERSION = 1;
}
if (string.IsNullOrEmpty(entity.TITLE) || entity.TITLE == "<p></p>")
{
throw new Exception("请输入标语后再操作!");
}
if (entity.STATUS == STATEEnum.release)
{
check = GetEntity<T_PF_BITITLE>(e => e.STATUS == STATEEnum.release);
if (check != null)
{
if (check.ID == entity.ID)
{
//旧数据 撤回状态 本条修改ID 父项ID 版本号等
ModelUpdateOld = check;
ModelUpdateOld.STATUS = STATEEnum.Draft;
2026-04-23 11:07:26 +08:00
entity.ID = Guid.NewGuid();
entity.PARENTID = ModelUpdateOld.ID;
entity.VERSION = ModelUpdateOld.VERSION + 1;
2026-04-23 13:56:25 +08:00
entity.USER_ID_CREATER = APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value;
}
else
{
2026-04-23 11:07:26 +08:00
throw new Exception("只能有一条已发布的标语!如需发布本本条,请撤回已发布的标语!");
}
}
}
2026-04-23 11:07:26 +08:00
else if (entity.STATUS == STATEEnum.Delete)
{
entity.IS_DELETED = true;
}
else if (entity.STATUS == STATEEnum.Draft)
{
check = GetEntity<T_PF_BITITLE>(entity.ID);
if (check != null)
{
if (check.STATUS == STATEEnum.release)
{
throw new Exception("请先撤回后再修改!");
}
else if (check.TITLE != entity.TITLE)
{
ModelUpdateOld = check;
ModelUpdateOld.STATUS = STATEEnum.Draft;
2026-04-23 11:07:26 +08:00
entity.ID = Guid.NewGuid();
//entity.VERSION = ModelUpdateOld.VERSION + 1; //只是保存 不加版本号
2026-04-23 11:07:26 +08:00
entity.PARENTID = ModelUpdateOld.ID;
2026-04-23 13:56:25 +08:00
entity.USER_ID_CREATER = APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value;
2026-04-23 11:07:26 +08:00
}
}
}
2026-04-23 13:56:25 +08:00
if (entity.USER_ID_CREATER == Guid.Empty)
{
entity.USER_ID_CREATER = APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value;
}
2026-04-23 11:07:26 +08:00
entity.MODIFY_TIME = DateTime.Now;
if (ModelUpdateOld != null)
ModelUpdateOld.MODIFY_TIME = DateTime.Now;
2026-04-23 11:07:26 +08:00
this.UnifiedCommit(() =>
{
UpdateEntityNoCommit(entity);
if (ModelUpdateOld != null)
{
UpdateEntityNoCommit(ModelUpdateOld);
}
});
return true;
});
}
}
}