using Admin.NET.Plugin.AiDOP.Dto.S0.Sales; using Admin.NET.Plugin.AiDOP.Entity.S0.Sales; namespace Admin.NET.Plugin.AiDOP.Controllers.S0.Sales; /// /// 合同评审周期同步开关:工厂级一行。 /// GET 行不存在时返回 IsSyncEnabled=false 兜底;PUT 走 upsert。 /// [ApiController] [Route("api/s0/sales/contract-review-cycle-sync-flag")] [AllowAnonymous] [NonUnify] public class AdoS0ContractReviewCycleSyncFlagsController : ControllerBase { private readonly SqlSugarRepository _rep; public AdoS0ContractReviewCycleSyncFlagsController(SqlSugarRepository rep) => _rep = rep; [HttpGet] public async Task GetByFactoryAsync([FromQuery] long factoryRefId) { if (factoryRefId <= 0) return BadRequest(new { message = "factoryRefId 不能为空" }); var entity = await _rep.AsQueryable() .Where(x => x.FactoryRefId == factoryRefId) .FirstAsync(); if (entity == null) { return Ok(new AdoS0ContractReviewCycleSyncFlagDto { FactoryRefId = factoryRefId, IsSyncEnabled = false, }); } return Ok(new AdoS0ContractReviewCycleSyncFlagDto { Id = entity.Id, CompanyRefId = entity.CompanyRefId, FactoryRefId = entity.FactoryRefId, DomainCode = entity.DomainCode, IsSyncEnabled = entity.IsSyncEnabled, }); } [HttpPut] public async Task UpsertAsync([FromBody] AdoS0ContractReviewCycleSyncFlagUpsertDto dto) { var now = DateTime.Now; var entity = await _rep.AsQueryable() .Where(x => x.FactoryRefId == dto.FactoryRefId) .FirstAsync(); if (entity == null) { entity = new AdoS0ContractReviewCycleSyncFlag { CompanyRefId = dto.CompanyRefId, FactoryRefId = dto.FactoryRefId, DomainCode = dto.DomainCode, IsSyncEnabled = dto.IsSyncEnabled, CreateUser = dto.CreateUser, CreateTime = now, }; await _rep.AsInsertable(entity).ExecuteReturnEntityAsync(); } else { entity.CompanyRefId = dto.CompanyRefId; entity.DomainCode = dto.DomainCode; entity.IsSyncEnabled = dto.IsSyncEnabled; entity.UpdateUser = dto.UpdateUser; entity.UpdateTime = now; await _rep.AsUpdateable(entity).ExecuteCommandAsync(); } return Ok(new AdoS0ContractReviewCycleSyncFlagDto { Id = entity.Id, CompanyRefId = entity.CompanyRefId, FactoryRefId = entity.FactoryRefId, DomainCode = entity.DomainCode, IsSyncEnabled = entity.IsSyncEnabled, }); } }