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

sql 优化

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