AccountMapper.xml 6.2 KB
Newer Older
doc_wei's avatar
doc_wei 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<?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.skyeye.dao.AccountDao">
    <select id="queryAccountByList" parameterType="java.util.Map" resultType="java.util.Map">
        SELECT
            a.id,
            a.name accountName,
            a.serial_no serialNo,
            FORMAT(a.initial_amount, 2) initialAmount,
            FORMAT(IFNULL(SUM(IFNULL(b.change_amount, b.total_price) * CASE b.type WHEN 1 THEN 1 WHEN 2 THEN -1 WHEN 3 THEN 0 ELSE '' END), 0) + a.current_amount, 2) currentAmount,
            a.remark,
            a.is_default isDefault,
            CONVERT (a.create_time, CHAR) createTime
        FROM
doc_wei's avatar
doc_wei 已提交
15
            ifs_account a
doc_wei's avatar
doc_wei 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28
            LEFT JOIN erp_depothead b ON a.id = b.account_id AND b.sub_type NOT IN(10, 11) AND b.delete_flag = '0'
        WHERE
            a.delete_flag = 0
        <if test="accountName != '' and accountName != null">
            AND a.name LIKE '%${accountName}%'
        </if>
        <if test="serialNo != '' and serialNo != null">
            AND a.serial_no LIKE '%${serialNo}%'
        </if>
        <if test="remark != '' and remark != null">
            AND a.remark LIKE '%${remark}%'
        </if>
        ORDER BY a.create_time DESC
doc_wei's avatar
doc_wei 已提交
29
        GROUP BY a.id
doc_wei's avatar
doc_wei 已提交
30 31 32 33 34 35
    </select>

    <select id="queryAccountByName" parameterType="java.util.Map" resultType="java.util.Map">
        SELECT
            a.id
        FROM
doc_wei's avatar
doc_wei 已提交
36
            ifs_account a
doc_wei's avatar
doc_wei 已提交
37 38 39 40 41 42 43
        WHERE
            a.delete_flag = 0
        AND a.name = #{accountName}
        ORDER BY a.create_time DESC LIMIT 0,1
    </select>

    <insert id="insertAccount" parameterType="java.util.Map">
doc_wei's avatar
doc_wei 已提交
44
        INSERT INTO ifs_account(
doc_wei's avatar
doc_wei 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
            id, name, serial_no, initial_amount, current_amount, remark, is_default, delete_flag, create_time
        ) values (#{id}, #{accountName}, #{serialNo}, #{initialAmount}, #{currentAmount}, #{remark}, #{isDefault}, #{deleteFlag}, #{createTime})
    </insert>

    <select id="queryAccountById" parameterType="java.util.Map" resultType="java.util.Map">
        SELECT
            a.id,
            a.name accountName,
            a.serial_no serialNo,
            a.initial_amount initialAmount,
            a.current_amount currentAmount,
            a.remark,
            a.is_default isDefault,
            CONVERT (a.create_time, CHAR) createTime
        FROM
doc_wei's avatar
doc_wei 已提交
60
            ifs_account a
doc_wei's avatar
doc_wei 已提交
61 62 63 64 65 66 67
        WHERE
            a.delete_flag = 0
        AND a.id = #{id}
        ORDER BY a.create_time DESC LIMIT 0,1
    </select>

    <update id="editAccountByDeleteFlag" parameterType="java.util.Map">
doc_wei's avatar
doc_wei 已提交
68
        UPDATE ifs_account
doc_wei's avatar
doc_wei 已提交
69 70 71 72 73 74 75 76 77 78 79
        <set>
            delete_flag = #{deleteFlag}
        </set>
        WHERE
            id = #{id}
    </update>

    <select id="queryAccountByIdAndName" parameterType="java.util.Map" resultType="java.util.Map">
        SELECT
            a.id
        FROM
doc_wei's avatar
doc_wei 已提交
80
          ifs_account a
doc_wei's avatar
doc_wei 已提交
81 82 83 84 85 86 87 88
        WHERE
            a.delete_flag = 0
        AND a.id != #{id}
        AND a.name = #{accountName}
        ORDER BY a.create_time DESC LIMIT 0,1
    </select>

    <update id="editAccountById" parameterType="java.util.Map">
doc_wei's avatar
doc_wei 已提交
89
        UPDATE ifs_account
doc_wei's avatar
doc_wei 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
        <set>
            name = #{accountName},
            serial_no = #{serialNo},
            initial_amount = #{initialAmount},
            current_amount = #{initialAmount},
            remark = #{remark},
            is_default = #{isDefault}
        </set>
        WHERE
            id = #{id}
    </update>

    <select id="queryAccountByIdAndIsDeafault" parameterType="java.util.Map" resultType="java.util.Map">
        SELECT
            a.id
        FROM
doc_wei's avatar
doc_wei 已提交
106
          ifs_account a
doc_wei's avatar
doc_wei 已提交
107 108 109 110 111 112 113 114
        WHERE
            a.delete_flag = 0
        AND a.is_default = 1
        AND a.id = #{id}
        ORDER BY a.create_time DESC LIMIT 0,1
    </select>

    <update id="editAccountByIsNotDefault" parameterType="java.util.Map">
doc_wei's avatar
doc_wei 已提交
115
        UPDATE ifs_account
doc_wei's avatar
doc_wei 已提交
116 117 118 119 120 121
        <set>
            is_default = #{isDefault}
        </set>
    </update>

    <update id="editAccountByIdAndIsDefault" parameterType="java.util.Map">
doc_wei's avatar
doc_wei 已提交
122
        UPDATE ifs_account
doc_wei's avatar
doc_wei 已提交
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
        <set>
            is_default = #{isDefault}
        </set>
        WHERE
            id = #{id}
    </update>

    <select id="queryAccountByIdAndInfo" parameterType="java.util.Map" resultType="java.util.Map">
        SELECT
            a.id,
            a.name accountName,
            a.serial_no serialNo,
            FORMAT(a.initial_amount, 2) initialAmount,
            FORMAT(a.current_amount, 2) currentAmount,
            a.remark,
            a.is_default isDefault,
            CONVERT (a.create_time, CHAR) createTime
        FROM
doc_wei's avatar
doc_wei 已提交
141
          ifs_account a
doc_wei's avatar
doc_wei 已提交
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
        WHERE
            a.delete_flag = 0
        AND a.id = #{id}
        ORDER BY a.create_time DESC LIMIT 0,1
    </select>

    <select id="queryAccountStreamById" parameterType="java.util.Map" resultType="java.util.Map">
        SELECT
            d.id,
            d.sub_type subType,
            CASE d.sub_type WHEN 1 THEN '采购入库' WHEN 2 THEN '销售退货' WHEN 3 THEN '零售退货' WHEN 4 THEN '其他入库' WHEN 5 THEN '销售出库' 
							WHEN 6 THEN '采购退货' WHEN 7 THEN '调拨' WHEN 8 THEN '零售出库' WHEN 9 THEN '其他出库' ELSE '' END subTypeName,
            d.default_number defaultNumber,
            CONVERT(d.oper_time, CHAR) operTime,
            CONVERT(d.create_time, CHAR) createTime,
            FORMAT(d.total_price * (CASE d.type WHEN 2 THEN -1 ELSE 1 END), 2) totalPrice,
            d.type,
            IF(IFNULL(c.supplier, '') = '', e.`name`, c.supplier) supplierName,
            d.pay_type payType,
            d.`status`,
			d.status_content statusContent,
			d.link_number linkNumber
        FROM
            erp_depothead d
            LEFT JOIN erp_supplier c ON d.organ_id = c.id
            LEFT JOIN crm_customer e ON d.organ_id = e.id
        WHERE
            d.account_id = #{id}
        AND d.delete_flag = 0
    	AND d.type = '1'
        AND d.sub_type NOT IN(10, 11)
    </select>
    
    <select id="queryAccountListToSelect" parameterType="java.util.Map" resultType="java.util.Map">
    	SELECT
			a.id,
			a.`name`
		FROM
doc_wei's avatar
doc_wei 已提交
180
			ifs_account a
doc_wei's avatar
doc_wei 已提交
181 182 183 184 185 186
		WHERE
			a.delete_flag = '0'
		ORDER BY a.is_default ASC
    </select>

</mapper>