package com.zjrs.zwnw.zj.bpo.impl;

import org.mohrss.leaf.core.framework.domain.bpo.impl.BPOImpl;
import org.mohrss.leaf.core.framework.web.controller.AjaxResponse;
import com.zjrs.zwnw.zj.blo.InitBLO;
import com.zjrs.zwnw.zj.bpo.InitBPO;
import com.zjrs.zwnw.zj.dto.InitDTO;
import com.zjrs.zwnw.zj.po.InitPO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

@Service
public class InitBPOImpl  extends BPOImpl implements InitBPO {

    @Resource
    private InitBLO initBLO;
    @Override
    public AjaxResponse save(InitDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        InitPO initPO = new InitPO();
        BeanUtils.copyProperties(dto, initPO);
        int cnt=initBLO.getCnt();
        if(cnt>0){
            InitPO oldPo=initBLO.getInfo();
            if(!initPO.getNd().equals(oldPo.getNd())){
                cnt=initBLO.queryIsTb();
                if(cnt>0){
                    ajaxResponse.setAppcode("1");
                    ajaxResponse.setErrorMsg("已存在“全市专业技术人才” 或 “全市博士数据” 或 “全市博士后” 或 “全市突出贡献专家、享受国务院津贴”数据，不可修改年度");
                    return ajaxResponse;
                }
            }
        }
        Long num1=Long.parseLong(dto.getNl40ubs())+Long.parseLong(dto.getNl40dbs());
        Long num2=Long.parseLong(dto.getZybs())+Long.parseLong(dto.getSsbs());
        if(num1!=num2){
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("“40周岁（含）以上博士”+“40周岁以下博士” 必须等于 “中央、省驻湛单位博士”+“市属单位博士”");
            return ajaxResponse;
        }
        num1=Long.parseLong(dto.getNl40ubsh())+Long.parseLong(dto.getNl40dbsh());
        num2=Long.parseLong(dto.getZybsh())+Long.parseLong(dto.getSsbsh());
        if(num1!=num2){
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("“40周岁（含）以上博士后”+“40周岁以下博士后” 必须等于 “中央、省驻湛单位博士后”+“市属单位博士后”");
            return ajaxResponse;
        }
        initBLO.save(initPO);
        return ajaxResponse;
    }

    @Override
    public AjaxResponse getInfo() {
        AjaxResponse ajaxResponse = new AjaxResponse();
        InitPO initPO = initBLO.getInfo();
        ajaxResponse.setData("data",initPO);
        return ajaxResponse;
    }

    @Override
    public AjaxResponse queryIsTb() {
        AjaxResponse ajaxResponse = new AjaxResponse();
        int cnt=initBLO.queryIsTb();
        ajaxResponse.setData("tbCnt",cnt);
        return ajaxResponse;
    }
}
