<?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.epmet.dao.CodeCustomerDao" >
<resultMap type= "com.epmet.entity.CodeCustomerEntity" id= "codeCustomerMap" >
<result property= "id" column= "ID" />
<result property= "customerId" column= "CUSTOMER_ID" />
<result property= "customerName" column= "CUSTOMER_NAME" />
<result property= "templateId" column= "TEMPLATE_ID" />
<result property= "clientType" column= "CLIENT_TYPE" />
<result property= "appId" column= "APP_ID" />
<result property= "extJson" column= "EXT_JSON" />
<result property= "userVersion" column= "USER_VERSION" />
<result property= "userDesc" column= "USER_DESC" />
<result property= "status" column= "STATUS" />
<result property= "revision" column= "REVISION" />
<result property= "delFlag" column= "DEL_FLAG" />
<result property= "createdBy" column= "CREATED_BY" />
<result property= "createdTime" column= "CREATED_TIME" />
<result property= "updatedBy" column= "UPDATED_BY" />
<result property= "updatedTime" column= "UPDATED_TIME" />
</resultMap>
<select id= "selectCodeList" resultType= "com.epmet.dto.result.UploadListResultDTO" parameterType= "com.epmet.dto.form.UploadListFormDTO" >
SELECT
cc.ID,
cc.CUSTOMER_ID,
cc.CUSTOMER_NAME,
cc.CLIENT_TYPE,
cc.APP_ID,
cc.USER_VERSION AS "version",
cc.USER_DESC AS "codeInfo",
cc.STATUS,
DATE_FORMAT(cc.CREATED_TIME,'%Y-%m-%d %T') AS "uploadTime",
IFNULL(DATE_FORMAT(car.CREATED_TIME,'%Y-%m-%d %T'),'') AS "auditTime",
car.AUDIT_ID
FROM code_customer cc
LEFT JOIN code_audit_result car ON cc.ID = car.CODE_ID AND car.DEL_FLAG = '0'
WHERE
cc.DEL_FLAG = '0'
AND cc.SOURCE = #{source}
<if test= "customerId != null and customerId.trim() != ''" >
AND cc.CUSTOMER_ID = #{customerId}
</if>
<if test= "clientType != null and clientType.trim() != ''" >
AND cc.CLIENT_TYPE = #{clientType}
</if>
<if test= "status != null and status.trim() != ''" >
AND cc.STATUS = #{status}
</if>
<if test= "startTime != null and startTime.trim() != ''" >
AND DATE_FORMAT(cc.CREATED_TIME, '%Y-%m-%d') <![CDATA[ >= ]]> #{startTime}
</if>
<if test= "endTime != null and endTime.trim() != ''" >
AND DATE_FORMAT(cc.CREATED_TIME, '%Y-%m-%d') <![CDATA[ <= ]]> #{endTime}
</if>
</select>
<!-- 根据客户id和客户端类型获取 代码模板ID和授权方AppId -->
<select id= "selectTemplateAndAppId" resultType= "com.epmet.dto.result.TemplateAndAppIdResultDTO" >
SELECT
template_id AS templateId,
app_id AS authAppId
FROM
code_customer
WHERE
del_flag = '0'
AND customer_id = #{customerId}
AND client_type = #{clientType}
order by created_time desc
LIMIT 1
</select>
<!-- 查询 code_customer 表ID -->
<select id= "selectCodeCustomerId" resultType= "java.lang.String" >
SELECT
id AS id
FROM
code_customer
WHERE
del_flag = '0'
AND customer_id = #{customerId}
AND client_type = #{clientType}
AND app_id = #{authAppId}
AND template_id = #{templateId}
</select>
<select id= "selectAuditingCodeList" resultType= "com.epmet.dto.CodeCustomerDTO" >
select * FROM code_customer WHERE DEL_FLAG = '0' AND STATUS = 'auditing' AND SOURCE = #{source}
</select>
<select id= "selectUploadCodeByCustomer" resultType= "com.epmet.dto.CodeCustomerDTO" >
SELECT
ID, STATUS
FROM
code_customer
WHERE CUSTOMER_ID = #{customerId}
AND CLIENT_TYPE = #{clientType}
AND DEL_FLAG = '0'
</select>
<update id= "deleteCode" >
UPDATE code_customer
SET
DEL_FLAG = '1'
WHERE CUSTOMER_ID = #{customerId}
AND CLIENT_TYPE = #{clientType}
AND STATUS = 'release_success'
AND DEL_FLAG = '0'
</update>
<select id= "selectCommitInfo" resultType= "com.epmet.dto.CodeCustomerDTO" >
SELECT ID,
USER_VERSION,
USER_DESC,
TEMPLATE_ID,
COMMIT_TIME
FROM code_customer
WHERE CUSTOMER_ID = #{customerId}
AND CLIENT_TYPE = #{clientType}
AND STATUS = 'unaudited'
AND DEL_FLAG = '0'
</select>
<select id= "selectAuditInfo" resultType= "com.epmet.dto.CodeCustomerDTO" >
SELECT ID,
USER_VERSION,
USER_DESC,
COMMIT_TIME,
AUDIT_TIME,
STATUS
FROM code_customer
WHERE CUSTOMER_ID = #{customerId}
AND CLIENT_TYPE = #{clientType}
AND (STATUS = 'auditing' OR STATUS = 'audit_success' OR STATUS = 'audit_failed' OR STATUS = 'withdrawn' OR STATUS = 'delay' OR STATUS = 'release_failed')
AND DEL_FLAG = '0'
</select>
<select id= "selectReleaseInfo" resultType= "com.epmet.dto.CodeCustomerDTO" >
SELECT ID,
USER_VERSION,
USER_DESC,
COMMIT_TIME,
AUDIT_TIME,
RELEASE_TIME,
RELEASE_TYPE,
GARY_PERCENTAGE
FROM code_customer
WHERE CUSTOMER_ID = #{customerId}
AND CLIENT_TYPE = #{clientType}
AND STATUS = 'release_success'
AND DEL_FLAG = '0'
</select>
<select id= "selectLastVersion" resultType= "com.epmet.dto.CodeCustomerDTO" >
SELECT ID
FROM code_customer
WHERE CUSTOMER_ID = #{customerId}
AND CLIENT_TYPE = #{clientType}
AND STATUS = 'release_success'
AND DEL_FLAG = '1'
ORDER BY RELEASE_TIME DESC
LIMIT 1
</select>
<update id= "updateVersion" >
UPDATE code_customer
SET
DEL_FLAG = '0'
WHERE ID = #{codeId}
</update>
</mapper>