package com.doumee.service.business.impl; 
 | 
  
 | 
import com.doumee.biz.system.SystemDictDataBiz; 
 | 
import com.doumee.core.constants.ResponseStatus; 
 | 
import com.doumee.core.exception.BusinessException; 
 | 
import com.doumee.core.model.LoginUserInfo; 
 | 
import com.doumee.core.model.PageData; 
 | 
import com.doumee.core.model.PageWrap; 
 | 
import com.doumee.core.utils.Constants; 
 | 
import com.doumee.core.utils.Utils; 
 | 
import com.doumee.dao.business.WebParamMapper; 
 | 
import com.doumee.dao.business.model.WebParam; 
 | 
import com.doumee.dao.system.dto.UpdateWebParamDTO; 
 | 
import com.doumee.service.business.WebParamService; 
 | 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 
 | 
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; 
 | 
import com.baomidou.mybatisplus.core.metadata.IPage; 
 | 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 
 | 
import org.apache.commons.lang3.StringUtils; 
 | 
import org.apache.shiro.SecurityUtils; 
 | 
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.Date; 
 | 
import java.util.List; 
 | 
import java.util.Objects; 
 | 
  
 | 
/** 
 | 
 * 企业页面配置信息表Service实现 
 | 
 * @author 江蹄蹄 
 | 
 * @since 2023/09/12 11:18 
 | 
 */ 
 | 
@Service 
 | 
public class WebParamServiceImpl implements WebParamService { 
 | 
  
 | 
    @Autowired 
 | 
    private WebParamMapper webParamMapper; 
 | 
  
 | 
    @Autowired 
 | 
    private SystemDictDataBiz systemDictDataBiz; 
 | 
  
 | 
    @Override 
 | 
    public WebParam findOne() { 
 | 
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); 
 | 
        QueryWrapper<WebParam> wrapper = new QueryWrapper<>(); 
 | 
        wrapper.eq("COMPANY_ID",user.getCompanyId()); 
 | 
        wrapper.last(" limit 1  "); 
 | 
        WebParam webParam = webParamMapper.selectOne(wrapper); 
 | 
        if(!Objects.isNull(webParam)){ 
 | 
            webParam.setResourcePath(systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode() + 
 | 
                    systemDictDataBiz.queryByCode(Constants.OSS,Constants.WEB_PARAM).getCode()); 
 | 
        }else{ 
 | 
            webParam = new WebParam(); 
 | 
            webParam.setResourcePath(systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode() + 
 | 
                    systemDictDataBiz.queryByCode(Constants.OSS,Constants.WEB_PARAM).getCode()); 
 | 
            webParam.setBgImg(systemDictDataBiz.queryByCode(Constants.WEB_PARAM,Constants.BG_IMG).getCode()); 
 | 
            webParam.setTopImg(systemDictDataBiz.queryByCode(Constants.WEB_PARAM,Constants.TOP_IMG).getCode()); 
 | 
            webParam.setPkImg(systemDictDataBiz.queryByCode(Constants.WEB_PARAM,Constants.PK_IMG).getCode()); 
 | 
            webParam.setMainColor(systemDictDataBiz.queryByCode(Constants.WEB_PARAM,Constants.MAIN_COLOR).getCode()); 
 | 
            webParam.setRangeSize(systemDictDataBiz.queryByCode(Constants.WEB_PARAM,Constants.RANGE_SIZE).getCode()); 
 | 
        } 
 | 
        return webParam; 
 | 
    } 
 | 
  
 | 
    @Override 
 | 
    public WebParam findOneNew() { 
 | 
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); 
 | 
        QueryWrapper<WebParam> wrapper = new QueryWrapper<>(); 
 | 
        wrapper.lambda().eq(WebParam::getCompanyId,user.getCompanyId()); 
 | 
        wrapper.last(" limit 1  "); 
 | 
        WebParam webParam = webParamMapper.selectOne(wrapper); 
 | 
        return webParam; 
 | 
    } 
 | 
  
 | 
  
 | 
    @Override 
 | 
    public void renew(UpdateWebParamDTO updateWebParamDTO) { 
 | 
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); 
 | 
        QueryWrapper<WebParam> wrapper = new QueryWrapper<>(); 
 | 
        wrapper.eq("COMPANY_ID",user.getCompanyId()); 
 | 
        wrapper.last(" limit 1  "); 
 | 
        WebParam webParam = webParamMapper.selectOne(wrapper); 
 | 
        if(Objects.isNull(webParam)){ 
 | 
            webParam = new WebParam(); 
 | 
            BeanUtils.copyProperties(updateWebParamDTO,webParam); 
 | 
            webParam.setCreateTime(new Date()); 
 | 
            webParam.setDeleted(Constants.ZERO); 
 | 
            webParam.setCompanyId(user.getCompanyId()); 
 | 
            webParam.setCreateUser(user.getId()); 
 | 
            webParamMapper.insert(webParam); 
 | 
        }else{ 
 | 
            BeanUtils.copyProperties(updateWebParamDTO,webParam); 
 | 
            webParam.setUpdateUser(user.getId()); 
 | 
            webParam.setUpdateTime(new Date()); 
 | 
            webParamMapper.updateById(webParam); 
 | 
        } 
 | 
    } 
 | 
    @Override 
 | 
    public void  renewUpdate(UpdateWebParamDTO updateWebParamDTO){ 
 | 
        if(StringUtils.isBlank(updateWebParamDTO.getNewParam())){ 
 | 
            throw  new BusinessException(ResponseStatus.BAD_REQUEST); 
 | 
        } 
 | 
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); 
 | 
        QueryWrapper<WebParam> wrapper = new QueryWrapper<>(); 
 | 
        wrapper.lambda().eq(WebParam::getCompanyId,user.getCompanyId()); 
 | 
        wrapper.last(" limit 1  "); 
 | 
        WebParam webParam = webParamMapper.selectOne(wrapper); 
 | 
        if(Objects.isNull(webParam)){ 
 | 
            webParam = new WebParam(); 
 | 
            BeanUtils.copyProperties(updateWebParamDTO,webParam); 
 | 
            webParam.setCreateTime(new Date()); 
 | 
            webParam.setDeleted(Constants.ZERO); 
 | 
            webParam.setCompanyId(user.getCompanyId()); 
 | 
            webParam.setCreateUser(user.getId()); 
 | 
            webParamMapper.insert(webParam); 
 | 
        }else{ 
 | 
            BeanUtils.copyProperties(updateWebParamDTO,webParam); 
 | 
            webParam.setUpdateUser(user.getId()); 
 | 
            webParam.setUpdateTime(new Date()); 
 | 
            webParamMapper.updateById(webParam); 
 | 
        } 
 | 
    } 
 | 
  
 | 
} 
 |