<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.rongwei.bscommon.sys.dao.CommonDao">

    <select id="getFileUrlById" resultType="java.util.Map">
        select *
        from sys_file_item
        where ID = #{id}
          and DELETED = '0'
          limit 1
    </select>

    <select id="getDictByNameAndDictType" resultType="java.lang.Integer">
        SELECT count( * )
        FROM sys_dict
        WHERE
        NAME = #{name}
        AND DICTTYPE = #{dictType}
        AND DELETED = '0'
    </select>

    <select id="getDictByValueAndDictType" resultType="java.lang.Integer">
        SELECT count( * )
        FROM sys_dict
        WHERE
        VALUE = #{value}
        AND DICTTYPE = #{dictType}
        AND DELETED = '0'
    </select>

    <select id="getIdByFactoryName" resultType="java.lang.String">
        SELECT ID
        FROM sys_organization
        WHERE
        FULLNAME = #{factoryName}
        AND DELETED = '0'
        limit 1
    </select>

    <select id="getIdByFactoryIdAndDept" resultType="java.lang.String">
        SELECT ID
        FROM sys_organization
        WHERE
        FULLNAME = #{dept}
        AND FIND_IN_SET(#{factoryId},FULLPID)
        AND DELETED = '0'
        limit 1
    </select>

    <select id="getAllFactoryNameAndId" resultType="com.rongwei.rwadmincommon.system.vo.SysOrganizationVo">
        SELECT FULLNAME,ID
        FROM sys_organization
        WHERE
        PID='-1'
        AND DELETED = '0'
    </select>

    <insert id="insertFile">
        INSERT INTO `sys_file_item` (
	`ID`,
	`FILENAME`,
	`FILESIZE`,
	`FILETYPE`,
	`STORAGETYPE`,
	`FILEFOLDERID`,
	`RELATIONID`,
	`PATH`,
	`FULLPATH`,
	`URLPATH`,
	`MD5`,
	`EXTENDS1`,
	`EXTENDS2`,
	`EXTENDS3`,
	`TENANTID`,
	`ROPTION`,
	`DELETED`,
	`REMARK`,
	`CREATEDATE`,
	`CREATEUSERID`,
	`MODIFYDATE`,
	`MODIFYUSERID`,
	`CREATEUSERNAME`,
	`MODIFYUSERNAME`
)
VALUES
	(
		#{model.id},
		#{model.filename},
		#{model.filesize},
		#{model.filetype},
		#{model.storagetype},
		#{model.filefolderid},
		#{model.relationid},
		NULL,
		#{model.fullpath},
		#{model.urlpath},
		NULL,
		#{model.extends1},
		NULL,
		NULL,
		NULL,
		NULL,
		#{model.deleted},
		NULL,
		#{model.createdate},
		#{model.createuserid},
		#{model.modifydate},
		#{model.modifyuserid},
		#{model.createusername},
	    #{model.modifyusername}
	)
    </insert>
</mapper>
