java110
2020-04-23 5bd79abfedcfb1cc4bfe06e2d68456e410f73cb9
优化员工公司显示
6个文件已修改
1个文件已添加
473 ■■■■■ 已修改文件
CommonService/src/main/java/com/java110/common/smo/impl/FileInnerServiceSMOImpl.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
java110-bean/src/main/java/com/java110/dto/user/UserDto.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
java110-bean/src/main/java/com/java110/vo/api/staff/ApiStaffDataVo.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
java110-core/pom.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
java110-core/src/main/java/com/java110/core/client/JSchFtpUploadTemplate.java 323 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
java110-db/src/main/resources/mapper/user/UserServiceDaoImplMapper.xml 103 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
CommonService/src/main/java/com/java110/common/smo/impl/FileInnerServiceSMOImpl.java
@@ -3,6 +3,7 @@
import com.java110.common.dao.IFileServiceDao;
import com.java110.config.properties.code.Java110Properties;
import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.core.client.JSchFtpUploadTemplate;
import com.java110.core.smo.file.IFileInnerServiceSMO;
import com.java110.dto.file.FileDto;
import com.java110.core.client.FtpUploadTemplate;
@@ -26,6 +27,9 @@
    @Autowired
    private FtpUploadTemplate ftpUploadTemplate;
    @Autowired
    private JSchFtpUploadTemplate jSchFtpUploadTemplate;
    @Override
    public String saveFile(@RequestBody FileDto fileDto) {
@@ -37,6 +41,9 @@
                java110Properties.getFtpPort(), java110Properties.getFtpUserName(),
                java110Properties.getFtpUserPassword(), java110Properties.getFtpPath());
//        String fileName = jSchFtpUploadTemplate.upload(fileDto.getContext(), java110Properties.getFtpServer(),
//                java110Properties.getFtpPort(), java110Properties.getFtpUserName(),
//                java110Properties.getFtpUserPassword(), java110Properties.getFtpPath());
        return fileName;
    }
java110-bean/src/main/java/com/java110/dto/user/UserDto.java
@@ -50,6 +50,9 @@
    private String openId;
    private String statusCd;
    private String parentOrgName;
    private List<UserAttrDto> userAttrs;
@@ -205,4 +208,12 @@
    public void setStatusCd(String statusCd) {
        this.statusCd = statusCd;
    }
    public String getParentOrgName() {
        return parentOrgName;
    }
    public void setParentOrgName(String parentOrgName) {
        this.parentOrgName = parentOrgName;
    }
}
java110-bean/src/main/java/com/java110/vo/api/staff/ApiStaffDataVo.java
@@ -30,6 +30,10 @@
    private String orgName;
    private String parentOrgId;
    private String parentOrgName;
    public String getUserId() {
@@ -143,4 +147,20 @@
    public void setInitials(String initials) {
        this.initials = initials;
    }
    public String getParentOrgId() {
        return parentOrgId;
    }
    public void setParentOrgId(String parentOrgId) {
        this.parentOrgId = parentOrgId;
    }
    public String getParentOrgName() {
        return parentOrgName;
    }
    public void setParentOrgName(String parentOrgName) {
        this.parentOrgName = parentOrgName;
    }
}
java110-core/pom.xml
@@ -43,6 +43,10 @@
            <groupId>com.tencentcloudapi</groupId>
            <artifactId>tencentcloud-sdk-java</artifactId>
        </dependency>
        <dependency>
            <groupId>com.jcraft</groupId>
            <artifactId>jsch</artifactId>
        </dependency>
        <dependency>
java110-core/src/main/java/com/java110/core/client/JSchFtpUploadTemplate.java
New file
@@ -0,0 +1,323 @@
package com.java110.core.client;
import com.java110.utils.util.Base64Convert;
import com.java110.utils.util.DateUtil;
import com.jcraft.jsch.*;
import com.jcraft.jsch.ChannelSftp.LsEntry;
import org.apache.commons.net.ftp.FTP;
import org.omg.CORBA.SystemException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import java.util.Vector;
/**
 * @author joychen
 * @date 2020/4/21 4:59 PM
 */
@Component
public class JSchFtpUploadTemplate {
    private static final Logger LOG = LoggerFactory.getLogger(JSchFtpUploadTemplate.class);
    private static String ftpPath = "uploadFiles"; // 文件上传目录
    private static String LOCAL_CHARSET = "GBK";
    private static String SERVER_CHARSET = "ISO-8859-1";
    private final static String localpath = "F:/";//下载到F盘下
    private final static String fileSeparator = System.getProperty("file.separator");
    private final static String DEFAULT_IMG_SUFFIX = ".jpg";
    private final static String IMAGE_DEFAULT_PATH = "img/";
    private Channel channel = null;
    private Session session = null;
    /*
     *图片上传工具方法
     * 默认上传至 img 文件下的当前日期下
     */
    public String upload(String imageBase64, String server, int port,
                         String userName, String userPassword, String ftpPath) {
        String fileName = "";
        ChannelSftp sftp = null;
        try {
            sftp = getChannel(server,port+"",userName,userPassword,0);
            ftpPath = ftpPath + IMAGE_DEFAULT_PATH + DateUtil.getNowII() + "/";
            createDir(sftp, ftpPath);// 创建目录
            // 设置上传目录 must
            fileName = UUID.randomUUID().toString();
            if (imageBase64.contains("data:image/png;base64,")) {
                imageBase64 = imageBase64.replace("data:image/png;base64,", "");
                fileName += ".png";
            } else if (imageBase64.contains("data:image/jpeg;base64,")) {
                imageBase64 = imageBase64.replace("data:image/jpeg;base64,", "");
                fileName += ".jpg";
            } else if (imageBase64.contains("data:image/webp;base64,")) {
                imageBase64 = imageBase64.replace("data:image/webp;base64,", "");
                fileName += ".jpg";
            } else if(imageBase64.contains("data:application/octet-stream;base64,")){
                imageBase64 = imageBase64.replace("data:application/octet-stream;base64,", "");
                fileName += ".jpg";
            }else {
                fileName += ".jpg";
            }
            byte[] context = Base64Convert.base64ToByte(imageBase64);
            ByteArrayInputStream is = new ByteArrayInputStream(context);
            Vector<String> vector =  sftp.ls(ftpPath);
            if (vector.contains(fileName)){
                System.out.println("this file exist ftp");
                sftp.rm(fileName);
            }else{
                System.out.println("this file not exist ftp");
            }
            sftp.put(is,fileName);
            is.close();
            sftp.disconnect();
        } catch (Exception e) {
            LOG.error("上传文件失败", e);
            throw new IllegalArgumentException("上传文件失败");
        } finally {
            try {
                if (sftp !=null) {
                    sftp.disconnect();
                }
                closeChannel();
            } catch (IOException e) {
                e.printStackTrace();
                LOG.error("关闭ftpClient 失败", e);
            } catch (Exception e) {
                e.printStackTrace();
                e.printStackTrace();
                LOG.error("关闭ftpClient 失败", e);
            }
        }
        return IMAGE_DEFAULT_PATH + DateUtil.getNowII() + "/" + fileName;
    }
    /**
     *
     * @param ftpHost
     * @param port
     * @param ftpUserName
     * @param ftpPassword
     * @param timeout
     * @return
     * @throws JSchException
     */
    public ChannelSftp getChannel(String ftpHost,
                                  String port ,  String ftpUserName ,String ftpPassword ,int timeout) throws JSchException {
        int ftpPort = 22;
        if (port != null && !port.equals("")) {
            ftpPort = Integer.valueOf(port);
        }
        JSch jsch = new JSch(); // 创建JSch对象
        session = jsch.getSession(ftpUserName, ftpHost, ftpPort); // 根据用户名,主机ip,端口获取一个Session对象
        LOG.debug("Session created.");
        if (ftpPassword != null) {
            session.setPassword(ftpPassword); // 设置密码
        }
        Properties config = new Properties();
        config.put("StrictHostKeyChecking", "no");
        session.setConfig(config); // 为Session对象设置properties
        session.setTimeout(timeout); // 设置timeout时间
        session.connect(); // 通过Session建立链接
        LOG.debug("Session connected.");
        LOG.debug("Opening Channel.");
        channel = session.openChannel("sftp"); // 打开SFTP通道
        channel.connect(); // 建立SFTP通道的连接
        LOG.debug("Connected successfully to ftpHost = " + ftpHost + ",as ftpUserName = " + ftpUserName
                + ", returning: " + channel);
        return (ChannelSftp) channel;
    }
    public void closeChannel() throws Exception {
        if (channel != null) {
            channel.disconnect();
        }
        if (session != null) {
            session.disconnect();
        }
    }
    /*
     *文件上传工具方法
     */
    public String upload(MultipartFile uploadFile, String server, int port,
                         String userName, String userPassword, String ftpPath) {
        String fileName = "";
        ChannelSftp sftp = null;
        try {
            sftp = getChannel(server,port+"",userName,userPassword,0);
            createDir(sftp, ftpPath);// 创建目录
            fileName = UUID.randomUUID().toString() + "." + uploadFile.getOriginalFilename().substring(uploadFile.getOriginalFilename().lastIndexOf(".") + 1);
            InputStream os = sftp.get(fileName);
            int length =  os.read();
            if (length == 0) {
                System.out.println("this file not exist ftp");
            } else if (length >= 1) {
                System.out.println("this file exist ftp");
                sftp.rm(fileName);
            }
            InputStream is = uploadFile.getInputStream();
            sftp.put(is,fileName);
            is.close();
            sftp.disconnect();
        } catch (Exception e) {
            // logger.error("上传文件失败", e);
            throw new IllegalArgumentException("上传文件失败");
        } finally {
            try {
                if (sftp !=null) {
                    sftp.disconnect();
                }
                closeChannel();
            } catch (IOException e) {
                e.printStackTrace();
                LOG.error("关闭ftpClient 失败", e);
            } catch (Exception e) {
                e.printStackTrace();
                e.printStackTrace();
                LOG.error("关闭ftpClient 失败", e);
            }
        }
        return fileName;
    }
    /*
     *文件下载工具方法
     */
    public byte[] downFileByte(String remotePath, String fileName, String server, int port, String userName, String userPassword) {
        byte[] return_arraybyte = null;
        ChannelSftp sftp = null;
        LOG.info("remotePath"+remotePath+"      fileName = "+fileName);
        try {
            sftp = getChannel(server,port+"",userName,userPassword,0);
            if (sftp != null) {
                String f = new String(
                        (remotePath + fileName).getBytes("UTF-8"), SERVER_CHARSET);//防止乱码
                InputStream ins = sftp.get(f);//需使用file.getName获值,若用f会乱码
                ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
                sftp.get(f,byteOut);
//                byte[] buf = new byte[204800];
//                int bufsize = 0;
//                int readLength = 2048;
//                while (ins != null && (bufsize = ins.read(buf, bufsize,bufsize+readLength)) != -1) {
//                    byteOut.write(buf, bufsize, bufsize  + readLength);
//                }
                return_arraybyte = byteOut.toByteArray();
                byteOut.close();
                if (ins != null) {
                    ins.close();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            LOG.error("从ftp读取文件失败", e);
        } finally {
            try {
                if (sftp !=null) {
                    sftp.disconnect();
                }
                closeChannel();
            } catch (IOException e) {
                e.printStackTrace();
                LOG.error("关闭ftpClient 失败", e);
            } catch (Exception e) {
                e.printStackTrace();
                e.printStackTrace();
                LOG.error("关闭ftpClient 失败", e);
            }
        }
        return return_arraybyte;
    }
    /**
     * 创建一个文件目录
     */
    public void createDir(ChannelSftp sftp,String createpath) {
        try {
            if (isDirExist(sftp,createpath)) {
                if (sftp.pwd().equals(createpath)){
                    return;
                }
                sftp.cd(createpath);
                return;
            }
            String pathArry[] = createpath.split("/");
            StringBuffer filePath = new StringBuffer("/");
            for (String path : pathArry) {
                if (path.equals("")) {
                    continue;
                }
                filePath.append(path + "/");
                if (isDirExist(sftp,filePath.toString())) {
                    sftp.cd(filePath.toString());
                } else {
                    // 建立目录
                    sftp.mkdir(filePath.toString());
                    // 进入并设置为当前目录
                    sftp.cd(filePath.toString());
                }
            }
            sftp.cd(createpath);
        } catch (SftpException e) {
            throw new IllegalArgumentException("创建路径错误:" + createpath);
        }
    }
    /**
     * 判断目录是否存在
     */
    public boolean isDirExist(ChannelSftp sftp,String directory) {
        boolean isDirExistFlag = false;
        try {
            SftpATTRS sftpATTRS = sftp.lstat(directory);
            isDirExistFlag = true;
            return sftpATTRS.isDir();
        } catch (Exception e) {
            if (e.getMessage().toLowerCase().equals("no such file")) {
                isDirExistFlag = false;
            }
        }
        return isDirExistFlag;
    }
}
java110-db/src/main/resources/mapper/user/UserServiceDaoImplMapper.xml
@@ -74,33 +74,34 @@
    </insert>
    <!-- 删除实例客户信息 cust -->
    <update id="deleteDataToCustAttr" parameterType="com.java110.entity.user.CustAttr">
           delete * from cust_attr ct where 1=1
           <if test="custId != null and custId != ''">
               and ct.custId = #{custId}
           </if>
            <if test="attrCd != null and attrCd != ''">
                and ct.attrCd = #{attrCd}
            </if>
        delete * from cust_attr ct where 1=1
        <if test="custId != null and custId != ''">
            and ct.custId = #{custId}
        </if>
        <if test="attrCd != null and attrCd != ''">
            and ct.attrCd = #{attrCd}
        </if>
    </update>
    <!--根据客户ID 查询客户信息,其中包括 cust 和custAttr 数据-->
    <select id="queryDataToCust" parameterType="com.java110.entity.user.Cust" resultMap="custMap">
            select c.custId,c.name,c.email,c.cellphone,c.realName,c.sex,c.password,c.lanId,c.custAdress,c.custType,c.openId,
            ca.custId,ca.attrCd,ca.value
             from cust c, cust_attr ca where c.custId= ca.custId
        select c.custId,c.name,c.email,c.cellphone,c.realName,c.sex,c.password,c.lanId,c.custAdress,c.custType,c.openId,
        ca.custId,ca.attrCd,ca.value
        from cust c, cust_attr ca where c.custId= ca.custId
        <if test="custId != null and custId != ''">
            and c.custId = #{custId}
        </if>
        <if test="versionId != null and versionId != ''">
            and c.versionId = #{versionId}
        </if>
            and c.status_cd = '0'
        and c.status_cd = '0'
    </select>
    <!-- 查询客户过程数据 -->
    <select id="queryBoCust" parameterType="com.java110.entity.user.BoCust" resultType="com.java110.entity.user.BoCust">
        select bc.boId,bc.custId,bc.name,bc.email,bc.cellphone,bc.realName,bc.sex,bc.password,bc.lanId,bc.custAdress,bc.custType,bc.openId,bc.create_dt
        select
        bc.boId,bc.custId,bc.name,bc.email,bc.cellphone,bc.realName,bc.sex,bc.password,bc.lanId,bc.custAdress,bc.custType,bc.openId,bc.create_dt
        from bo_cust bc where 1=1
        <if test="boId != null and boId != ''">
            and bc.boId = #{boId}
@@ -117,7 +118,8 @@
        </if>
    </select>
    <!-- 查询客户属性过程表-->
    <select id="queryBoCustAttr" parameterType="com.java110.entity.user.BoCustAttr" resultType="com.java110.entity.user.BoCustAttr">
    <select id="queryBoCustAttr" parameterType="com.java110.entity.user.BoCustAttr"
            resultType="com.java110.entity.user.BoCustAttr">
        select bca.boId,bca.custId,bca.attrCd,bca.value,bca.state,bca.create_dt from bo_cust_attr bca where 1=1
        <if test="boId !=null and boId != ''">
            and bca.boId = #{boId}
@@ -134,7 +136,8 @@
    </select>
    <!-- 查询客户属性信息 -->
    <select id="queryDataToCustAttr" parameterType="com.java110.entity.user.CustAttr" resultType="com.java110.entity.user.CustAttr">
    <select id="queryDataToCustAttr" parameterType="com.java110.entity.user.CustAttr"
            resultType="com.java110.entity.user.CustAttr">
        select * from cust_attr ca where 1=1
        <if test="custId != null and custId != ''">
            and ca.custId = #{custId}
@@ -162,12 +165,15 @@
    <!-- 实例数据 -->
    <insert id="saveUserInfoInstance" parameterType="map">
        insert into u_user(user_id,name,email,address,password,location_cd,age,sex,tel,level_cd,b_id,status_cd)
        select bu.user_id,bu.name,bu.email,bu.address,bu.password,bu.location_cd,bu.age,bu.sex,bu.tel,bu.level_cd,bu.b_id,'0' from business_user bu where bu.operate = 'ADD' and bu.b_id=#{b_id}
        select
        bu.user_id,bu.name,bu.email,bu.address,bu.password,bu.location_cd,bu.age,bu.sex,bu.tel,bu.level_cd,bu.b_id,'0'
        from business_user bu where bu.operate = 'ADD' and bu.b_id=#{b_id}
    </insert>
    <insert id="saveUserAttrInstance" parameterType="map">
        insert into u_user_attr(attr_id,user_id,spec_cd,value,b_id,status_cd)
        select bua.attr_id,bua.user_id,bua.spec_cd,bua.value,bua.b_id,'0' from business_user_attr bua where bua.operate='ADD' and bua.b_id=#{b_id}
        select bua.attr_id,bua.user_id,bua.spec_cd,bua.value,bua.b_id,'0' from business_user_attr bua where
        bua.operate='ADD' and bua.b_id=#{b_id}
    </insert>
    <update id="updateUserInfoInstance" parameterType="map">
@@ -222,14 +228,13 @@
    </update>
    <!-- 查询用户信息 Business -->
    <select id="queryBusinessUserInfo" parameterType="map" resultType="map">
        select u.user_id,u.name,u.email,u.address,u.password,u.location_cd,
        u.age,u.sex,u.tel,u.level_cd,u.b_id,u.operate
        from business_user u where 1 = 1
        <if test="operate != null and operate != ''">
           and u.operate = #{operate}
            and u.operate = #{operate}
        </if>
        <if test="bId != null and bId !=''">
            and u.b_id = #{bId}
@@ -259,7 +264,8 @@
    <!-- 查询用户信息 -->
    <select id="queryUserInfo" parameterType="map" resultType="map">
        select u.user_id, u.user_id userId,u.name,u.name userName,u.email,u.address,u.password,u.location_cd,u.location_cd locationCd,
        select u.user_id, u.user_id userId,u.name,u.name
        userName,u.email,u.address,u.password,u.location_cd,u.location_cd locationCd,
        u.age,u.sex,u.tel,u.level_cd,u.b_id
        from u_user u where 1= 1
        <if test="bId != null and bId !=''">
@@ -273,12 +279,11 @@
        </if>
        <if test="userIds != null and userIds != null">
            and u.user_id in
                <foreach collection="userIds" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            <foreach collection="userIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
    </select>
    <!-- 查询用户属性信息 -->
@@ -388,7 +393,6 @@
    </update>
    <!--保存用户证件信息 add by wuxw 2018-06-29 -->
    <insert id="saveBusinessUserCredentials" parameterType="map">
        insert into business_user_credentials(credentials_id,b_id,user_id,credentials_cd,value,operate)
@@ -437,19 +441,23 @@
    <select id="getStaffCount" parameterType="Map" resultType="Map">
        select count(1) count
        from
             u_user a
            u_user u
            ,u_org uo
            ,u_org_staff_rel uosr
        where a.level_cd = '01'
            and a.user_id = uosr.staff_id
            ,u_org puo
        where u.level_cd = '01'
            and u.user_id = uosr.staff_id
            and uosr.store_id = #{storeId}
            and uosr.org_id = uo.org_id
            and uo.parent_org_id = puo.org_id
            and puo.status_cd = '0'
            and uo.status_cd = '0'
        <if test="parentOrgId !=null and parentOrgId != ''">
            and uo.parent_org_id = #{parentOrgId}
        </if>
            and a.status_cd = '0'
            and uo.status_cd = '0'
            and uosr.status_cd = '0'
        and a.status_cd = '0'
        and uo.status_cd = '0'
        and uosr.status_cd = '0'
        <if test="tel !=null and tel != ''">
            and a.tel= #{tel}
        </if>
@@ -469,22 +477,27 @@
    <!-- 查询员工总量 -->
    <select id="getStaffs" parameterType="Map" resultType="Map">
        select uo.org_name,uo.org_name orgName,u.user_id, u.user_id userId,u.name,u.name userName,u.email,u.address,u.location_cd,u.location_cd locationCd,
            u.age,u.sex,u.tel,u.level_cd,u.b_id
        select uo.org_name,uo.org_name orgName,u.user_id, u.user_id userId,u.name,u.name
        userName,u.email,u.address,u.location_cd,u.location_cd locationCd,
        u.age,u.sex,u.tel,u.level_cd,u.b_id,puo.org_id parentOrgId,puo.org_name parentOrgName
        from
            u_user u
            ,u_org uo
            ,u_org_staff_rel uosr
            where u.level_cd = '01'
            and u.user_id = uosr.staff_id
            and uosr.store_id = #{storeId}
            and uosr.org_id = uo.org_id
        u_user u
        ,u_org uo
        ,u_org_staff_rel uosr
        ,u_org puo
        where u.level_cd = '01'
        and u.user_id = uosr.staff_id
        and uosr.store_id = #{storeId}
        and uosr.org_id = uo.org_id
        and uo.parent_org_id = puo.org_id
        and puo.status_cd = '0'
        and uo.status_cd = '0'
        <if test="parentOrgId !=null and parentOrgId != ''">
            and uo.parent_org_id = #{parentOrgId}
        </if>
            and u.status_cd = '0'
            and uo.status_cd = '0'
            and uosr.status_cd = '0'
        and u.status_cd = '0'
        and uo.status_cd = '0'
        and uosr.status_cd = '0'
        <if test="tel !=null and tel != ''">
            and u.tel= #{tel}
        </if>
@@ -508,7 +521,8 @@
    <!-- 查询用户 -->
    <select id="getUsers" parameterType="Map" resultType="Map">
        select u.user_id, u.user_id userId,u.name,u.name userName,u.email,u.address,u.password,u.location_cd,u.location_cd locationCd,
        select u.user_id, u.user_id userId,u.name,u.name
        userName,u.email,u.address,u.password,u.location_cd,u.location_cd locationCd,
        u.age,u.sex,u.tel,u.level_cd,u.b_id
        from u_user u
        <if test="openId != null and openId !=''">
@@ -575,7 +589,8 @@
    <!-- 查询用户密码 -->
    <select id="getUserHasPwd" parameterType="Map" resultType="Map">
        select u.user_id, u.user_id userId,u.name,u.name userName,u.email,u.address,u.password,u.location_cd,u.location_cd locationCd,
        select u.user_id, u.user_id userId,u.name,u.name
        userName,u.email,u.address,u.password,u.location_cd,u.location_cd locationCd,
        u.age,u.sex,u.tel,u.level_cd levelCd,u.b_id,u.password
        from u_user u
        <if test="openId != null and openId !=''">
pom.xml
@@ -267,6 +267,11 @@
                <version>3.0.9.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>com.jcraft</groupId>
                <artifactId>jsch</artifactId>
                <version>0.1.49</version>
            </dependency>
            <dependency>
                <groupId>org.apache.activemq</groupId>