package com.tofly.feesapi.znbgl.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tofly.feesapi.bjgl.entity.YhCbkxx;

import com.tofly.feesapi.security.util.SecurityUtils;
import com.tofly.feesapi.yhgl.entity.YhKhjbxx;
import com.tofly.feesapi.znbgl.entity.ZnbDaLog;
import com.tofly.feesapi.znbgl.mapper.ZnbDaLogMapper;
import com.tofly.feesapi.znbgl.service.ZnbDaLogService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 智能表档案明细 服务实现类
 */
@Service
public class ZnbDaLogServiceImpl extends ServiceImpl<ZnbDaLogMapper, ZnbDaLog> implements ZnbDaLogService {

    @Override
    @Transactional(rollbackFor = Exception.class) //声明式事务管理
    public boolean addznbDaLog(YhKhjbxx yhKhjbxx, YhCbkxx yhCbkxx, String jdlx) {
        ZnbDaLog znbDaLog = new ZnbDaLog();
        znbDaLog.setYhbh(yhKhjbxx.getYhbh());//用户编号
        znbDaLog.setYhxm(yhKhjbxx.getYhxm());//用户姓名
        znbDaLog.setYhdz(yhKhjbxx.getYhdz());//用户地址
        znbDaLog.setLxdh(yhKhjbxx.getLxdh());//联系电话
        znbDaLog.setSsgs(yhKhjbxx.getSsgs());//所属公司
        znbDaLog.setSscbpq(yhKhjbxx.getSscbpq());//片区
        znbDaLog.setSscbb(yhKhjbxx.getSscbb());//抄表本
        znbDaLog.setJdrq(yhKhjbxx.getJdrq());//建档日期
        znbDaLog.setPch(yhKhjbxx.getJdpcxlh());//建档批次号

        //znbDaLog.setYhlx("");


        znbDaLog.setCbkh(yhCbkxx.getCbkh());//抄表卡号
        znbDaLog.setCbkid(yhCbkxx.getCbkid());//抄表卡ID

        znbDaLog.setJgbm(yhCbkxx.getSjbm());//价格编码
        znbDaLog.setJgbm1(yhCbkxx.getSjbm1());//价格编码1
        znbDaLog.setJgbm2(yhCbkxx.getSjbm2());//价格编码2
        znbDaLog.setSccj(yhCbkxx.getSbsccj());//厂家
        znbDaLog.setBjbh(yhCbkxx.getSbbh());//表具编号
        znbDaLog.setBjwz(yhCbkxx.getBjwz());//位置
        znbDaLog.setBjkj(yhCbkxx.getSbkj());//口径
        znbDaLog.setCbpl(yhCbkxx.getCbpl());//抄表频率
        znbDaLog.setXbqs(BigDecimal.valueOf(Long.valueOf(yhCbkxx.getSbqs())));//新表起数
        znbDaLog.setIckid(yhCbkxx.getIckid());
        znbDaLog.setXkcs(yhCbkxx.getXkcs());
        znbDaLog.setBkcs(yhCbkxx.getBkcs());
        znbDaLog.setBjjdrq(new Date());//表具定检日期

        if (jdlx.equals("2")) {
            znbDaLog.setJbbh("");//旧表编号
            znbDaLog.setJbzs(BigDecimal.ZERO);//旧表止数
        }
        znbDaLog.setYhye(BigDecimal.ZERO);//用户余额

        znbDaLog.setJdlx(jdlx);//建档类型（0：建档；1：变更；2：换表）
        znbDaLog.setCzry(String.valueOf(SecurityUtils.getUserId()));//操作人员编码
        znbDaLog.setCzsj(new Date());//操作时间
        znbDaLog.setClLock("0");
        znbDaLog.setClCljg("0");

        return this.save(znbDaLog);
    }

}
