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

import com.tofly.common.core.util.StringUtil;
import com.tofly.feesapi.security.util.SecurityUtils;
import com.tofly.feesapi.xtgl.entity.Syscommlog;
import com.tofly.feesapi.xtgl.mapper.SyscommlogMapper;
import com.tofly.feesapi.xtgl.service.ISyscommlogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Slf4j
@Service
public class SyscommlogServiceImpl extends ServiceImpl<SyscommlogMapper, Syscommlog> implements ISyscommlogService {

    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    @Override
    public void ymjzsfdyrz(int total, int cgs) {
        log.info("调用算费，成功{}条，失败{}条", total, cgs);
        Syscommlog syscommlog = new Syscommlog();
        syscommlog.setTablename("yy_qfmx");
        syscommlog.setMstext("月末结转调用cbymjzTask");
        syscommlog.setAddate(LocalDateTime.now().format(formatter));
        syscommlog.setRemark(String.format("调用算费，成功%s条，失败%s条", total, cgs));
        syscommlog.setUserid("YMJZ");
        this.save(syscommlog);
    }

    @Override
    public void xz(String tablename, String mstext, String remark, String userid) {
        String addate = LocalDateTime.now().format(formatter);
        Syscommlog syscommlog = new Syscommlog();
        syscommlog.setTablename(tablename);
        syscommlog.setMstext(mstext);
        syscommlog.setAddate(addate);
        syscommlog.setRemark(remark);
        syscommlog.setUserid(userid);
        this.save(syscommlog);
    }
    @Override
    public void LogSave(String Tablename, String Context, String optype, String remark, String userid) {
        Syscommlog syscommlog = new Syscommlog();
        if (StringUtil.isEmpty(userid)) {
            syscommlog.setUserid(SecurityUtils.getUserId().toString());
        } else {
            syscommlog.setUserid(userid);
        }
        String addate = LocalDateTime.now().format(formatter);
        syscommlog.setAddate(addate);
        syscommlog.setTablename(Tablename);
        syscommlog.setMstext(Context);
        syscommlog.setOptype(optype);
        syscommlog.setRemark(remark);
        this.save(syscommlog);
    }
}
