CompanyMapper.xml 7.47 KB
<?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.huaheng.pc.general.company.mapper.CompanyMapper">

	<select id="selectCompanyByUserId" parameterType="Integer" resultType="com.huaheng.pc.general.company.domain.Company">
		SELECT c.id, c.name, c.code
		FROM sys_user_company suc
		INNER JOIN company c ON  suc.companyId = c.id AND suc.userId = #{userId}
		INNER JOIN warehouse_company wc ON wc.companyId=c.id AND wc.warehouseId = #{warehouseId}
	</select>

	<select id="selectCompanyList" resultType="com.huaheng.pc.general.company.domain.Company">
        SELECT c.id, c.code, c.parentId, c.type, c.name, c.address1, c.address2, c.city, c.province, c.country, c.postalCode,
        c.attentionTo, c.phoneNum, c.mobile, c.faxNum, c.email, c.created, c.createdBy, c.lastUpdated, c.lastUpdatedBy, c.enable,
        c.deleted, c.userDef1, c.userDef2, c.userDef3
        FROM company c
        inner join warehouse_company wc ON c.id = wc.companyId
        <if test="id != null and id != ''">
            AND c.id = #{id}
        </if>
        <if test="code != null and code != ''">
            <bind name="codePattern" value="'%' + code + '%'" />
            AND c.code like #{codePattern}
        </if>
        <if test="parentId != null and parentId != ''">
            AND c.parentId = #{parentId}
        </if>
        <if test="type != null and type != ''">
            <bind name="typePattern" value="'%' + type + '%'" />
            AND c.type like #{typePattern}
        </if>
        <if test="name != null and name != ''">
            <bind name="namePattern" value="'%' + name + '%'" />
            AND c.name like #{namePattern}
        </if>
        <if test="address1 != null and address1 != ''">
            <bind name="address1Pattern" value="'%' + address1 + '%'" />
            AND c.address1 like #{address1Pattern}
        </if>
        <if test="address2 != null and address2 != ''">
            <bind name="address2Pattern" value="'%' + address2 + '%'" />
            AND c.address2 like #{address2Pattern}
        </if>
        <if test="city != null and city != ''">
            <bind name="cityPattern" value="'%' + city + '%'" />
            AND c.city like #{cityPattern}
        </if>
        <if test="province != null and province != ''">
            <bind name="provincePattern" value="'%' + province + '%'" />
            AND c.province like #{provincePattern}
        </if>
        <if test="country != null and country != ''">
            <bind name="countryPattern" value="'%' + country + '%'" />
            AND c.country like #{countryPattern}
        </if>
        <if test="postalCode != null and postalCode != ''">
            <bind name="postalCodePattern" value="'%' + postalCode + '%'" />
            AND c.postalCode like #{postalCodePattern}
        </if>
        <if test="attentionTo != null and attentionTo != ''">
            <bind name="attentionToPattern" value="'%' + attentionTo + '%'" />
            AND c.attentionTo like #{attentionToPattern}
        </if>
        <if test="phoneNum != null and phoneNum != ''">
            <bind name="phoneNumPattern" value="'%' + phoneNum + '%'" />
            AND c.phoneNum like #{phoneNumPattern}
        </if>
        <if test="mobile != null and mobile != ''">
            <bind name="mobilePattern" value="'%' + mobile + '%'" />
            AND c.mobile like #{mobilePattern}
        </if>
        <if test="faxNum != null and faxNum != ''">
            <bind name="faxNumPattern" value="'%' + faxNum + '%'" />
            AND c.faxNum like #{faxNumPattern}
        </if>
        <if test="email != null and email != ''">
            <bind name="emailPattern" value="'%' + email + '%'" />
            AND c.email like #{emailPattern}
        </if>
        <if test="created != null and created != ''">
            AND c.created = #{created}
        </if>
        <if test="createdBy != null and createdBy != ''">
            <bind name="createdByPattern" value="'%' + createdBy + '%'" />
            AND c.createdBy like #{createdByPattern}
        </if>
        <if test="lastUpdated != null and lastUpdated != ''">
            AND c.lastUpdated = #{lastUpdated}
        </if>
        <if test="lastUpdatedBy != null and lastUpdatedBy != ''">
            <bind name="lastUpdatedByPattern" value="'%' + lastUpdatedBy + '%'" />
            AND c.lastUpdatedBy like #{lastUpdatedByPattern}
        </if>
        <if test="enable != null and enable != ''">
            AND c.enable = #{enable}
        </if>
        <if test="deleted != null and deleted != ''">
            AND c.deleted = #{deleted}
        </if>
        <if test="userDef1 != null and userDef1 != ''">
            <bind name="userDef1Pattern" value="'%' + userDef1 + '%'" />
            AND c.userDef1 like #{userDef1Pattern}
        </if>
        <if test="userDef2 != null and userDef2 != ''">
            <bind name="userDef2Pattern" value="'%' + userDef2 + '%'" />
            AND c.userDef2 like #{userDef2Pattern}
        </if>
        <if test="userDef3 != null and userDef3 != ''">
            <bind name="userDef3Pattern" value="'%' + userDef3 + '%'" />
            AND c.userDef3 like #{userDef3Pattern}
        </if>
        <if test="warehouseId != null">
            AND wc.warehouseId = #{warehouseId}
        </if>
        <if test="warehouseCode != null">
            AND wc.warehouseCode = #{warehouseCode}
        </if>
	</select>

    <select id="CompanyParent" resultType="java.util.Map">
        SELECT id, code, name, enable
        FROM company
        <where>
            <if test="enable != null and enable != ''">
                AND enable = #{enable}
            </if>
            <if test="deleted != null and deleted != ''">
                AND deleted = #{deleted}
            </if>
            <if test="type != null">
                AND type = #{type}
            </if>
        </where>
    </select>

    <select id="getCurrentCompanyList" resultType="com.huaheng.pc.general.company.domain.Company">
       SELECT c.id, c.code, c.parentId, c.name, c.enable
        FROM company c
        inner join warehouse_company wc ON c.id = wc.companyId
        <if test="enable != null and enable != ''">
            AND c.enable = #{enable}
        </if>
        <if test="deleted != null and deleted != ''">
            AND c.deleted = #{deleted}
        </if>
        <if test="warehouseId != null">
            AND wc.warehouseId = #{warehouseId}
        </if>
        <if test="warehouseCode != null">
            AND wc.warehouseCode = #{warehouseCode}
        </if>
    </select>

    <delete id="deleteCompanyByIds" parameterType="Integer">
 		update  company  set deleted=true where id in
        <foreach collection="array" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
 	</delete>

    <select id="selectCompanyWu" resultType="com.huaheng.pc.general.company.domain.CompanyWu">
        select id, uCompanyCode, companyCode from company_wu
        <where>
            <if test="uCompanyCode != null and uCompanyCode != ''">
                AND uCompanyCode = #{uCompanyCode}
            </if>
            <if test="companyCode != null and companyCode != ''">
                AND companyCode = #{companyCode}
            </if>
        </where>
    </select>

    <select id="selcetIWCBycode" resultType="com.huaheng.pc.general.company.domain.WarehouseCompany">
        select * from warehouse_company where warehouseCode = #{warehouseCode} AND companyCode=#{companyCode}
    </select>


</mapper>