| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using Admin.NET.Plugin.AiDOP.Dto.S0.Sales;
- using Admin.NET.Plugin.AiDOP.Entity.S0.Sales;
- namespace Admin.NET.Plugin.AiDOP.Controllers.S0.Sales;
- /// <summary>
- /// 合同评审周期同步开关:工厂级一行。
- /// GET 行不存在时返回 IsSyncEnabled=false 兜底;PUT 走 upsert。
- /// </summary>
- [ApiController]
- [Route("api/s0/sales/contract-review-cycle-sync-flag")]
- [AllowAnonymous]
- [NonUnify]
- public class AdoS0ContractReviewCycleSyncFlagsController : ControllerBase
- {
- private readonly SqlSugarRepository<AdoS0ContractReviewCycleSyncFlag> _rep;
- public AdoS0ContractReviewCycleSyncFlagsController(SqlSugarRepository<AdoS0ContractReviewCycleSyncFlag> rep)
- => _rep = rep;
- [HttpGet]
- public async Task<IActionResult> 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<IActionResult> 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,
- });
- }
- }
|