SysLicenseServiceImpl.java 3.93 KB
package com.zteits.sys.biz;

import com.alibaba.fastjson.JSONObject;
import com.clouds.common.log.LogSelf;
import com.clouds.common.utils.LogSelfFactory;
import com.zteits.clouds.api.apibase.bean.BizResult;
import com.zteits.clouds.api.apibase.constants.DataStatusEnum;
import com.zteits.clouds.api.dto.sys.SysLicenseDTO;
import com.zteits.clouds.api.dto.sys.param.QuerySysLicenseByOrgIdReq;
import com.zteits.clouds.api.dto.sys.param.SaveSysLicenseReq;
import com.zteits.clouds.api.service.sys.SysLicenseService;
import com.zteits.sys.domain.SysLicense;
import com.zteits.sys.domain.SysLicenseExample;
import com.zteits.sys.mapper.SysLicenseMapper;
import com.zteits.sys.mapper.smapper.SysLicenseSmapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * Copyright: Copyright (c) 2017  zteits
 *
 * @ClassName: SysLicenseServiceImpl.java
 * @Description:
 * @version: v1.0.0
 * @author: wangfs
 * @date: 2019-06-11 16:15
 * Modification History:
 * Date             Author          Version            Description
 * ---------------------------------------------------------*
 * 2019-06-11     wangfs              v1.0.0               创建
 */
@Service("com.zteits.sys.biz.SysLicenseServiceImpl")
public class SysLicenseServiceImpl implements SysLicenseService {

    private static final LogSelf logger = LogSelfFactory.getLogSelf(SysLicenseServiceImpl.class);
    @Autowired
    private SysLicenseMapper sysLicenseMapper;

    @Autowired
    private SysLicenseSmapper sysLicenseSmapper;



    @Override
    public BizResult<SysLicenseDTO> querySysLicenseByOrgId(QuerySysLicenseByOrgIdReq req) {
        logger.info("begin通过组织ID获取License,入参={}", JSONObject.toJSON(req));
        SysLicenseDTO sysLicenseDTO = new SysLicenseDTO();
        SysLicenseExample example = new SysLicenseExample();
        example.createCriteria().andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value())
                .andOrgIdEqualTo(req.getOrgId());
        List<SysLicense> list = sysLicenseMapper.selectByExampleWithBLOBs(example);
        logger.info("通过组织ID获取License对象为={}", JSONObject.toJSON(list));
        if(!CollectionUtils.isEmpty(list)){
            BeanUtils.copyProperties(list.get(0),sysLicenseDTO);
        }
        logger.info("end通过组织ID获取LicenseDTO对象={}", JSONObject.toJSON(sysLicenseDTO));
        return new BizResult<SysLicenseDTO>(sysLicenseDTO);
    }

    @Override
    public BizResult<Boolean> updateSysLicenseByOrgId(SaveSysLicenseReq req) {
        logger.info("begin通过组织ID更新License,入参={}", JSONObject.toJSON(req));
        int i =0;
        SysLicenseExample example = new SysLicenseExample();
        example.createCriteria().andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value())
                .andOrgIdEqualTo(req.getOrgId());
        List<SysLicense> list = sysLicenseMapper.selectByExampleWithBLOBs(example);

        SysLicense record = new SysLicense();
        record.setLicense(req.getLicense());
        record.setOrgId(req.getOrgId());
        record.setModfiyDate(new Date());
        record.setModfiyEmpid(req.getModfiyEmpid());

        if(CollectionUtils.isEmpty(list) && list.size()==0){
            record.setDataState(DataStatusEnum.DATA_STATUS_VALID.value());
            record.setCreateDate(new Date());
            record.setCreateEmpid(req.getModfiyEmpid());
            i = sysLicenseMapper.insert(record);
            logger.info("end通过组织没有查询到执行,插入条数={}条.", i);
        }else{
            i = sysLicenseSmapper.updateLicenseByOrgId(record);
            logger.info("end通过组织ID更新License,更新条数={}条.", i);
        }

        return new BizResult<Boolean>(i >0);
    }
}