insert into PPW_EMAIL.company_email_send_history(company_id,email,send_status,send_time,send_remark,isvalid,createtime,updatetime,creatorid,updaterid)
values (#{companyId},#{email},#{sendStatus},#{sendTime},#{sendRemark},#{isvalid},#{createTime},#{updateTime},#{creatorId},#{updaterId})
update PPW_EMAIL.company_email_send_history set isvalid =0,updatetime=sysdate() where email in
#{email}
update PPW_EMAIL.company_email_send_history set isvalid =0,updatetime=sysdate() where id in
#{id}
SELECT
cec.id,
cec.company_id,
c.company_name,
cec.email,
maxce.send_time,
maxce.send_remark,
ifnull(maxce.send_status,-1) as send_status
FROM
PPW_EMAIL.company_email_config cec
JOIN PPW_EMAIL.pvn_company_info c
ON cec.company_id = c.company_id
LEFT JOIN (select me.email as email,max(me.send_time) as send_time,me.company_id,me.send_remark,me.send_status from PPW_EMAIL.company_email_send_history me where isvalid =1 group by me.email,me.company_id) maxce
ON cec.email = maxce.email and cec.company_id = maxce.company_id
WHERE cec.isvalid = 1 and c.isvalid=1
and (c.company_name like concat('%',#{companyName},'%') or c.company_short_name like concat('%',#{companyName},'%') or c.register_number like concat('%',#{companyName},'%'))
and cec.email like concat('%',#{email},'%')
and maxce.send_status=#{sendStatus}
order by maxce.send_time desc
limit #{offset},#{pageSize}
SELECT
count(cec.company_id)
from
PPW_EMAIL.company_email_config cec
JOIN PPW_EMAIL.pvn_company_info c
ON cec.company_id = c.company_id
LEFT JOIN (select me.email as email,max(me.send_time) as send_time,me.company_id,me.send_remark,me.send_status from PPW_EMAIL.company_email_send_history me where isvalid =1 group by me.email,me.company_id) maxce
ON cec.email = maxce.email and cec.company_id = maxce.company_id
WHERE cec.isvalid = 1 and c.isvalid=1
and (c.company_name like concat('%',#{companyName},'%') or c.company_short_name like concat('%',#{companyName},'%') or c.register_number like concat('%',#{companyName},'%'))
and cec.email like concat('%',#{email},'%')
and maxce.send_status=#{sendStatus}
SELECT distinct
cesh.id,
cec.company_id,
c.company_name,
cesh.email,
cesh.send_time,
cesh.send_remark,
cesh.send_status
FROM
PPW_EMAIL.company_email_send_history cesh
JOIN PPW_EMAIL.company_email_config cec
ON cec.email = cesh.email
JOIN PPW_EMAIL.pvn_company_info c
ON cec.company_id = c.company_id
WHERE cec.isvalid = 1
AND cesh.isvalid = 1 and c.isvalid =1
and c.company_id=#{companyId}
limit #{offset},#{pageSize}
SELECT
count(distinct cesh.id)
FROM
PPW_EMAIL.company_email_send_history cesh
JOIN PPW_EMAIL.company_email_config cec
ON cec.email = cesh.email
JOIN PPW_EMAIL.pvn_company_info c
ON cec.company_id = c.company_id
WHERE cec.isvalid = 1
AND cesh.isvalid = 1 and c.isvalid =1
and c.company_id=#{companyId}