123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using System;
- using System.Collections.Generic;
- using System.Data.SqlClient;
- using System.Linq;
- using JLHHJSvr.BLL;
- using JLHHJSvr.Com;
- using JLHHJSvr.LJException;
- using LJLib.DAL.SQL;
- using LJLib.Net.SPI.Server;
- namespace JLHHJSvr.Excutor
- {
- internal sealed class AuditDeptExcutor : ExcutorBase<AuditDeptRequest, AuditDeptResponse>
- {
- protected override void ExcuteInternal(AuditDeptRequest request, object state, AuditDeptResponse rslt)
- {
- var tokendata = BllHelper.GetToken(request.token);
- if (tokendata == null)
- {
- rslt.ErrMsg = "会话已经中断,请重新登录";
- return;
- }
- if (!request.list.Any())
- {
- rslt.ErrMsg = "至少提交一条需要审核/撤审/禁用/反禁用的记录";
- return;
- }
- using (var con = new SqlConnection(GlobalVar.ConnectionString))
- using (var cmd = con.CreateCommand())
- {
- con.Open();
- var updateField = string.Empty;
- if (request.type < 2) // 审核
- {
- updateField = "flag";
- }
- else
- {
- updateField = "inuse";
- }
- foreach (var item in request.list)
- {
- if (DbSqlHelper.SelectOne(cmd, item, "flag,inuse") <= 0)
- {
- throw new LJCommonException("部门不存在或已审核,请检查!");
- }
- if (request.type == 0 && item.flag == 1)
- {
- throw new LJCommonException("部门已审核,请检查!");
- }
- else if (request.type == 1 && item.flag == 0)
- {
- throw new LJCommonException("部门未审核,请检查!");
- }
- else if (request.type == 2 && item.inuse == 0)
- {
- throw new LJCommonException("部门未禁用,请检查!");
- }
- else if (request.type == 3 && item.inuse == 1)
- {
- throw new LJCommonException("部门已禁用,请检查!");
- }
- }
- using (cmd.Transaction = con.BeginTransaction())
- {
- try
- {
- foreach (var item in request.list)
- {
- switch (request.type)
- {
- case 0:
- item.flag = 1;
- break;
- case 1:
- item.flag = 0;
- break;
- case 2:
- item.inuse = 0;
- break;
- case 3:
- item.inuse = 1;
- break;
- }
- if (DbSqlHelper.Update(cmd, "u_dept", null, item, "deptid", updateField) <= 0)
- {
- throw new LJCommonException("部门更新失败!");
- }
- }
- cmd.Transaction.Commit();
- }
- catch (Exception e)
- {
- cmd.Transaction.Rollback();
- rslt.ErrMsg = e.ToString();
- }
- }
- }
- }
- }
- }
|