package org.jeecg.modules.sjly.service.impl;

import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.sjly.entity.CsXxSjly;
import org.jeecg.modules.sjly.service.impl.CsXxSjlyServiceImpl;
import org.jeecg.modules.sjly.entity.CsXxSjly;
import org.jeecg.modules.sjly.mapper.CsXxSjlyMapper;
import org.jeecg.modules.sjly.service.ICsXxSjlyService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Date;

/**
 * @Description: 数据来源
 * @Author: jeecg-boot
 * @Date:   2023-12-13
 * @Version: V1.0
 */
@Service
public class CsXxSjlyServiceImpl extends ServiceImpl<CsXxSjlyMapper, CsXxSjly> implements ICsXxSjlyService {
    /**
     * 初始化数据来源枚举类型
     */
    enum IntiSjlyEnum {
        sglr ("手工录入","sglr"),
        djdr ("单据导入","djdr"),
        fpxf ("发票修复","fpxf");
        private final String desc;//描述
        private final String value;//值
        IntiSjlyEnum(String desc, String value) {
            this.desc = desc;
            this.value = value;
        }

        public String getDesc() {
            return desc;
        }

        public String getValue() {
            return value;
        }

    }

    /**
     * 在新增加账套租户时初试化系统内置的数据来源
     * @param tenantId
     */
    public void initSjly(int tenantId){
        for(CsXxSjlyServiceImpl.IntiSjlyEnum sjlyEnum : CsXxSjlyServiceImpl.IntiSjlyEnum.values()){
            CsXxSjly csXxSjly=new CsXxSjly();
            csXxSjly.setCcode(sjlyEnum.getValue());
            csXxSjly.setCname(sjlyEnum.getDesc());
            csXxSjly.setCdesc("系统内置请误删除");
            csXxSjly.setTenantId(tenantId);
            LoginUser user=(LoginUser) SecurityUtils.getSubject().getPrincipal();
            if(user!=null){
                csXxSjly.setCreateBy(user.getUsername());
                csXxSjly.setSysOrgCode(user.getOrgCode());
            }
            csXxSjly.setCreateTime(new Date());
            this.save(csXxSjly);
        }
    }
}
