• kotlin的常规使用


    package cn.szqhyf.qhyffs.app.fs.ctl
    
    import club.newepoch.ijfinal.http.paras.Parameter
    import club.newepoch.ijfinal.kit.buildReturn
    import club.newepoch.utils.JsonUtils
    import cn.szqhyf.qhyffs.app.fs.iservice.BizAbsProfitInfoService
    import cn.szqhyf.qhyffs.app.fs.pojo.po.AddOrRevisionIncomePoJo
    import cn.szqhyf.qhyffs.app.fs.pojo.po.BizAbsProfitInfo
    import cn.szqhyf.qhyffs.app.fs.pojo.po.ModificationFinancialPoJo
    import com.jfinal.core.ActionKey
    import com.jfinal.core.action.Rest
    import com.jfinal.core.pojo.RestMethod
    import com.jfinal.ext.render.Return
    
    /**
     *金融部ABS收益表Controller
     *
     */
    open class BizAbsProfitInfoController : QhyffsController() {
    
    
        /**
         * ABS收益表画面一览 (所属大期)的获得方法
         */
        @Rest(method = RestMethod.GET)
        @ActionKey(value = "/api/finance/biz/abs/profit/periods")
        fun periods(): Return {
            var r = this.initService<BizAbsProfitInfoService>().periods(iwebReq = getIwebRequest())
            return this.buildReturn(data = r)
        }
    
        /**
         * ABS收益表画面一览(带分页查询)
         * @param coreEnterpriseId
         *                       核心企业
         * @param financialInstitutionId
         *                       计划管理人ID
         * @param periods
         *               期数
         * @param bigPeriodsId
         *                       所属大区ID
         */
        @Rest(method = RestMethod.GET)
        @ActionKey(value = "/api/finance/biz/abs/profit/info")
        fun index( @Parameter("核心企业ID") coreEnterpriseId: String? =null,
                   @Parameter("计划管理人ID") financialInstitutionsId: String? =null,
                   @Parameter("期数") periods: String? =null,
                   @Parameter("所属大区") bigPeriodsId: String? =null): Return {
            var r = this.initService<BizAbsProfitInfoService>().pages(iwebReq = getIwebRequest(),
                    pageInfo = this.pageInfo,coreEnterpriseId = coreEnterpriseId, financialInstitutionsId = financialInstitutionsId,
                    periods = periods , bigPeriodsId = bigPeriodsId)
    
            return this.buildReturn(data = r)
        }
    
    
    
    
        /**
         * 添加收益信息表画面 中 (查询按钮的实现)
         * @param  coreEnterpriseId
         *                       核心企业(不允许为空)
         * @param financialInstitutionId
         *                       计划管理人ID(不允许为空)
         * @param periodsId
         *           期数id(不允许为空)
         */
        @Rest(method = RestMethod.GET)
        @ActionKey(value = "/api/finance/biz/abs/profit/subject/info")
        fun getQuery( @Parameter("核心企业ID", optional = false) coreEnterpriseId: String,
                        @Parameter("计划管理人ID", optional = false) financialInstitutionsId: String,
                      @Parameter("期数", optional = false) periods: String )
                : Return {
            var r = this.initService<BizAbsProfitInfoService>().getQuery(iwebReq = getIwebRequest(),
                    coreEnterpriseId = coreEnterpriseId, financialInstitutionsId = financialInstitutionsId , periods =periods)
    
            return this.buildReturn(data = r)
        }
    
    
    
    
        /**
         * 添加收益信息表画面 中 (判断是否跳期的判断依准)
         * @param  coreEnterpriseId
         *                       核心企业(不允许为空)
         * @param financialInstitutionId
         *                       计划管理人ID(不允许为空)
         * @param periodsId
         *           期数id(不允许为空)
         */
        @Rest(method = RestMethod.GET)
        @ActionKey(value = "/api/finance/biz/abs/profit/periods/check")
        fun isjumpPeriods( @Parameter("核心企业ID") coreEnterpriseId: String,
                          @Parameter("计划管理人ID") financialInstitutionsId: String,
                          @Parameter("期数") periods: String )
                : Return {
            var r = this.initService<BizAbsProfitInfoService>().isjumpPeriods(iwebReq = getIwebRequest(),
                    coreEnterpriseId = coreEnterpriseId, financialInstitutionsId = financialInstitutionsId , periods =periods)
    
            return this.buildReturn(data = r)
        }
    
    
        /**
         * 添加收益信息表画面 中 (保存按钮的实现)
         * @param  coreEnterpriseId
         *                       核心企业(不允许为空)
         * @param financialInstitutionId
         *                       计划管理人ID(不允许为空)
         * @param periodsId
         *               期数id(不允许为空)
         * @param  information
         *                       信息(费用名称,备注,金额)
         * @param financeOpinion
         *                       意见
         * @param  releaseDate
         *              发行日期
         */
        @Rest(method = RestMethod.POST)
        @ActionKey(value = "/api/finance/biz/abs/profit/save/subject/info")
        fun saveWays( @Parameter("核心企业ID" ,optional = false) coreEnterpriseId: String,
                      @Parameter("计划管理人ID",optional = false) financialInstitutionsId: String,
                      @Parameter("期数",optional = false) periods: String,
                      @Parameter("费用金额备注", optional = false) subjectlist: MutableList<String> ,
                      @Parameter("意见",optional = false) financeOpinion: String? =null ,
                      @Parameter("发行日期",optional = false)  releaseDate :String? =null
                    ): Return {
            val  subjectlists:MutableList<AddOrRevisionIncomePoJo> = mutableListOf()
            for (subject in subjectlist!!.listIterator() ){
                // 解析字符窜转对象
                var  obj= JsonUtils.parseJson2T(subject,AddOrRevisionIncomePoJo::class.java)
                subjectlists.add(obj)
            }
            var r = this.initService<BizAbsProfitInfoService>().saveWays(iwebReq = getIwebRequest(),
                    subjectlist = subjectlists, financeOpinion = financeOpinion ,releaseDate = releaseDate , coreEnterpriseId = coreEnterpriseId ,
                    financialInstitutionsId = financialInstitutionsId , periods = periods)
            return this.buildReturn(data = r)
        }
    
    
        /**
         * 根据发行日判断是否超过提交期限
         * @param releaseDate
         *         发行日(不能为空)
         */
        @Rest(method = RestMethod.GET)
        @ActionKey(value = "/api/finance/biz/abs/profit/releasedate/check")
        fun isPassDeadline( @Parameter("发行日") releaseDate: String )
                : Return {
            var r = this.initService<BizAbsProfitInfoService>().isPassDeadline(iwebReq = getIwebRequest(),
                    releaseDate = releaseDate)
            return this.buildReturn(data = r)
        }
    
        /**
         * 添加收益信息表画面 中 (提交按钮的实现)
         * @param  coreEnterpriseId
         *                       核心企业(不允许为空)
         * @param financialInstitutionId
         *                       计划管理人ID(不允许为空)
         * @param periodsId
         *               期数id(不允许为空)
         * @param  information
         *                       信息(费用名称,备注,金额)
         * @param financeOpinion
         *                       意见
         * @param  releaseDate
         *              发行日期   List<AddOrRevisionIncomePoJo>
         */
        @Rest(method = RestMethod.POST)
        @ActionKey(value = "/api/finance/biz/abs/profit/submit/subject/info")
        fun getSubmit(
                @Parameter("核心企业ID") coreEnterpriseId: String,
                @Parameter("计划管理人ID") financialInstitutionsId: String,
                @Parameter("期数") periods: String,
                @Parameter("费用金额备注", optional = false) subjectlist: MutableList<String> ,
                @Parameter("意见") financeOpinion: String ,
                @Parameter("发行日期")  releaseDate :String
        ) : Return {
            val  subjectlists:MutableList<AddOrRevisionIncomePoJo> = mutableListOf()
            for (subject in subjectlist!!.listIterator() ){
                // 解析字符窜转对象
                var  obj= JsonUtils.parseJson2T(subject,AddOrRevisionIncomePoJo::class.java)
                subjectlists.add(obj)
            }
            var r = this.initService<BizAbsProfitInfoService>().getSubmit(iwebReq = getIwebRequest(),
                    subjectlist = subjectlists, financeOpinion = financeOpinion ,releaseDate =releaseDate , coreEnterpriseId = coreEnterpriseId ,
                    financialInstitutionsId =financialInstitutionsId , periods = periods )
            return this.buildReturn(data = r)
        }
    
    
        /**
         * 修改收益信息表画面中(获取表单的单个信息)
         * 根据ABS收益信息表id获取收益共通信息
         * @param  absProfitId
         *          表单的id(ABS收益ID)
         *
         */
        @Rest(method = RestMethod.GET)
        @ActionKey(value = "/api/finance/biz/abs/profit/modify/profit/info")
        fun getFormEarningsInformation(
                @Parameter("ABS收益ID", optional = false) absProfitId: Long ): Return {
            var r = this.initService<BizAbsProfitInfoService>().getFormEarningsInformation(iwebReq = getIwebRequest(), absProfitId = absProfitId)
            return this.buildReturn(data = r)
        }
    
        /**
         * 修改收益信息表画面中(获取表单的单个信息)
         * 根据ABS收益ID获取对应科目信息
         * @param  absProfitId
         *          表单的id(ABS收益ID)
         *
         */
        @Rest(method = RestMethod.GET)
        @ActionKey(value = "/api/finance/biz/abs/profit/modify/subject/info")
        fun getFormSubjectInformation(
                @Parameter("ABS收益ID", optional = false) absProfitId: Long ): Return {
            var r = this.initService<BizAbsProfitInfoService>().getFormSubjectInformation(iwebReq = getIwebRequest(), absProfitId = absProfitId)
            return this.buildReturn(data = r)
        }
    
        /**
         * 修改收益信息表画面中
         * 保存金融部收益信息
         * @param  absProfitId
         *          表单的id(ABS收益ID)
         *@param  releaseDate
         *         发行日期
         *@param  financeOpinion
         *         金融意见
         *@param   subjectlist       List<ModificationFinancialPoJo>
         *          科目ID(基础费用科目ID),收益明细ID,收益金额,备注
         */
        @Rest(method = RestMethod.POST)
        @ActionKey(value = "/api/finance/biz/abs/profit/modifysave/subject/info")
        fun saveFinance(
                @Parameter("ABS收益ID", optional = true) absProfitId: Long,
                @Parameter("发行日期", optional = true) releaseDate: String?,
                @Parameter("金融部意见", optional = true) financeOpinion: String?,
                @Parameter("科目的信息", optional = false) subjectlist: MutableList<String>?,
                @Parameter("form表单数据", optional = false) form: String?
                ): Return {
            var subjectlists= mutableListOf<ModificationFinancialPoJo>()
            for (subject in subjectlist!!.iterator()){
               var obj= JsonUtils.parseJson2T(subject,ModificationFinancialPoJo::class.java)
                subjectlists.add(obj)
            }
            var bizAbsProfitInfo=JsonUtils.parseJson2T(form, BizAbsProfitInfo::class.java)
            var r = this.initService<BizAbsProfitInfoService>().saveFinance(iwebReq = getIwebRequest(), absProfitId = absProfitId , releaseDate = releaseDate,
                    financeOpinion = financeOpinion ,  subjectlist = subjectlists,bizAbsProfit=bizAbsProfitInfo)
            return this.buildReturn(data = r)
        }
    
        /**
         * 修改收益信息表画面中
         * 提交金融部收益信息
         * @param  absProfitId
         *          表单的id(ABS收益ID)
         *@param  releaseDate
         *         发行日期
         *@param  financeOpinion
         *         金融意见
         *@param   subjectlist      MutableList<String>?
         *          科目ID(基础费用科目ID),收益明细ID,收益金额,备注
         */
        @Rest(method = RestMethod.POST)
        @ActionKey(value = "/api/finance/biz/abs/profit/modifysubmit/subject/info")
        fun submitFinance(
                @Parameter("ABS收益ID", optional = true) absProfitId: Long ,
                @Parameter("发行日期", optional = true) releaseDate: String? ,
                @Parameter("金融部意见", optional = true) financeOpinion: String? ,
                @Parameter("科目的信息", optional = false) subjectlist: MutableList<String>?,
                @Parameter("form表单数据", optional = false) form: String?
        ): Return {
            //遍历
            val  subjectlists:MutableList<ModificationFinancialPoJo> = mutableListOf()
            for (subject in subjectlist!!.listIterator() ){
                // 解析字符窜转对象
                 var  obj=JsonUtils.parseJson2T(subject,ModificationFinancialPoJo::class.java)
                 subjectlists.add(obj)
            }
            var bizAbsProfit=JsonUtils.parseJson2T(form, BizAbsProfitInfo::class.java)
            var r = this.initService<BizAbsProfitInfoService>().submitFinance(iwebReq = getIwebRequest(), absProfitId = absProfitId , releaseDate = releaseDate,
                    financeOpinion = financeOpinion ,  subjectlist = subjectlists , bizAbsProfit  = bizAbsProfit)
            return this.buildReturn(data = r)
        }
    
    
        /**
         * 修改收益信息表画面中
         * 验证上一期的金融部的所有费用金额与财务部费用是否存在差异
         *   未做完
         */
    //    @Rest(method = RestMethod.GET)
    //    @ActionKey(value = "/api/finance/biz/abs/profit/releasedate/check33333333333333333")
    //    fun differenceMoney(
    //            @Parameter("ABS收益ID", optional = false) absProfitId: Long ,
    //            @Parameter("发行日期", optional = false) releaseDate: String? ,
    //            @Parameter("金融部意见", optional = false) financeOpinion: String? ,
    //            @Parameter("科目的信息", optional = false) subjectlist: List<ModificationFinancialPoJo>?
    //    ): Return {
    ////        var r = this.initService<BizAbsProfitInfoService>().submitFinance(iwebReq = getIwebRequest(), absProfitId = absProfitId , releaseDate = releaseDate,
    ////                financeOpinion = financeOpinion ,  subjectlist = null)
    //      //  return this.buildReturn(data = r)
    //    }
    
    
    
    
    
    
    }
    package cn.szqhyf.qhyffs.app.fs.iservice
    
    import club.newepoch.iweb.ext.IwebReq
    import club.newepoch.persistent.db.common.Model
    import club.newepoch.persistent.db.common.Page
    import club.newepoch.persistent.db.pojo.Record
    import club.newepoch.utils.AssertUtils
    import cn.szqhyf.qhyffs.app.fs.idal.BizAbsProfitInfoServiceDal
    import cn.szqhyf.qhyffs.app.fs.pojo.po.*
    import com.jfinal.aop.Before
    import com.jfinal.core.PageInfo
    import com.jfinal.plugin.activerecord.tx.Tx
    import org.apache.poi.ss.formula.functions.T
    import java.sql.Timestamp
    import java.text.SimpleDateFormat
    import java.util.*
    
    /**
     * ABS收益明细信息表服务类
     *
     */
    open class BizAbsProfitInfoService :  QhyffsService() {
    
    
        /**
         * ABS收益表管理一览画面
         * @param core_enterprise_id
         *                      核心企业
         * @param financial_institutions_id
         *                      金融机构
         * @param periods
         *             期数
         * @param bigPeriodsId
         *                   所属大区ID
         */
        fun pages(iwebReq: IwebReq, pageInfo: PageInfo, coreEnterpriseId:String ?, financialInstitutionsId:String?, periods: String?, bigPeriodsId:String? ): Page<Record>? {
            return this.intDal<BizAbsProfitInfoServiceDal>().pages(iwebReq = iwebReq, pageInfo = pageInfo, coreEnterpriseId = coreEnterpriseId, financialInstitutionsId = financialInstitutionsId, periods = periods , bigPeriodsId = bigPeriodsId)
        }
    
        /**
         * ABS收益表画面一览 (所属大期)的获得方法
         */
        fun periods(iwebReq: IwebReq  ): List<Record>? {
            return this.intDal<BizAbsProfitInfoServiceDal>().periods(iwebReq= iwebReq)
        }
    
        /**
         * 添加收益信息表画面 中 (查询按钮的实现)
         * @param  coreEnterpriseId
         *                       核心企业
         * @param financialInstitutionId
         *                       计划管理人ID
         * @param periodsId
         *           期数ID
         */
        fun getQuery(iwebReq: IwebReq, coreEnterpriseId:String , financialInstitutionsId:String ,periods: String ): List<Record>? {
            if (coreEnterpriseId == null){
                AssertUtils.isTrue(false,"核心企业不能为空!")
            }
            if (financialInstitutionsId == null) {
               AssertUtils.isTrue(false, " 计划管理人不能为空")
            }
            if (periods == null) {
                AssertUtils.isTrue(false, " 期数不能为空")
            }
           var  result= this.intDal<BizAbsProfitInfoServiceDal>().getQuery(iwebReq = iwebReq,  coreEnterpriseId = coreEnterpriseId, financialInstitutionsId = financialInstitutionsId,periods =periods)
            return result
        }
    
    
        /**
         * 添加收益信息表画面 中 (判断是否跳期的判断依准)
         * @param  coreEnterpriseId
         *                       核心企业(不允许为空)
         * @param financialInstitutionId
         *                       计划管理人ID(不允许为空)
         * @param periodsId
         *           期数ID(不允许为空)
         */
        fun isjumpPeriods(iwebReq: IwebReq, coreEnterpriseId:String , financialInstitutionsId:String ,periods: String ): Boolean {
            if (coreEnterpriseId == null){
                AssertUtils.isTrue(false,"核心企业不能为空!")
            }
            if (financialInstitutionsId == null) {
                AssertUtils.isTrue(false, " 计划管理人不能为空")
            }
            if (periods == null) {
                AssertUtils.isTrue(false, " 期数不能为空")
            }
            // true:不存在跳期,false:存在跳期
            var periodsCheck = false
            var list = this.intDal<BizAbsProfitInfoServiceDal>().isjumpPeriods(iwebReq = iwebReq,  coreEnterpriseId = coreEnterpriseId, financialInstitutionsId = financialInstitutionsId,periods =periods)
    
            //如果查询的东西,不为空,不存在跳期
            if (list==null){
                periodsCheck = true
            }
            return  periodsCheck
        }
    
        /**
         * 根据发行日判断是否超过提交期限
         * @param releaseDate
         *         发行日(不能为空)
         */
        fun isPassDeadline(iwebReq: IwebReq, releaseDate:String ): Boolean {
            if (releaseDate == null){
                AssertUtils.isTrue(false,"发行日不能为空!")
            }
            // true:期限验证通过,false:期限验证不通过
            var releaseDateCheck = true
            // 定义发行到期日  发行日+1个月
            var checkDate = this.subMonth(releaseDate)
            //定义工作日
            var workDateCount = 0
            //循环15次,总会有3次是工作日
            for (i in 1..15 step 1) {
                if (workDateCount == 3){
                    break
                }
                //判断"checkDate"的日期是否在配置的法定日期配置表中:
                var isExist=this.intDal<BizAbsProfitInfoServiceDal>().isPassDeadline(iwebReq = iwebReq, releaseDate =releaseDate)
                //查询结果为空
                if (!isExist ){
                    var format1 =  SimpleDateFormat("yyyy-mm-dd")
                    var bdate = format1.parse(checkDate)
                    var cal = Calendar.getInstance()
                    cal.setTime(bdate);
                    // 判断是否是周六或周日
                    if(cal.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY && cal.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY){
                        // 说明是工作日
                        workDateCount++
                    }
                    //加一天
                    checkDate =addOneDay(checkDate)
    
                }else{
                   if("w".equals(isExist)){
                      //是工作日
                       workDateCount++
                   }
                    //加一天
                    checkDate =addOneDay(checkDate)
                }
            }
            //string 转data
            var sdf =  SimpleDateFormat("yyyy-MM-dd");
           if (Date().time > sdf.parse(this.subDay(checkDate)).time){
               //说明超过时限
               releaseDateCheck = false
           }
           return releaseDateCheck
        }
    
        /****
         * 传入具体日期 ,返回具体日期增加一个月。
         * @param date 日期(2017-04-13)
         * @return 2017-05-13
         */
        fun   subMonth(date:String) :String{
            var sdf =  SimpleDateFormat("yyyy-MM-dd");
            var dt = sdf.parse(date)
            var rightNow = Calendar.getInstance()
            rightNow.setTime(dt)
            rightNow.add(Calendar.MONTH, 1)
            var dt1 = rightNow.getTime()
            var reStr = sdf.format(dt1)
            return reStr
        }
    
        /****
         * 传入具体日期 ,返回具体日期减少一天
         * @param date 日期(2017-04-13)
         * @return 2017-04-12
         * @throws ParseException
         */
        fun   subDay(date:String ):String  {
            var sdf =  SimpleDateFormat("yyyy-MM-dd");
            var dt = sdf.parse(date);
            var rightNow = Calendar.getInstance();
            rightNow.setTime(dt);
            rightNow.add(Calendar.DAY_OF_MONTH, -1);
            var dt1 = rightNow.getTime();
            var reStr = sdf.format(dt1);
            return reStr;
        }
    
    
        /****
         * 传入具体日期 ,返回具体日期减少一天
         * @param date 日期(2017-04-13)
         * @return 2017-04-12
         * @throws ParseException
         */
        fun   addOneDay(date:String ):String  {
            var sdf =  SimpleDateFormat("yyyy-MM-dd");
            var dt = sdf.parse(date);
            var rightNow = Calendar.getInstance();
            rightNow.setTime(dt);
            rightNow.add(Calendar.DAY_OF_MONTH, 1);
            var dt1 = rightNow.getTime();
            var reStr = sdf.format(dt1);
            return reStr;
        }
    
    
    
        /**
         * 添加收益信息表画面 中 (提交按钮的实现)
         * @param  coreEnterpriseId
         *                       核心企业(不允许为空)
         * @param financialInstitutionId
         *                       计划管理人ID(不允许为空)
         * @param periodsId
         *               期数id(不允许为空)
         * @param  information
         *                     信息(费用名称,备注,金额)
         * @param financeOpinion
         *                     意见(不允许为空)
         * @param  releaseDate
         *              发行日期(不允许为空)
         */
        fun getSubmit(iwebReq: IwebReq, subjectlist:List<AddOrRevisionIncomePoJo> , financeOpinion:String, releaseDate :String ,
                      coreEnterpriseId : String , financialInstitutionsId : String , periods : String  ): Boolean {
            //判断数据保存到表是否成功
            var isok=false
            if (coreEnterpriseId == null){
                AssertUtils.isTrue(false,"核心企业不能为空!")
            }
            if (financialInstitutionsId == null) {
                AssertUtils.isTrue(false, "计划管理人不能为空")
            }
            if (periods == null) {
                AssertUtils.isTrue(false, "期数不能为空")
            }
            if (financeOpinion == null) {
                AssertUtils.isTrue(false, "意见不能为空")
            }
            if (releaseDate == null) {
                AssertUtils.isTrue(false, "发行日期不能为空")
            }
            //判断当前保存的数据在数据库中是否存在
            var list =this.intDal<BizAbsProfitInfoServiceDal>().isExist(iwebReq = iwebReq,  coreEnterpriseId =coreEnterpriseId , financialInstitutionsId = financialInstitutionsId , periods =periods)
            //遍历financeOpinion
            //存在数据
            if (list != null){
                AssertUtils.isTrue(false, "当前添加的核心企业、金融机构、期数所对应的ABS收益信息已存在!")
            }else{
                //创造ABS收益信息表的实体对象
                var bizAbsProfitInfo = BizAbsProfitInfo()
                //设置核心企业id
                bizAbsProfitInfo.coreEnterpriseId = coreEnterpriseId
                //设置金融机构id
                bizAbsProfitInfo.financialInstitutionsId = financialInstitutionsId
                //设置期数
                bizAbsProfitInfo.periods = Integer.valueOf(periods)
                //设置金融部意见
                bizAbsProfitInfo.financeOpinion=financeOpinion
                // 发行日  release_date
                val format = SimpleDateFormat("yyyy-MM-dd")
                bizAbsProfitInfo.releaseDate=format.parse(releaseDate)
                //设置当前登录的用户
                bizAbsProfitInfo.addUserId= "123"
                       // AdminService().getUserInfo(iwebReq)!!.getStr("id")
                //设置当前时间
                var date = Date()
                var sdf =  SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                //获取当前时间
                bizAbsProfitInfo.addTime= Timestamp.valueOf(sdf.format(date))
                //设置状态00(没有提交审批)
                bizAbsProfitInfo.status="03"
                this.save(iwebReq = iwebReq, d = bizAbsProfitInfo)
                isok =  true
            }
                if (isok){
                    //再次查询获取刚保存的id
                    var lists=this.intDal<BizAbsProfitInfoServiceDal>().isExist(iwebReq = iwebReq,   coreEnterpriseId =coreEnterpriseId , financialInstitutionsId = financialInstitutionsId , periods =periods)
                    // 获取其中的id
                    var id =lists?.getStr("id")
                    for (content  in subjectlist!!){
                        //创造ABS收益明细表的实体对象
                        var bizAbsProfitDetail = BizAbsProfitDetail()
                        //获取费用名称,并设置进去
                        bizAbsProfitDetail.subjectId= content.subjectId
                        //获取金额
                        bizAbsProfitDetail.profit=content.profit
                        //获取备注
                        bizAbsProfitDetail.memo=content.memo
                        //设置获取的id
                        bizAbsProfitDetail.absProfitId= id
                        //  isTrue=dbp.merge("biz_abs_profit_detail",bizAbsProfitDetail)
                        this.save(iwebReq = iwebReq, d = bizAbsProfitDetail)
                        isok =true
                    }
                }
            return isok
        }
    
        /**
         * 添加收益信息表画面 中 (保存按钮的实现)
         * @param  coreEnterpriseId
         *                       核心企业(不允许为空)
         * @param financialInstitutionId
         *                       计划管理人ID(不允许为空)
         * @param periodsId
         *               期数id(不允许为空)
         * @param  information
         *                     信息(费用名称,备注,金额)
         * @param financeOpinion
         *                     意见
         * @param  releaseDate
         *              发行日期
         */
        fun saveWays(iwebReq: IwebReq, subjectlist:List<AddOrRevisionIncomePoJo> ?, financeOpinion:String? , releaseDate :String? ,
                     coreEnterpriseId : String , financialInstitutionsId : String , periods : String ): Boolean {
            if (coreEnterpriseId == null){
                AssertUtils.isTrue(false,"核心企业不能为空!")
            }
            if (financialInstitutionsId == null) {
                AssertUtils.isTrue(false, " 计划管理人不能为空")
            }
            if (periods == null) {
                AssertUtils.isTrue(false, " 期数不能为空")
            }
            //判断数据保存到表是否成功
            var isok = false
            var list= this.intDal<BizAbsProfitInfoServiceDal>().isExist(iwebReq = iwebReq, coreEnterpriseId =coreEnterpriseId , financialInstitutionsId = financialInstitutionsId , periods = periods)
            //存在数据
            if (list != null){
                AssertUtils.isTrue(false, "当前添加的核心企业、金融机构、期数所对应的ABS收益信息已存在!")
            }else{
                //创造ABS收益信息表的实体对象
                var bizAbsProfitInfo = BizAbsProfitInfo()
                //设置核心企业id
                bizAbsProfitInfo.coreEnterpriseId = coreEnterpriseId
                //设置金融机构id
                bizAbsProfitInfo.financialInstitutionsId = financialInstitutionsId
                //设置期数
                bizAbsProfitInfo.periods = Integer.valueOf(periods)
                //设置金融部意见
                bizAbsProfitInfo.financeOpinion = financeOpinion
                // 发行日  release_date
                val format = SimpleDateFormat("yyyy-MM-dd")
                bizAbsProfitInfo.releaseDate = format.parse(releaseDate)
                //设置当前登录的用户
                bizAbsProfitInfo.addUserId = iwebReq.userId.toString()
                    //    AdminService().getUserInfo(iwebReq)!!.getStr("id")
    
                //获取当前时间
                bizAbsProfitInfo.addTime = Date()
                //设置状态00(没有提交审批)
                bizAbsProfitInfo.status = "00"
                this.save(iwebReq = iwebReq,d = bizAbsProfitInfo)
                isok = true
            }
            if (isok){
                //再次查询获取刚保存的id
                var lists= this.intDal<BizAbsProfitInfoServiceDal>().isExist(iwebReq = iwebReq,  coreEnterpriseId = coreEnterpriseId , financialInstitutionsId = financialInstitutionsId , periods =periods)
                // 获取其中的id
                var id =lists?.getStr("id")
                //遍历financeOpinion
                for (content  in subjectlist!!){
                    //创造ABS收益明细表的实体对象
                    var bizAbsProfitDetail = BizAbsProfitDetail()
                    //获取费用名称,并设置进去
                    bizAbsProfitDetail.subjectId = content.subjectId
                    //获取金额
                    bizAbsProfitDetail.profit = content.profit
                    //获取备注
                    bizAbsProfitDetail.memo = content.memo
                    //设置获取的id
                    bizAbsProfitDetail.absProfitId = id
                    this.save(iwebReq = iwebReq, d = bizAbsProfitDetail)
                    // isTrue=dbp.merge("biz_abs_profit_detail",bizAbsProfitDetail)
                    isok = true
                }
            }
            return isok
        }
    
    
        /**
         * 依据表单ID获取表单项信息
         *  根据ABS收益信息表id获取收益共通信息
         * @param id
         *        表单id(ABS收益ID)
         * @return 表单项信息
         */
        fun getFormEarningsInformation(iwebReq: IwebReq, absProfitId: Long): Record{
            if (absProfitId == null){
                AssertUtils.isTrue(false,"ABS收益ID不能为空!")
            }
            //返回一个对象给前端
            var record= this.intDal<BizAbsProfitInfoServiceDal>().getFormEarningsInformation(iwebReq = iwebReq, absProfitId = absProfitId)
            return  record
        }
    
    
        /**
         * 依据表单ID获取表单项信息
         *  根据ABS收益ID获取对应科目信息
         * @param id
         *        表单id(ABS收益ID)
         * @return 表单项信息
         */
        fun getFormSubjectInformation(iwebReq: IwebReq, absProfitId: Long): List<Record> {
            if (absProfitId == null){
                AssertUtils.isTrue(false,"ABS收益ID不能为空!")
            }
            //返回一个集合
            var list : List<Record> = this.intDal<BizAbsProfitInfoServiceDal>().getFormSubjectInformation(iwebReq = iwebReq, absProfitId = absProfitId)
            //获取期数
            var  per =list.get(0).getStr("periods")
            var periods =Integer.parseInt(per) -1
            //获取金融机构
            var financialInstitutionsId=list.get(0).getStr("financialInstitutionsId")
            //获取核心企业
            var  coreEnterpriseId= list.get(0).getStr("coreEnterpriseId")
            //遍历集合
            for (li in list){
               //获取科目的id
               var  subjectId=li.getStr("subjectId")
                //查询上一期对应的金额
                var record : Record? = this.intDal<BizAbsProfitInfoServiceDal>().beforeMoney(iwebReq = iwebReq, periods = periods ,
                        financialInstitutionsId = financialInstitutionsId ,  coreEnterpriseId = coreEnterpriseId ,subjectId =subjectId)
                //获取上一期的金额
               var profit= record?.getStr("profit")
                if (profit == null ){
                    li.set("lastProfit","")
                }else{
                    li.set("lastProfit",profit)
                }
            }
            return  list
        }
    
    
    
    
        /**
         * 修改收益信息表画面中
         * 保存金融部收益信息
         * @param  absProfitId
         *          表单的id(ABS收益ID)
         *@param  releaseDate
         *         发行日期
         *@param  financeOpinion
         *         金融意见
         *@param   subjectlist
         *          科目ID(基础费用科目ID),收益明细ID,收益金额,备注
         */
        fun saveFinance(iwebReq: IwebReq, absProfitId: Long,releaseDate:String ? ,financeOpinion :String? ,
                        subjectlist :List<ModificationFinancialPoJo>? , bizAbsProfit:BizAbsProfitInfo):Boolean{
            if (absProfitId == null){
                AssertUtils.isTrue(false,"ABS收益ID不能为空!")
            }
            //创造ABS收益信息表的实体对象
            var bizAbsProfitInfo = BizAbsProfitInfo()
            //保存表单的id
            bizAbsProfitInfo.id = absProfitId
            //保存发行日期  string 转data
            val formatter = SimpleDateFormat("yyyy-MM-dd")
    //        var  releaseDate=
            bizAbsProfitInfo.releaseDate = formatter.parse(releaseDate)
            //保存金融部意见
            bizAbsProfitInfo.financeOpinion = financeOpinion
            //保存核心企业
            bizAbsProfitInfo.coreEnterpriseId = bizAbsProfit.coreEnterpriseId
            //保存金融机构
            bizAbsProfitInfo.financialInstitutionsId = bizAbsProfit.financialInstitutionsId
            //保存状态
            bizAbsProfitInfo.status = bizAbsProfit.status
            //保存用户id
            bizAbsProfitInfo.addUserId = iwebReq.userId.toString()
          //  this.merge(iwebReq = iwebReq, models = Model<BizAbsProfitInfo>())
            this.merge4T(iwebReq = iwebReq, tableName= "biz_abs_profit_info",datas =bizAbsProfitInfo)
            var isOk = false
            //遍历 subjectlist
            for(subject in subjectlist !!){
               var profitDetailId= subject.profitDetailId
                if (profitDetailId == null){
                    //创造ABS收益明细表的实体对象
                    var bizAbsProfitDetail = BizAbsProfitDetail()
                    //新增数据
                    bizAbsProfitDetail.subjectId = subject.subjectId
                    bizAbsProfitDetail.profit  = subject.profit
                    bizAbsProfitDetail.memo = subject.memo
                    bizAbsProfitDetail.absProfitId = absProfitId.toString()
                    this.merge4T(iwebReq = iwebReq, tableName= "biz_abs_profit_detail",datas =bizAbsProfitDetail)
                    isOk = true
                }else{
                    //创造ABS收益明细表的实体对象
                    var bizAbsProfitDetail = BizAbsProfitDetail()
                    //更新数据
                    bizAbsProfitDetail.subjectId = subject.subjectId
                    bizAbsProfitDetail.profit  = subject.profit
                    bizAbsProfitDetail.memo = subject.memo
                    bizAbsProfitDetail.id =  subject.profitDetailId!!.toLong()
                    bizAbsProfitDetail.absProfitId = absProfitId.toString()
                  //  this.merge(iwebReq = iwebReq, models = bizAbsProfitDetail as Model<*> )
                    this.merge4T(iwebReq = iwebReq, tableName= "biz_abs_profit_detail",datas =bizAbsProfitDetail)
                    isOk = true
                }
            }
            //调用新增的履历,逻辑的方法
            if (isOk){
                addSavaLogic(iwebReq,absProfitId,subjectlist , "0")
            }
    
            return  isOk
        }
    
    
        /**
         * 修改收益信息表画面中
         * 提交金融部收益信息
         * @param  absProfitId
         *          表单的id(ABS收益ID)
         *@param  releaseDate
         *         发行日期
         *@param  financeOpinion
         *         金融意见
         *@param   subjectlist
         *          科目ID(基础费用科目ID),收益明细ID,收益金额,备注
         */
        fun submitFinance(iwebReq: IwebReq, absProfitId: Long,releaseDate:String ? ,financeOpinion :String? ,
                        subjectlist :MutableList<ModificationFinancialPoJo>?,bizAbsProfit :BizAbsProfitInfo):Boolean{
            if (absProfitId == null){
                AssertUtils.isTrue(false,"ABS收益ID不能为空!")
            }
            //创造ABS收益信息表的实体对象
            var bizAbsProfitInfo = BizAbsProfitInfo()
    
            //保存表单的id
            bizAbsProfitInfo.id = absProfitId
            //保存发行日期  string 转data
            val formatter = SimpleDateFormat("yyyy-MM-dd")
            var  releaseDa=formatter.parse(releaseDate.toString())
            //  (Date)formatter.parseObject(releaseDate)
            bizAbsProfitInfo.releaseDate = releaseDa
            //保存金融部意见
            bizAbsProfitInfo.financeOpinion = financeOpinion
            //保存核心企业
            bizAbsProfitInfo.coreEnterpriseId = bizAbsProfit.coreEnterpriseId
            //保存金融机构
            bizAbsProfitInfo.financialInstitutionsId = bizAbsProfit.financialInstitutionsId
            //保存状态
            bizAbsProfitInfo.status = bizAbsProfit.status
            //保存用户id
            bizAbsProfitInfo.addUserId = iwebReq.userId.toString()
            //状态设置为03(等待审批)
            bizAbsProfitInfo.status = "03"
            this.merge4T(iwebReq = iwebReq, tableName= "biz_abs_profit_info",datas =bizAbsProfitInfo)
            var isOk = false
            //遍历 subjectlist
            for(subject in subjectlist !!){
                var profitDetailId= subject.profitDetailId
                if (profitDetailId == null){
                    //创造ABS收益明细表的实体对象
                    var bizAbsProfitDetail = BizAbsProfitDetail()
                    //新增数据
                    bizAbsProfitDetail.subjectId = subject.subjectId
                    bizAbsProfitDetail.profit  = subject.profit
                    bizAbsProfitDetail.memo = subject.memo
                    bizAbsProfitDetail.absProfitId = absProfitId.toString()
                 //   this.save(iwebReq = iwebReq, d = bizAbsProfitDetail)
                    this.merge4T(iwebReq = iwebReq, tableName= "biz_abs_profit_detail",datas =bizAbsProfitDetail)
                    isOk = true
                }else{
                    //创造ABS收益明细表的实体对象
                    var bizAbsProfitDetail = BizAbsProfitDetail()
                    //更新数据
                    bizAbsProfitDetail.subjectId = subject.subjectId
                    bizAbsProfitDetail.profit  = subject.profit
                    bizAbsProfitDetail.memo = subject.memo
                    bizAbsProfitDetail.id =  subject.profitDetailId!!.toLong()
                    bizAbsProfitDetail.absProfitId = absProfitId.toString()
                   // this.save(iwebReq = iwebReq, d = bizAbsProfitDetail)
                    this.merge4T(iwebReq = iwebReq, tableName= "biz_abs_profit_detail",datas =bizAbsProfitDetail)
                    isOk = true
                }
            }
            //调用新增的履历,逻辑的方法
            if (isOk){
                addSavaLogic(iwebReq,absProfitId,subjectlist , "1")
            }
            return  isOk
        }
    
    
        /**
         *修改页面的保存时候,增加的逻辑
         */
        @Before(Tx::class)
        fun addSavaLogic(iwebReq: IwebReq,absProfitId: Long,subjectlist :List<ModificationFinancialPoJo>?,submitState:String){
            //利用abs_profit_id 获取ABS收益审核结果表的审核数据
            var  isOk=this.intDal<BizAbsProfitInfoServiceDal>().addSavaLogic(iwebReq,absProfitId)
            //等于true时,证明存在审核数据
            if (isOk){
            // 若存在审核数据:
                //a、判断对应的 最大的履历编号对应的履历数据的提交状态:利用abs_profit_id 来查
                var recordHistory=this.intDal<BizAbsProfitInfoServiceDal>().bigNumberState(iwebReq,absProfitId)
                //若不存在履历 或者 提交状态是已提交,则新增对应的科目修改履历数据;
                if (recordHistory == null || recordHistory.getStr("submitState").equals("1")){
                    //遍历
                    for(subject in subjectlist !!){
                        // 科目ID
                        var subjectId = subject.subjectId
                        // 修改后的收益金额
                        var profit  = subject.profit
                        // 判断金额是否有修改,有修改时保存履历, 为true,有修改数据
                        if( this.intDal<BizAbsProfitInfoServiceDal>().profitModifyState(iwebReq,absProfitId,subjectId,profit)){
                           //创建ABS收益明细修改履历表实力对象
                           var bizAbsProfitModifyHistory= BizAbsProfitModifyHistory()
                            //新增保存
                            //保存 履历编号
                            if (recordHistory == null ){
                                bizAbsProfitModifyHistory.historyNo = 1
                            }else{
                                bizAbsProfitModifyHistory.historyNo = recordHistory.getStr("historyNo").toInt()+1
                            }
                            //保存abs收益ID
                            bizAbsProfitModifyHistory.absProfitId = absProfitId!!.toInt()
                            //保存科目id
                            bizAbsProfitModifyHistory.subjectId = subject.subjectId
                            //保存收益
                            bizAbsProfitModifyHistory.profit = subject.profit
                            //保存提交状态
                            bizAbsProfitModifyHistory.submitState = submitState.toInt()
                            //保存备注
                            bizAbsProfitModifyHistory.memo = subject.memo
                            this.save(iwebReq = iwebReq, d = bizAbsProfitModifyHistory)
                        }
                    }
                }
                //  b、若存在履历 且 提交状态是未提交:
                else  if (recordHistory != null && recordHistory.getStr("submitState").equals("0")){
                    //遍历
                    for(subject in subjectlist !!){
                        // 科目ID
                        var subjectId = subject.subjectId
                        // 修改后的收益金额
                        var profit  = subject.profit
                        // 判断金额是否有修改,有修改时保存履历, 为true,有修改数据
                        if( this.intDal<BizAbsProfitInfoServiceDal>().profitModifyState(iwebReq,absProfitId,subjectId,profit)) {
                            //查询该履历编号、ABS收益ID 下是否有该科目的履历
                            var isExist= this.intDal<BizAbsProfitInfoServiceDal>().isExistResume(iwebReq, recordHistory.getStr("historyNo").toInt(),absProfitId!!.toInt())
                            //如果存在
                            if (isExist != null ){
                                //创建ABS收益明细修改履历表实力对象
                                var bizAbsProfitModifyHistory= BizAbsProfitModifyHistory()
                                // 修改保存 ,需要id
                                //保存 履历编号
                                bizAbsProfitModifyHistory.historyNo = recordHistory.getStr("historyNo").toInt()
                                //保存abs收益ID
                                bizAbsProfitModifyHistory.absProfitId = absProfitId.toInt()
                                //保存科目id
                                bizAbsProfitModifyHistory.subjectId = subject.subjectId
                                //保存收益
                                bizAbsProfitModifyHistory.profit = subject.profit
                                //保存提交状态
                                bizAbsProfitModifyHistory.submitState = submitState.toInt()
                                //保存备注
                                bizAbsProfitModifyHistory.memo = subject.memo
                                //保存id(代表是修改)
                                bizAbsProfitModifyHistory.id = isExist.getStr("id").toLong()
                                this.save(iwebReq = iwebReq, d = bizAbsProfitModifyHistory)
                            }else{
                                //创建ABS收益明细修改履历表实力对象
                                var bizAbsProfitModifyHistory= BizAbsProfitModifyHistory()
                                // 新增保存 ,不需要id
                                //保存 履历编号
                                bizAbsProfitModifyHistory.historyNo = recordHistory.getStr("historyNo").toInt()
                                //保存abs收益ID
                                bizAbsProfitModifyHistory.absProfitId = absProfitId!!.toInt()
                                //保存科目id
                                bizAbsProfitModifyHistory.subjectId = subject.subjectId
                                //保存收益
                                bizAbsProfitModifyHistory.profit = subject.profit
                                //保存提交状态
                                bizAbsProfitModifyHistory.submitState = submitState.toInt()
                                //保存备注
                                bizAbsProfitModifyHistory.memo = subject.memo
                                this.save(iwebReq = iwebReq, d = bizAbsProfitModifyHistory)
                            }
                        }
                    }
                }
                //如果是提交,继续走下面这个逻辑
                if (submitState.equals("1")){
                    //4、修改画面提交时,将对应的最大编号的履历数据,的提交状态都改成已提交;
                    //获取对应的最大编号的履历数据中的id
                     var historyNo=recordHistory.getStr("historyNo")
                    var  recordList =this.intDal<BizAbsProfitInfoServiceDal>().getBigNumberResumeData(iwebReq,historyNo,absProfitId)
                    //遍历
                    for ( record in  recordList ){
                        //获取每次的id
                        var id = record.getStr("id")
                        //创建ABS收益明细修改履历表实例对象
                        var bizAbsProfitModifyHistory= BizAbsProfitModifyHistory()
                        bizAbsProfitModifyHistory.id= id.toLong()
                        bizAbsProfitModifyHistory.submitState = 1
                        bizAbsProfitModifyHistory.memo = record.getStr("memo")
                        this.save(iwebReq = iwebReq, d = bizAbsProfitModifyHistory)
                    }
                }
            }else{
                //等于false,证明没有数据,则不用保存履历
                return
            }
        }
    
    
    }
    package cn.szqhyf.qhyffs.app.fs.idal
    
    
    import club.newepoch.admin.app.sys.service.AdminService
    import club.newepoch.iweb.IwebConstant
    import club.newepoch.iweb.ext.IwebReq
    import club.newepoch.persistent.db.common.DbPro
    import club.newepoch.persistent.db.common.Page
    import club.newepoch.persistent.db.pojo.Record
    import club.newepoch.utils.AssertUtils
    import club.newepoch.utils.StringUtils
    import cn.szqhyf.qhyffs.app.fs.pojo.po.AddOrRevisionIncomePoJo
    import cn.szqhyf.qhyffs.app.fs.pojo.po.BizAbsProfitDetail
    import cn.szqhyf.qhyffs.app.fs.pojo.po.BizAbsProfitInfo
    
    import com.alibaba.fastjson.JSONObject
    import com.jfinal.core.PageInfo
    import org.json.JSONArray
    import java.sql.Timestamp
    import java.util.*
    import java.text.SimpleDateFormat
    
    
    
    
    /**
     *ABS收益表ServiceDal
     */
    open class BizAbsProfitInfoServiceDal :  QhyffsDal(){
    
        /**
         * ABS收益表管理一览画面
         * @param coreEnterpriseId
         *                       核心企业
         * @param financialInstitutionId
         *                       计划管理人
         * @param periods
         *              期数
         * @param bigPeriodsId
         *                       所属大区ID
         */
        fun pages(iwebReq: IwebReq, pageInfo: PageInfo, coreEnterpriseId:String ?, financialInstitutionsId:String?, periods:String? , bigPeriodsId :String? ): Page<Record>? {
            var dbp = DbPro.use(iwebReq.dsName)
            var pageIndex = pageInfo?.pageIndex ?: 1
            var pageSize = pageInfo?.pageSize ?: IwebConstant.DEFAULT_PAGE_SIZE
            var select= """
                      SELECT
                            a.id as abs_profit_id ,
                            a.core_enterprise_id,
                            a.financial_institutions_id,
                            a.periods,
                            a.status ,
                            c.id
                        """
            var from="""
                       FROM
                            biz_abs_profit_info a,
                            biz_big_periods_info c,
                            biz_periods_mapping_info b
                        WHERE
                            a.sys_status = 1
                        AND a.core_enterprise_id = c.core_enterprise_id
                        AND a.financial_institutions_id = c.financial_institutions_id
                        AND c.sys_status = 1
                        AND a.periods = b.periods
                        AND b.sys_status = 1
                        AND c.id = b.big_periods_id
                      """
            var paras = mutableListOf<Any>()
            //核心企业
            if(StringUtils.notBlank(coreEnterpriseId)  ){
                from += " AND a.core_enterprise_id = ? "
                var  coreEnterpriseId="${coreEnterpriseId?.trim()}"
                paras.add(coreEnterpriseId)
            }
            //金融机构
            if(StringUtils.notBlank(financialInstitutionsId) ){
                from += " AND a.financial_institutions_id = ? "
                var financialInstitutionsId="${financialInstitutionsId?.trim()}"
                paras.add(financialInstitutionsId)
            }
            //期数
            if(StringUtils.notBlank(periods) ){
                from += " AND a.periods = ? "
                var periods = "${periods?.trim()}"
                paras.add(periods.trim())
            }
            //所属大区
            if (StringUtils.notBlank(bigPeriodsId)){
                from += " AND c.id =  ? "
                var BelongsToRegional = "${bigPeriodsId?.trim()}"
                paras.add(BelongsToRegional)
            }
          // 设置所属大期
            var pageList=dbp.paginate(pageIndex,pageSize,select,from,*paras.toTypedArray<Any>())
            for (page  in pageList.list){
               //获取大期id
               var bigPeriodsId = page.getStr("id")
                //调用获取所属大期的方法
                 var  record = this.getPeriods(iwebReq,bigPeriodsId)
                page.set("bigPeriods",record!!.getStr("bigPeriods"))
            }
            return pageList
        }
    
        /**
         * 所属大期
         */
        fun getPeriods(iwebReq: IwebReq,bigPeriodsId :String ): Record? {
            var dbp = DbPro.use(iwebReq.dsName)
            var sql= """
                       SELECT
                            b.big_periods_id,
                            concat(
                                MIN(b.periods),
                                '~',
                                MAX(b.periods)
                            ) AS big_periods
                        FROM
                            biz_big_periods_info a
                        LEFT JOIN biz_periods_mapping_info b ON a.id = b.big_periods_id
                        WHERE
                            a.sys_status = 1
                        AND b.sys_status = 1
                        and b.big_periods_id = ?
                        GROUP BY
                            b.big_periods_id
                      """
            var list = dbp.findFirst(sql ,bigPeriodsId)
            return list
        }
    
    
        /**
         * ABS收益表画面一览 (所属大期)的获得方法
         */
        fun periods(iwebReq: IwebReq): List<Record>? {
            var dbp = DbPro.use(iwebReq.dsName)
            var sql= """
                       SELECT
                            b.big_periods_id,
                            concat(
                                MIN(b.periods),
                                '~',
                                MAX(b.periods)
                            ) AS big_periods
                        FROM
                            biz_big_periods_info a
                        LEFT JOIN biz_periods_mapping_info b ON a.id = b.big_periods_id
                        WHERE
                            a.sys_status = 1
                        AND b.sys_status = 1
                        GROUP BY
                            b.big_periods_id
                      """
            var list = dbp.find(sql)
         /*   val json = JSONArray()
            for ( li  in list  ){
                val jo = JSONObject()
                jo.put("bigPeriods",li.getStr("bigPeriods"))
                json.put(jo)
            }*/
    
            return list
    }
    
        /**
         * 添加收益信息表画面 中 (查询按钮)
         * @param  coreEnterpriseId
         *                       核心企业(不允许为空)
         * @param financialInstitutionId
         *                       计划管理人ID (不允许为空)
         * @param periodsId
         *           期数  (不允许为空)
    
         */
        fun getQuery(iwebReq: IwebReq, coreEnterpriseId:String , financialInstitutionsId:String , periods:String ): List<Record>? {
            var dbp = DbPro.use(iwebReq.dsName)
            var sql= """
                         SELECT
                            c.subject_id,
                            d.name
                        FROM
                            biz_big_periods_info a,
                            biz_periods_mapping_info b,
                            biz_fs_abs_relation c,
                            biz_financial_subjects d,
                            biz_financial_subjects_source e
                        WHERE
                        a.id = b.big_periods_id
                        AND a.id = c.abs_id
                        AND c.subject_id = d.id
                        AND d.source_id = e.id
                        AND a.core_enterprise_id = trim(?)
                        AND a.financial_institutions_id = trim(?)
                        AND b.periods = trim(?)
                        AND e.type in(3,4)
                        AND a.sys_status = 1
                        AND b.sys_status= 1
                        AND c.sys_status=1
                        AND d.sys_status=1
                        AND e.sys_status=1
                      """
            var list = dbp.find(sql,coreEnterpriseId,financialInstitutionsId,periods)
            return list
        }
    
        /**
         * 添加收益信息表画面中 (判断是否跳期的判断依准)
         * @param  coreEnterpriseId
         *                       核心企业(不允许为空)
         * @param financialInstitutionId
         *                       计划管理人ID (不允许为空)
         * @param periodsId
         *           期数 (不允许为空)
         */
        fun isjumpPeriods(iwebReq: IwebReq, coreEnterpriseId:String , financialInstitutionsId:String , periods:String ): List<Record>? {
            var dbp = DbPro.use(iwebReq.dsName)
            if (Integer.valueOf(periods) - 1 > 0){
                var jumpSql= """
                            SELECT
                                a.id
                            FROM
                                biz_abs_profit_info a
                            WHERE
                                a.core_enterprise_id = ?
                                AND a.financial_institutions_id = ?
                                AND a.periods = (? - 1)
                                AND a.sys_status = 1
                           """
    
              var record=  dbp.find(jumpSql,coreEnterpriseId,financialInstitutionsId,periods)
                return record
            }else{
                return null
            }
    
        }
    
        /**
         * 根据发行日判断是否超过提交期限
         * @param releaseDate
         *         发行日(不能为空)
         */
        fun isPassDeadline(iwebReq: IwebReq,releaseDate: String  ): Boolean {
            var isOk= true
            var dbp = DbPro.use(iwebReq.dsName)
            var sql="""
                     SELECT
                        a.date_type
                    FROM
                        biz_legal_date_configure a
                    WHERE
                        a.legal_date = ?
                    AND a.sys_status = 1
                """
            var release=dbp.findFirst(sql,releaseDate)
            if(release == null){
                 isOk=false
            }
            return isOk
        }
    
        /**
         * 添加收益信息表画面 中 (判断当前保存的数据在数据库中是否存在)
         * @param  coreEnterpriseId
         *                       核心企业(不允许为空)
         * @param financialInstitutionId
         *                       计划管理人ID(不允许为空)
         * @param periodsId
         *               期数id(不允许为空)
         */
        fun isExist(iwebReq: IwebReq, coreEnterpriseId : String , financialInstitutionsId : String , periods :String ): Record? {
            var dbp = DbPro.use(iwebReq.dsName)
            //判断当前保存的数据在数据库中是否存在
            var  sql= """
                    SELECT
                        a.id
                    FROM
                        biz_abs_profit_info a
                    WHERE
                        a.core_enterprise_id = ?
                        AND a.financial_institutions_id = ?
                        AND a.periods = ?
                        AND a.sys_status = 1
                """
            var list= dbp.findFirst(sql,coreEnterpriseId , financialInstitutionsId ,periods)
            return list
        }
    
        /**
         * 依据表单ID获取表单项信息(修改页面)
         *  根据ABS收益信息表id获取收益共通信息
         * @param absProfitId
         *     表单的id(ABS收益ID)
         * @return 表单项信息
         */
        fun getFormEarningsInformation(iwebReq: IwebReq, absProfitId: Long?): Record{
            var dbp = DbPro.use(iwebReq.dsName)
            var  sql="""
                          SELECT
                            core_enterprise_id,
                            financial_institutions_id,
                            periods,
                            finance_opinion,
                            release_date
                        FROM
                            biz_abs_profit_info
                        WHERE
                            id = ?
                            AND sys_status =1
                      """
           var record= dbp.findFirst(sql,absProfitId)
    
           var  releaseDate =record.getDate("releaseDate").toString()
            record.set("releaseDate",releaseDate)
            return  record
        }
    
    
        /**
         * 依据表单ID获取表单项信息(修改页面)
         * 根据ABS收益ID获取对应科目信息
         * @param absProfitId
         *     表单的id(ABS收益ID)
         * @return 表单项信息
         */
        fun getFormSubjectInformation(iwebReq: IwebReq, absProfitId: Long): List<Record>{
            var dbp = DbPro.use(iwebReq.dsName)
            var  sql="""
                      SELECT
                        c.subject_id,
                        d.name,
                        g.id AS profit_detail_id,
                        g.profit,
                        g.memo,
                        f.periods,
                        f.core_enterprise_id,
                        f.financial_institutions_id
                    FROM
                        biz_big_periods_info a,
                        biz_periods_mapping_info b,
                        biz_financial_subjects d,
                        biz_financial_subjects_source e,
                        biz_abs_profit_info f,
                        biz_fs_abs_relation c
                    LEFT JOIN biz_abs_profit_detail g ON g.abs_profit_id = ?
                    AND g.sys_status = 1
                    AND c.subject_id = g.subject_id
                    WHERE
                        a.id = b.big_periods_id
                    AND a.id = c.abs_id
                    AND c.subject_id = d.id
                    AND d.source_id = e.id
                    AND a.core_enterprise_id = f.core_enterprise_id
                    AND a.financial_institutions_id = f.financial_institutions_id
                    AND b.periods = f.periods
                    AND f.id = ?
                    AND e.type IN (3, 4)
                    AND a.sys_status = 1
                    AND b.sys_status = 1
                    AND c.sys_status = 1
                    AND d.sys_status = 1
                    AND e.sys_status = 1
                    AND f.sys_status = 1
                    """
            var list=dbp.find(sql,absProfitId,absProfitId)
            return  list
        }
    
        /**
         * 获取上一期对应的金额
         */
      fun  beforeMoney(iwebReq: IwebReq, coreEnterpriseId: String , financialInstitutionsId : String ,
                        periods: Int , subjectId : String): Record?{
            var dbp = DbPro.use(iwebReq.dsName)
            var  sql =  """
                        SELECT
                            b.profit
                        FROM
                            biz_abs_profit_info a,
                            biz_abs_profit_detail b
                        WHERE
                            a.id = b.abs_profit_id
                            AND a.sys_status = 1
                            AND b.sys_status = 1
                            AND a.core_enterprise_id = ?
                            AND a.financial_institutions_id = ?
                            AND a.periods = ?
                            AND b.subject_id = ?
                 """
            var record= dbp.findFirst(sql,coreEnterpriseId,financialInstitutionsId , periods , subjectId)
            return  record
        }
    
        /**
         * 根据abs_profit_id获取ABS收益审核结果表的审核数据
         */
        fun  addSavaLogic(iwebReq: IwebReq, absProfitId: Long?): Boolean{
            //判断是否数据
            var isOk = false
            var dbp = DbPro.use(iwebReq.dsName)
            var  sql =  """
                        SELECT
                            id
                        FROM
                            biz_abs_profit_approve_result
                        WHERE
                            abs_profit_id = ?
                             AND sys_status = 1
                 """
            var record= dbp.find(sql,absProfitId)
            //等于true,有数据,等于false,没有数据
            if(record.size > 0){
                  isOk = true
            }
            return  isOk
        }
    
    
    
        /**
         * 判断对应的 最大的履历编号对应的履历数据的提交状态:利用abs_profit_id 来查
         */
        fun  bigNumberState(iwebReq: IwebReq, absProfitId: Long?): Record{
            //判断是否数据
            var isOk = false
            var dbp = DbPro.use(iwebReq.dsName)
            var  sql =  """
                        SELECT
                            id,
                        history_no,
                        submit_state
                        FROM
                            biz_abs_profit_modify_history
                        WHERE
                            abs_profit_id = ?
                            AND sys_status = 1
                        ORDER BY history_no DESC
                    """
            var record= dbp.findFirst(sql,absProfitId)
            return  record
        }
    
    
    
        /**
         * 根据abs_profit_id、科目ID判断是否修改了金额
         */
        fun  profitModifyState(iwebReq: IwebReq, absProfitId: Long?, subjectId: Int?, profit: Double?): Boolean{
            //判断是否修改数据
            var isOk = true
            var dbp = DbPro.use(iwebReq.dsName)
            var  sql =  """
                        SELECT
                            id,profit
                        FROM
                            biz_abs_profit_detail
                        WHERE
                            abs_profit_id = ?
                            and subject_id = ?
                             and sys_status = 1
                 """
            var record= dbp.findFirst(sql,absProfitId, subjectId)
            // 等于true,有修改数据,等于false, 没有修改数据
            if(record !=null && record.getStr("profit").equals(profit)){
                isOk = false
            }
            return  isOk
        }
    
    
        /**
         * 查询该履历编号、ABS收益ID 下是否有该科目的履历
    
         */
        fun  isExistResume(iwebReq: IwebReq, historyNo: Int, absProfitId: Int):Record{
            var dbp = DbPro.use(iwebReq.dsName)
            var  sql =  """
                        SELECT
                            id
                        FROM
                            biz_abs_profit_modify_history
                        WHERE
                            abs_profit_id = ?
                            and history_no = ?
                            and sys_status = 1
                 """
            var record= dbp.findFirst(sql,absProfitId, historyNo)
            return  record
        }
    
        /**
         * 获取对应的最大编号的履历数据
         */
        fun  getBigNumberResumeData (iwebReq: IwebReq,historyNo: String,absProfitId:Long ):List<Record>{
            var dbp = DbPro.use(iwebReq.dsName)
            //利用最大的履历编号,查询对应的id
            var idSql ="""
                    SELECT
                        id,
                        memo
                    FROM
                        biz_abs_profit_modify_history
                    WHERE
                        history_no = ?
                        and abs_profit_id = ?
                        and submit_state = 0
                        and sys_status = 1
                    """
           var recordList = dbp.find(idSql,historyNo,absProfitId)
            return  recordList
        }
    
    
    
    }
  • 相关阅读:
    Win32基础知识2 Win32汇编语言003
    Win32基础知识4 Win32汇编语言005
    Win32基础知识4 Win32汇编语言005
    第一个程序 零基础入门学习Delphi01
    Mysql四种通信协议(linux下本地连接的都是socket 其他都是tcp)
    Rhino
    Common Gateway Interface Python CGI编程
    inaccessible
    mysqli_report
    算法功底网站性能瓶颈
  • 原文地址:https://www.cnblogs.com/xiaoniuniu886/p/10109367.html
Copyright © 2020-2023  润新知