TEnterpriseInfoServiceImpl.java 6.64 KB
Newer Older
1 2 3 4
package com.zehong.system.service.impl;

import java.util.ArrayList;
import java.util.List;
5 6
import java.util.Objects;

7
import com.zehong.common.core.domain.entity.SysUser;
8
import com.zehong.common.exception.BaseException;
9
import com.zehong.common.utils.DateUtils;
10
import com.zehong.common.utils.SecurityUtils;
11
import com.zehong.common.utils.StringUtils;
12
import com.zehong.common.utils.bean.BeanUtils;
13
import com.zehong.common.utils.uuid.UUID;
14
import com.zehong.system.domain.vo.TEnterpriseInfoVO;
15
import org.apache.commons.collections4.CollectionUtils;
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zehong.system.mapper.TEnterpriseInfoMapper;
import com.zehong.system.domain.TEnterpriseInfo;
import com.zehong.system.service.ITEnterpriseInfoService;

/**
 * 企业信息Service业务层处理
 * 
 * @author zehong
 * @date 2022-01-24
 */
@Service
public class TEnterpriseInfoServiceImpl implements ITEnterpriseInfoService 
{
    @Autowired
    private TEnterpriseInfoMapper tEnterpriseInfoMapper;

    /**
     * 查询企业信息
     * 
     * @param enterpriseId 企业信息ID
     * @return 企业信息
     */
    @Override
41
    public TEnterpriseInfo selectTEnterpriseInfoById(String enterpriseId)
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
    {
        return tEnterpriseInfoMapper.selectTEnterpriseInfoById(enterpriseId);
    }

    /**
     * 查询企业信息列表
     *
     * @param tEnterpriseInfo 企业信息
     * @return 企业信息
     */
    @Override
    public List<TEnterpriseInfoVO> enterpriseInfoList(TEnterpriseInfo tEnterpriseInfo)
    {
        List<TEnterpriseInfoVO> list = new ArrayList<>();
        List<TEnterpriseInfo> enterpriseInfoList = tEnterpriseInfoMapper.selectTEnterpriseInfoList(tEnterpriseInfo);

        for(TEnterpriseInfo info : enterpriseInfoList){
            TEnterpriseInfoVO tEnterpriseInfoVO = new TEnterpriseInfoVO();
            BeanUtils.copyProperties(info, tEnterpriseInfoVO);
            tEnterpriseInfoVO.setCompanyType(info.getEnterpriseId().toString());
            list.add(tEnterpriseInfoVO);
        }
        return list;
    }

    /**
     * 查询企业信息列表
     * 
     * @param tEnterpriseInfo 企业信息
     * @return 企业信息
     */
    @Override
    public List<TEnterpriseInfo> selectTEnterpriseInfoList(TEnterpriseInfo tEnterpriseInfo)
    {
        return tEnterpriseInfoMapper.selectTEnterpriseInfoList(tEnterpriseInfo);
    }

79 80 81 82 83 84 85 86 87 88

    /**
     * 无条件查询所有企业
     * @return re
     */
    @Override
    public List<TEnterpriseInfo> queryAllEnterprise() {
        return tEnterpriseInfoMapper.queryAllEnterprise();
    }

89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
    /**
     * 新增企业信息
     * 
     * @param tEnterpriseInfo 企业信息
     * @return 结果
     */
    @Override
    public int insertTEnterpriseInfo(TEnterpriseInfo tEnterpriseInfo)
    {
        tEnterpriseInfo.setCreateTime(DateUtils.getNowDate());
        return tEnterpriseInfoMapper.insertTEnterpriseInfo(tEnterpriseInfo);
    }

    /**
     * 修改企业信息
     * 
     * @param tEnterpriseInfo 企业信息
     * @return 结果
     */
    @Override
    public int updateTEnterpriseInfo(TEnterpriseInfo tEnterpriseInfo)
    {
        tEnterpriseInfo.setUpdateTime(DateUtils.getNowDate());
        return tEnterpriseInfoMapper.updateTEnterpriseInfo(tEnterpriseInfo);
    }

    /**
     * 批量删除企业信息
     * 
     * @param enterpriseIds 需要删除的企业信息ID
     * @return 结果
     */
    @Override
122
    public int deleteTEnterpriseInfoByIds(String[] enterpriseIds)
123 124 125 126 127 128 129 130 131 132 133
    {
        return tEnterpriseInfoMapper.deleteTEnterpriseInfoByIds(enterpriseIds);
    }

    /**
     * 删除企业信息信息
     * 
     * @param enterpriseId 企业信息ID
     * @return 结果
     */
    @Override
134
    public int deleteTEnterpriseInfoById(String enterpriseId)
135 136 137
    {
        return tEnterpriseInfoMapper.deleteTEnterpriseInfoById(enterpriseId);
    }
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157

    /**
     * 导入企业信息
     * @param tEnterpriseInfos 用户数据列表
     * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
     * @param operName 操作用户
     * @return
     */
    @Override
    public String importEnterpriseInfo(List<TEnterpriseInfo> tEnterpriseInfos, Boolean isUpdateSupport, String operName) {
        if (CollectionUtils.isEmpty(tEnterpriseInfos)) {
            throw new BaseException("导入项目编号数据不能为空! ");
        }
        int successNum = 0;
        int failureNum = 0;
        StringBuilder successMsg = new StringBuilder();
        StringBuilder failureMsg = new StringBuilder();
        for (TEnterpriseInfo enterpriseInfo : tEnterpriseInfos) {
            try {
                checkUploadRequired(enterpriseInfo);
158 159
                SysUser user = SecurityUtils.getLoginUser().getUser();
                enterpriseInfo.setCreateEnterpriseId(user.getDeptId());
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
                enterpriseInfo.setEnterpriseId(UUID.randomUUID().toString());
                this.insertTEnterpriseInfo(enterpriseInfo);
                successNum++;
                successMsg.append("<br/>" + successNum + "、项目编号 " + enterpriseInfo.getEnterpriseName() + " 导入成功");
            } catch (Exception e) {
                failureNum++;
                String msg = "<br/>" + failureNum + "、项目编号 " + enterpriseInfo.getEnterpriseName() + " 导入失败:";
                failureMsg.append(msg + e.getMessage());
            }
        }
        if (failureNum > 0) {
            failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
            throw new BaseException(failureMsg.toString());
        } else {
            successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
        }
        return successMsg.toString();
    }

    /**
     * 校验导入必填
     * @param tEnterpriseInfo t
     */
    public void checkUploadRequired(TEnterpriseInfo tEnterpriseInfo) {
        if (tEnterpriseInfo.getEnterpriseName() == null || "".equals(tEnterpriseInfo.getEnterpriseName())) {
            throw new BaseException("企业名称必填!!!");
        }

        if (tEnterpriseInfo.getEnterpriseType() == null) {
            throw new BaseException("企业类型必传!!!");
        }

        if (tEnterpriseInfo.getRegisterAddress() == null || "".equals(tEnterpriseInfo.getRegisterAddress())) {
            throw new BaseException("注册地址必传!!!");
        }

        if (tEnterpriseInfo.getLegalRepresentative() == null || "".equals(tEnterpriseInfo.getLegalRepresentative())) {
            throw new BaseException("法定代表人必传!!!");
        }
    }
200
}