<?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.ruoyi.web.modules.industryservice.mapper.BizCooperativeDevelopmentMapper">

    <resultMap type="com.ruoyi.web.modules.industryservice.domain.BizCooperativeDevelopment" id="BizCooperativeDevelopmentResult">
        <id property="id" column="id"/>
        <result property="statYear" column="stat_year"/>
        <result property="statMonth" column="stat_month"/>
        <result property="townDeptId" column="town_dept_id"/>
        <result property="townName" column="town_name"/>
        <result property="villageDeptId" column="village_dept_id"/>
        <result property="villageName" column="village_name"/>
        <result property="cooperativeName" column="cooperative_name"/>
        <result property="legalRepresentative" column="legal_representative"/>
        <result property="establishDate" column="establish_date"/>
        <result property="registeredCapital" column="registered_capital"/>
        <result property="yearEndTotalAssets" column="year_end_total_assets"/>
        <result property="memberHouseholdCount" column="member_household_count"/>
        <result property="memberPopulationCount" column="member_population_count"/>
        <result property="povertyMonitorCount" column="poverty_monitor_count"/>
        <result property="cattleShareCount" column="cattle_share_count"/>
        <result property="sheepShareCount" column="sheep_share_count"/>
        <result property="livestockShareTotal" column="livestock_share_total"/>
        <result property="grasslandShareArea" column="grassland_share_area"/>
        <result property="laborShareCount" column="labor_share_count"/>
        <result property="cashShareAmount" column="cash_share_amount"/>
        <result property="otherShareAmount" column="other_share_amount"/>
        <result property="totalIncome" column="total_income"/>
        <result property="netIncome" column="net_income"/>
        <result property="cashDividend" column="cash_dividend"/>
        <result property="inKindDividend" column="in_kind_dividend"/>
        <result property="revolvingFund" column="revolving_fund"/>
        <result property="lossAmount" column="loss_amount"/>
        <result property="collegeGraduateCount" column="college_graduate_count"/>
        <result property="collegeGraduateWage" column="college_graduate_wage"/>
        <result property="farmerTransferEmploymentCount" column="farmer_transfer_employment_count"/>
        <result property="farmerTransferWage" column="farmer_transfer_wage"/>
        <result property="cattleInventoryCount" column="cattle_inventory_count"/>
        <result property="cattleOutboundCount" column="cattle_outbound_count"/>
        <result property="sheepInventoryCount" column="sheep_inventory_count"/>
        <result property="sheepOutboundCount" column="sheep_outbound_count"/>
        <result property="trademarkProductCount" column="trademark_product_count"/>
        <result property="qualityCertProductCount" column="quality_cert_product_count"/>
        <result property="trainingManageCount" column="training_manage_count"/>
        <result property="trainingSkillCount" column="training_skill_count"/>
        <result property="trainingOtherCount" column="training_other_count"/>
        <result property="businessScope" column="business_scope"/>
        <result property="businessModel" column="business_model"/>
        <result property="operationStatus" column="operation_status"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectVo">
        select r.id, r.stat_year, r.stat_month, r.town_dept_id, r.town_name, r.village_dept_id, r.village_name, r.cooperative_name, r.legal_representative, r.establish_date, r.registered_capital, r.year_end_total_assets, r.member_household_count, r.member_population_count, r.poverty_monitor_count, r.cattle_share_count, r.sheep_share_count, r.livestock_share_total, r.grassland_share_area, r.labor_share_count, r.cash_share_amount, r.other_share_amount, r.total_income, r.net_income, r.cash_dividend, r.in_kind_dividend, r.revolving_fund, r.loss_amount, r.college_graduate_count, r.college_graduate_wage, r.farmer_transfer_employment_count, r.farmer_transfer_wage, r.cattle_inventory_count, r.cattle_outbound_count, r.sheep_inventory_count, r.sheep_outbound_count, r.trademark_product_count, r.quality_cert_product_count, r.training_manage_count, r.training_skill_count, r.training_other_count, r.business_scope, r.business_model, r.operation_status,
               r.create_by, r.create_time, r.update_by, r.update_time, r.remark
        from biz_cooperative_development r
    </sql>

    <select id="selectBizCooperativeDevelopmentById" parameterType="long" resultMap="BizCooperativeDevelopmentResult">
        <include refid="selectVo"/>
        where r.id = #{id}
    </select>

    <select id="countByUniqueExcludeId" resultType="int">
        select count(1) from biz_cooperative_development
        where stat_year = #{statYear} and stat_month = #{statMonth}
          and village_dept_id = #{villageDeptId} and cooperative_name = #{cooperativeName}
        <if test="excludeId != null">and id != #{excludeId}</if>
    </select>

    <select id="selectByUnique" resultMap="BizCooperativeDevelopmentResult">
        <include refid="selectVo"/>
        where r.stat_year = #{statYear} and r.stat_month = #{statMonth}
          and r.village_dept_id = #{villageDeptId} and r.cooperative_name = #{cooperativeName}
        limit 1
    </select>

    <select id="selectBizCooperativeDevelopmentList" parameterType="com.ruoyi.web.modules.industryservice.domain.BizCooperativeDevelopment"
            resultMap="BizCooperativeDevelopmentResult">
        <include refid="selectVo"/>
        left join sys_dept d on r.town_dept_id = d.dept_id
        <where>
            <if test="statYear != null">and r.stat_year = #{statYear}</if>
            <if test="statMonth != null">and r.stat_month = #{statMonth}</if>
            <if test="townDeptId != null">and r.town_dept_id = #{townDeptId}</if>
            <if test="villageDeptId != null">and r.village_dept_id = #{villageDeptId}</if>
            <if test="cooperativeName != null and cooperativeName != ''">and r.cooperative_name like concat('%', #{cooperativeName}, '%')</if>
        </where>
        order by r.stat_year desc, r.stat_month desc, d.order_num asc, r.village_dept_id asc, r.id desc
    </select>

    <insert id="insertBizCooperativeDevelopment" parameterType="com.ruoyi.web.modules.industryservice.domain.BizCooperativeDevelopment"
            useGeneratedKeys="true" keyProperty="id">
        insert into biz_cooperative_development (
            stat_year, stat_month, town_dept_id, town_name, village_dept_id, village_name, cooperative_name, legal_representative, establish_date, registered_capital, year_end_total_assets, member_household_count, member_population_count, poverty_monitor_count, cattle_share_count, sheep_share_count, livestock_share_total, grassland_share_area, labor_share_count, cash_share_amount, other_share_amount, total_income, net_income, cash_dividend, in_kind_dividend, revolving_fund, loss_amount, college_graduate_count, college_graduate_wage, farmer_transfer_employment_count, farmer_transfer_wage, cattle_inventory_count, cattle_outbound_count, sheep_inventory_count, sheep_outbound_count, trademark_product_count, quality_cert_product_count, training_manage_count, training_skill_count, training_other_count, business_scope, business_model, operation_status,
            create_by, create_time, remark
        ) values (
            #{statYear}, #{statMonth}, #{townDeptId}, #{townName}, #{villageDeptId}, #{villageName}, #{cooperativeName}, #{legalRepresentative}, #{establishDate}, #{registeredCapital}, #{yearEndTotalAssets}, #{memberHouseholdCount}, #{memberPopulationCount}, #{povertyMonitorCount}, #{cattleShareCount}, #{sheepShareCount}, #{livestockShareTotal}, #{grasslandShareArea}, #{laborShareCount}, #{cashShareAmount}, #{otherShareAmount}, #{totalIncome}, #{netIncome}, #{cashDividend}, #{inKindDividend}, #{revolvingFund}, #{lossAmount}, #{collegeGraduateCount}, #{collegeGraduateWage}, #{farmerTransferEmploymentCount}, #{farmerTransferWage}, #{cattleInventoryCount}, #{cattleOutboundCount}, #{sheepInventoryCount}, #{sheepOutboundCount}, #{trademarkProductCount}, #{qualityCertProductCount}, #{trainingManageCount}, #{trainingSkillCount}, #{trainingOtherCount}, #{businessScope}, #{businessModel}, #{operationStatus},
            #{createBy}, sysdate(), #{remark}
        )
    </insert>

    <update id="updateBizCooperativeDevelopment" parameterType="com.ruoyi.web.modules.industryservice.domain.BizCooperativeDevelopment">
        update biz_cooperative_development set
            stat_year = #{statYear},
            stat_month = #{statMonth},
            town_dept_id = #{townDeptId},
            town_name = #{townName},
            village_dept_id = #{villageDeptId},
            village_name = #{villageName},
            cooperative_name = #{cooperativeName},
            legal_representative = #{legalRepresentative},
            establish_date = #{establishDate},
            registered_capital = #{registeredCapital},
            year_end_total_assets = #{yearEndTotalAssets},
            member_household_count = #{memberHouseholdCount},
            member_population_count = #{memberPopulationCount},
            poverty_monitor_count = #{povertyMonitorCount},
            cattle_share_count = #{cattleShareCount},
            sheep_share_count = #{sheepShareCount},
            livestock_share_total = #{livestockShareTotal},
            grassland_share_area = #{grasslandShareArea},
            labor_share_count = #{laborShareCount},
            cash_share_amount = #{cashShareAmount},
            other_share_amount = #{otherShareAmount},
            total_income = #{totalIncome},
            net_income = #{netIncome},
            cash_dividend = #{cashDividend},
            in_kind_dividend = #{inKindDividend},
            revolving_fund = #{revolvingFund},
            loss_amount = #{lossAmount},
            college_graduate_count = #{collegeGraduateCount},
            college_graduate_wage = #{collegeGraduateWage},
            farmer_transfer_employment_count = #{farmerTransferEmploymentCount},
            farmer_transfer_wage = #{farmerTransferWage},
            cattle_inventory_count = #{cattleInventoryCount},
            cattle_outbound_count = #{cattleOutboundCount},
            sheep_inventory_count = #{sheepInventoryCount},
            sheep_outbound_count = #{sheepOutboundCount},
            trademark_product_count = #{trademarkProductCount},
            quality_cert_product_count = #{qualityCertProductCount},
            training_manage_count = #{trainingManageCount},
            training_skill_count = #{trainingSkillCount},
            training_other_count = #{trainingOtherCount},
            business_scope = #{businessScope},
            business_model = #{businessModel},
            operation_status = #{operationStatus},
            update_by = #{updateBy},
            update_time = sysdate(),
            remark = #{remark}
        where id = #{id}
    </update>

    <delete id="deleteBizCooperativeDevelopmentByIds">
        delete from biz_cooperative_development where id in
        <foreach collection="ids" item="id" open="(" separator="," close=")">#{id}</foreach>
    </delete>

    <delete id="deleteByYearMonth">
        delete from biz_cooperative_development where stat_year = #{statYear} and stat_month = #{statMonth}
    </delete>
</mapper>
