public bool AddPolicyCustomerRelation(CorpPolicyConfigCustomerModel model)
        {
            //1.先清空所有关系
            List <CorpPolicyConfigCustomerEntity> corpPolicyConfigCustomerEntities =
                _corpPolicyConfigCustomerDal.Query <CorpPolicyConfigCustomerEntity>(n => n.PolicyId == model.PolicyId)
                .ToList();

            if (corpPolicyConfigCustomerEntities.Count > 0)
            {
                foreach (var corpPolicyConfigCustomerEntity in corpPolicyConfigCustomerEntities)
                {
                    _corpPolicyConfigCustomerDal.Delete <CorpPolicyConfigCustomerEntity>(corpPolicyConfigCustomerEntity.Id);
                }
            }

            //2.在插入关联信息
            if (model.CidList != null && model.CidList.Count > 0)
            {
                foreach (int cid in model.CidList)
                {
                    _corpPolicyConfigCustomerDal.Insert <CorpPolicyConfigCustomerEntity>(new CorpPolicyConfigCustomerEntity()
                    {
                        Cid      = cid,
                        PolicyId = model.PolicyId
                    });
                }
            }


            return(true);
        }
        public List <CorpPolicyCustomerModel> GetCorpPolicyCustomer(string corpId, int policyId)
        {
            List <CorpPolicyCustomerModel> corpPolicyCustomerModels = new List <CorpPolicyCustomerModel>();

            //根据政策Id从部门关联表中获取对应的部门Id
            List <CorpPolicyConfigDepartmentEntity> configDepartmentEntities =
                _corpPolicyConfigDepartmentDal.Query <CorpPolicyConfigDepartmentEntity>(n => n.PolicyId == policyId, true)
                .ToList();

            List <int> departIdList = new List <int>();

            configDepartmentEntities.ForEach(n => departIdList.Add(n.DepartmentId));

            //根据部门id获取客户id
            List <CustomerInfoEntity> customerInfoEntities =
                _customerDal.Query <CustomerInfoEntity>(
                    n =>
                    !string.IsNullOrEmpty(n.CorpID) && n.CorpID.ToUpper() == corpId.ToUpper() &&
                    departIdList.Contains(n.CorpDepartID ?? 0) && !string.IsNullOrEmpty(n.IsDel) &&
                    n.IsDel.ToUpper() == "F" && n.IsLock.ToUpper() == "F", true)
                .ToList();


            //根据政策Id获取对应的客户id信息
            List <CorpPolicyConfigCustomerEntity> corpPolicyConfigCustomerEntities =
                _corpPolicyConfigCustomerDal.Query <CorpPolicyConfigCustomerEntity>(
                    n => n.PolicyId == policyId, true).ToList();

            //根据政策id获取非对应的客户信息
            List <CorpPolicyConfigCustomerEntity> corpPolicyConfigCustomerEntities2 =
                (from c in base.Context.Set <CorpPolicyConfigCustomerEntity>()
                 join a in Context.Set <CorpPolicyConfigEntity>() on c.PolicyId equals a.PolicyId
                 where a.IsDel == "F" && c.PolicyId != policyId
                 select c).ToList();


            foreach (var customerInfoEntity in customerInfoEntities)
            {
                if (corpPolicyConfigCustomerEntities2.Find(n => n.Cid == customerInfoEntity.Cid) != null)
                {
                    continue;
                }

                CorpPolicyConfigCustomerEntity configCustomerEntity =
                    corpPolicyConfigCustomerEntities.Find(n => n.Cid == customerInfoEntity.Cid);

                corpPolicyCustomerModels.Add(new CorpPolicyCustomerModel()
                {
                    Cid            = customerInfoEntity.Cid,
                    CustomerName   = customerInfoEntity.RealName,
                    DepartmentName = customerInfoEntity.DepartmentName,
                    IsHasPolicy    = (configCustomerEntity != null)
                });
            }
            corpPolicyCustomerModels = corpPolicyCustomerModels.OrderBy(n => n.DepartmentName).ToList();
            return(corpPolicyCustomerModels);
        }
Exemplo n.º 3
0
        public bool AddPolicyDepartmentRelation(CorpPolicyConfigDepartmentModel model)
        {
            List <CorpPolicyConfigDepartmentEntity> configDepartmentEntities =
                _corpPolicyConfigDepartmentDal.Query <CorpPolicyConfigDepartmentEntity>(
                    n => n.PolicyId == model.PolicyId, true)
                .ToList();                                                                 //根据政策id获取与部门的关系信息

            bool isClearAll = (model.DepartmentIdList.Find(n => n.Value == true) == null); //是否清空所有关系

            if (!isClearAll)
            {
                foreach (var departKeyValue in model.DepartmentIdList)
                {
                    var configDepartment = configDepartmentEntities.Find(n => n.DepartmentId == departKeyValue.Key);

                    if (configDepartment == null && departKeyValue.Value)//不存在关系,并且勾选了部门
                    {
                        //新增
                        _corpPolicyConfigDepartmentDal.Insert <CorpPolicyConfigDepartmentEntity>(new CorpPolicyConfigDepartmentEntity()
                        {
                            DepartmentId = departKeyValue.Key,
                            PolicyId     = model.PolicyId
                        });
                    }

                    if (configDepartment != null && !departKeyValue.Value)//存在关系,并且不选部门
                    {
                        //删除部门关系
                        _corpPolicyConfigDepartmentDal.Delete <CorpPolicyConfigDepartmentEntity>(configDepartment.Id);
                        //删除员工关系
                        List <CorpPolicyConfigCustomerEntity> corpPolicyConfigCustomerEntities =
                            _corpPolicyConfigCustomerDal.Query <CorpPolicyConfigCustomerEntity>(
                                n => n.PolicyId == model.PolicyId, true).ToList();
                        if (corpPolicyConfigCustomerEntities.Count > 0)
                        {
                            foreach (var entity in corpPolicyConfigCustomerEntities)
                            {
                                _corpPolicyConfigCustomerDal.Delete <CorpPolicyConfigCustomerEntity>(entity.Id);
                            }
                        }
                    }
                }
            }
            else
            {
                //清空所有关系
                if (configDepartmentEntities.Count > 0)
                {
                    foreach (var entity in configDepartmentEntities)
                    {
                        _corpPolicyConfigDepartmentDal.Delete <CorpPolicyConfigDepartmentEntity>(entity.Id);
                    }
                }

                //在清空与员工的关系
                List <CorpPolicyConfigCustomerEntity> corpPolicyConfigCustomerEntities =
                    _corpPolicyConfigCustomerDal.Query <CorpPolicyConfigCustomerEntity>(
                        n => n.PolicyId == model.PolicyId, true).ToList();
                if (corpPolicyConfigCustomerEntities.Count > 0)
                {
                    foreach (var entity in corpPolicyConfigCustomerEntities)
                    {
                        _corpPolicyConfigCustomerDal.Delete <CorpPolicyConfigCustomerEntity>(entity.Id);
                    }
                }
            }


            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 产生差旅政策信息
        /// </summary>
        /// <param name="cid"></param>
        /// <param name="departId"></param>
        /// <param name="isAllowUserInsurance"></param>
        /// <returns></returns>
        public List <CorpPolicyChangeModel> GetCorpPolicyChangeInfo(int cid, int departId, int isAllowUserInsurance)
        {
            List <CorpPolicyChangeModel> resultList = null;

            #region 先根据cid查找员工的差旅政策
            List <CorpPolicyConfigCustomerEntity> corpPolicyConfigCustomerList =
                _corpPolicyConfigCustomerDal.Query <CorpPolicyConfigCustomerEntity>(n => n.Cid == cid, true).ToList();
            if (corpPolicyConfigCustomerList != null && corpPolicyConfigCustomerList.Count > 0)
            {
                List <int> policyIdList = new List <int>();
                corpPolicyConfigCustomerList.ForEach(n => { policyIdList.Add(n.PolicyId); });
                //获取政策信息
                List <CorpPolicyConfigEntity> policyList = _corpPolicyConfigDal.Query <CorpPolicyConfigEntity>(
                    n => policyIdList.Contains(n.PolicyId) && !string.IsNullOrEmpty(n.IsDel) && n.IsDel.ToUpper() == "F",
                    true).ToList();

                resultList = new List <CorpPolicyChangeModel>();
                foreach (var entity in corpPolicyConfigCustomerList)
                {
                    var policy = policyList.Find(n => n.PolicyId == entity.PolicyId);
                    if (policy != null)
                    {
                        List <CorpPolicyDetailConfigEntity> policyDetailList =
                            _corpPolicyDetailConfigDal.Query <CorpPolicyDetailConfigEntity>(
                                n => n.PolicyId == entity.PolicyId, true).ToList();
                        CorpPolicyDetailConfigModel policyModel = CorpPolicyConvertFactory.Convert(policyDetailList);

                        if (isAllowUserInsurance == 0)//如果当前公司个性化不许购买保险,则统一设置F;如果允许购买保险,则看差标允许不允许
                        {
                            policyModel.NPolicyValI = "F";
                        }

                        resultList.Add(new CorpPolicyChangeModel()
                        {
                            PolicyId           = entity.PolicyId,
                            PolicyName         = policy.PolicyName,
                            ViolateNPolicyValL = policyModel.NPolicyValL,
                            ViolateNPolicyValT = policyModel.NPolicyValT,
                            ViolateNPolicyValR = policyModel.NPolicyValR,
                            ViolateNPolicyValY = policyModel.NPolicyValY,
                            ViolateNPolicyValI = policyModel.NPolicyValI,
                            ViolateTPolicyValQ = policyModel.TPolicyValQ,
                            ViolateTPolicyValM = policyModel.TPolicyValM,
                            ViolateTPolicyValS = policyModel.TPolicyValS
                        });
                    }
                }
                return(resultList);
            }

            #endregion

            #region 如果没有政策,则查找部门的差旅政策
            List <CorpPolicyConfigDepartmentEntity> corpPolicyConfigDepartmentEntities =
                _corpPolicyConfigDepartmentDal.Query <CorpPolicyConfigDepartmentEntity>(n => n.DepartmentId == departId,
                                                                                        true)
                .ToList();
            if (corpPolicyConfigDepartmentEntities != null && corpPolicyConfigDepartmentEntities.Count > 0)
            {
                List <int> policyIdList = new List <int>();
                corpPolicyConfigDepartmentEntities.ForEach(n => { policyIdList.Add(n.PolicyId); });

                //获取政策信息
                List <CorpPolicyConfigEntity> policyList = _corpPolicyConfigDal.Query <CorpPolicyConfigEntity>(
                    n => policyIdList.Contains(n.PolicyId) && !string.IsNullOrEmpty(n.IsDel) && n.IsDel.ToUpper() == "F",
                    true).ToList();
                resultList = new List <CorpPolicyChangeModel>();

                foreach (var entity in corpPolicyConfigDepartmentEntities)
                {
                    var policy = policyList.Find(n => n.PolicyId == entity.PolicyId);
                    if (policy != null)
                    {
                        List <CorpPolicyDetailConfigEntity> policyDetailList =
                            _corpPolicyDetailConfigDal.Query <CorpPolicyDetailConfigEntity>(
                                n => n.PolicyId == entity.PolicyId, true).ToList();
                        CorpPolicyDetailConfigModel policyModel = CorpPolicyConvertFactory.Convert(policyDetailList);
                        if (isAllowUserInsurance == 0)//如果当前公司个性化不许购买保险,则统一设置F;如果允许购买保险,则看差标允许不允许
                        {
                            policyModel.NPolicyValI = "F";
                        }
                        resultList.Add(new CorpPolicyChangeModel()
                        {
                            PolicyId           = entity.PolicyId,
                            PolicyName         = policy.PolicyName,
                            ViolateNPolicyValL = policyModel.NPolicyValL,
                            ViolateNPolicyValT = policyModel.NPolicyValT,
                            ViolateNPolicyValR = policyModel.NPolicyValR,
                            ViolateNPolicyValY = policyModel.NPolicyValY,
                            ViolateNPolicyValI = policyModel.NPolicyValI,
                            ViolateTPolicyValQ = policyModel.TPolicyValQ,
                            ViolateTPolicyValM = policyModel.TPolicyValM,
                            ViolateTPolicyValS = policyModel.TPolicyValS
                        });
                    }
                }
                return(resultList);
            }
            #endregion

            //都没找到则返回null
            return(null);
        }