提交 ac372935 authored 作者: 吴德鹏's avatar 吴德鹏

sql 优化

上级 d3ce48a9
......@@ -30,4 +30,6 @@ public interface TbCfStationItemDao extends BaseDao<TbCfStationItemEntity> {
int queryTopCount();
TbCfStationItemEntity queryItemBySort(Integer sort);
int updateItemSort(TbCfStationItemEntity item);
}
......@@ -22,6 +22,8 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* 站点商品Service实现类
......@@ -52,6 +54,7 @@ public class TbCfStationItemServiceImpl implements TbCfStationItemService {
@Autowired
private TbCfItemParamDao tbCfItemParamDao;
@Override
public ItemInfo queryItemInfoById(String itemId) {
//查询商品主体信息
......@@ -480,7 +483,7 @@ public class TbCfStationItemServiceImpl implements TbCfStationItemService {
@Override
public int itemTop(String itemId) {
TbCfStationItemEntity item = tbCfStationItemDao.queryObject(itemId);
if ("2".equals(item.getEnableFlag().toString())) {
if ("2".equals(String.valueOf(item.getEnableFlag()))) {
return -1;
}
item.setItemTop(1);
......@@ -500,19 +503,24 @@ public class TbCfStationItemServiceImpl implements TbCfStationItemService {
@Override
public int itemUpward(String itemId) {
int res = 0;
TbCfStationItemEntity item = tbCfStationItemDao.queryObject(itemId);
Integer sort = item.getSort();
if ("1".equals(sort.toString())) {
if ("1".equals(String.valueOf(sort))) {
return -1;
}
TbCfStationItemEntity upItem = tbCfStationItemDao.queryItemBySort(sort - 1);
upItem.setSort(sort);
int res1 = tbCfStationItemDao.update(upItem);
int res1 = tbCfStationItemDao.updateItemSort(upItem);
item.setSort(sort - 1);
int res2 = tbCfStationItemDao.update(item);
int res2 = tbCfStationItemDao.updateItemSort(item);
if (res1 > 0 && res2 > 0) {
res = 1;
}
return res;
}
......@@ -522,14 +530,14 @@ public class TbCfStationItemServiceImpl implements TbCfStationItemService {
TbCfStationItemEntity item = tbCfStationItemDao.queryObject(itemId);
Integer sort = item.getSort();
int count = tbCfStationItemDao.queryTopCount();
if (String.valueOf(count).equals(sort.toString())) {
if (String.valueOf(count).equals(String.valueOf(sort))) {
return -1;
}
TbCfStationItemEntity downItem = tbCfStationItemDao.queryItemBySort(sort + 1);
downItem.setSort(sort);
int res1 = tbCfStationItemDao.update(downItem);
int res1 = tbCfStationItemDao.updateItemSort(downItem);
item.setSort(sort + 1);
int res2 = tbCfStationItemDao.update(item);
int res2 = tbCfStationItemDao.updateItemSort(item);
if (res1 > 0 && res2 > 0) {
res = 1;
}
......
......@@ -119,17 +119,11 @@
i.item_id,
i.item_code,
i.item_name,
i.item_brief,
i.item_category,
i.item_price,
i.discount_price,
i.cost_price,
i.item_url,
i.item_img,
i.item_count,
i.item_num,
i.platform_code,
i.platform_name,
i.enable_flag,
i.create_time,
i.item_categorytwo,
......@@ -137,26 +131,20 @@
i.item_top,
i.sort,
i.supplier,
i.template,
i.sku_imgs,
i.creator,
d.descripition_name dname,
t.goodstwotype_title title,
o.goodstype_title goodtype,
u.user_name uname
o.goodstype_title goodtype
FROM
tb_cf_station_item i
left JOIN tb_cf_goodstype o ON o.goodstype_id = i.item_category
left JOIN tb_cf_goodstwotype t ON i.item_categorytwo=t.goodstwotype_id
left JOIN tb_cf_descripiton d ON i.item_descrition_id=d.descripition_id
left JOIN tb_cf_express_template e ON i.item_descrition_id = e.template_id
left join sys_user u on i.creator=u.user_id
WHERE 1=1 and i.enable_flag!=0
WHERE i.enable_flag!=0
<if test="creator != null and creator.trim() != ''">
AND creator=#{creator}
</if>
<if test="name != null and name.trim() != ''">
AND item_name LIKE concat('%',#{name},'%') or item_id LIKE concat('%',#{name},'%')
AND item_name LIKE concat('%',#{name},'%') or item_id= #{name}
</if>
<if test="code != null and code.trim() != ''">
AND item_code=#{code}
......@@ -217,7 +205,7 @@
select count(*) from tb_cf_station_item
WHERE 1=1 and enable_flag!=0
<if test="name != null and name.trim() != ''">
AND item_name LIKE concat('%',#{name},'%') or item_id LIKE concat('%',#{name},'%')
AND item_name LIKE concat('%',#{name},'%') or item_id =#{name}
</if>
<if test="code != null and code.trim() != ''">
AND item_code=#{code}
......@@ -336,6 +324,10 @@
where item_id = #{itemId}
</update>
<update id="updateItemSort" parameterType="com.platform.entity.TbCfStationItemEntity">
update tb_cf_station_item set `sort` = #{sort} where item_id=#{itemId}
</update>
<delete id="delete">
delete from tb_cf_station_item where item_id = #{value}
</delete>
......
......@@ -11,7 +11,7 @@ $(function () {
{label: '商品原价', name: 'itemPrice', index: 'item_price', width: 45},
{label: '商品现价', name: 'discountPrice', index: 'discount_price', width: 45},
{label: '库存', name: 'itemCount', index: 'item_count', width: 45},
{label: '点击量', name: 'itemNum', index: 'item_num', width: 45},
// {label: '点击量', name: 'itemNum', index: 'item_num', width: 45},
/*{label: '所属平台', name: 'platformCode', index: 'platform_code', width: 80},
{label: '平台名', name: 'platformName', index: 'platform_name', width: 80},*/
{label: '供应商', name: 'supplier', index: 'supplier', width: 80},
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论