记得上下班打卡 | git大法好,push需谨慎

Commit 8d996bc9 authored by 姜秀龙's avatar 姜秀龙

admin完善

parent f52ffd52
......@@ -33,9 +33,7 @@ public interface IKylinArtistService extends IService<KylinArtist> {
Boolean checkArtistNameExists(String artistName, String artistId);
List<ArtistGoodsOptionVo> searchGoods(String keyword);
String validateProductSpuIds(List<String> spuIds);
List<ArtistGoodsOptionVo> searchGoods(String keyword, String artistId, List<String> excludeSpuIds);
List<ArtistVo.ProductVo> listArtistProducts(String artistId);
......
......@@ -26,6 +26,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -353,8 +354,19 @@ public class KylinArtistController extends BaseController {
*/
@GetMapping("/searchGoods")
@ResponseBody
public AjaxResult searchGoods(@RequestParam(value = "keyword", required = false) String keyword) {
List<ArtistGoodsOptionVo> list = kylinArtistService.searchGoods(keyword);
public AjaxResult searchGoods(
@RequestParam(value = "keyword", required = false) String keyword,
@RequestParam(value = "artistId", required = false) String artistId,
@RequestParam(value = "excludeSpuIds", required = false) String excludeSpuIds) {
List<String> excludeList = new ArrayList<>();
if (excludeSpuIds != null && !excludeSpuIds.isEmpty()) {
for (String spuId : excludeSpuIds.split(",")) {
if (spuId != null && !spuId.trim().isEmpty()) {
excludeList.add(spuId.trim());
}
}
}
List<ArtistGoodsOptionVo> list = kylinArtistService.searchGoods(keyword, artistId, excludeList);
return AjaxResult.success(list);
}
......
......@@ -175,7 +175,17 @@
function openProductModal(artistId) {
var url = prefix + '/products/' + artistId;
$.modal.open("关联商品", url, '900', '600');
$.modal.openOptions({
title: '关联商品',
url: url,
width: '900',
height: '600',
btn: ['保存', '关闭'],
yes: function (index, layero) {
var iframeWin = layero.find('iframe')[0];
iframeWin.contentWindow.submitHandler(index, layero);
}
});
}
</script>
</body>
......
......@@ -21,7 +21,7 @@
<div class="add-row">
<select id="goodsSelect" style="width:400px;">
<option value="">请输入商品名称搜索...</option>
<option value="">默认最近20条,输入名称搜索全部匹配</option>
</select>
<span style="color:#999;font-size:12px;">选中商品后自动添加到列表</span>
</div>
......@@ -35,19 +35,16 @@
<th>头图</th>
<th>商品名称</th>
<th>状态</th>
<th>售价</th>
<th>操作</th>
</tr>
</thead>
<tbody id="linkedProductsBody">
<tr id="linkedProductsEmptyRow">
<td colspan="6" style="text-align:center;color:#999;">暂无关联商品</td>
<td colspan="5" style="text-align:center;color:#999;">暂无关联商品</td>
</tr>
</tbody>
</table>
</div>
<button type="button" class="btn btn-primary" onclick="saveProducts()">保存</button>
</div>
<th:block th:include="include :: footer"/>
......@@ -65,13 +62,19 @@
function initSelect2() {
$('#goodsSelect').select2({
allowClear: true,
placeholder: '请输入商品名称搜索...',
placeholder: '默认最近20条,输入名称搜索全部匹配',
minimumInputLength: 0,
ajax: {
url: prefix + '/searchGoods',
dataType: 'json',
delay: 300,
data: function (params) { return { keyword: params.term || '' }; },
data: function (params) {
return {
keyword: params.term || '',
artistId: artistId,
excludeSpuIds: linkedProducts.map(function (item) { return item.spuId; }).join(',')
};
},
processResults: function (resp) {
var list = (resp && resp.data) ? resp.data : [];
return { results: list.map(function (item) {
......@@ -105,7 +108,6 @@
spuId: item.spuId,
name: item.productName,
coverPic: item.imageUrl,
sellPrice: item.price ? item.price.replace('元', '') : null,
shelfStatusLabel: item.status === 1 ? '已上架' : '未上架'
};
});
......@@ -118,17 +120,15 @@
var $body = $('#linkedProductsBody');
$body.empty();
if (!linkedProducts.length) {
$body.append('<tr><td colspan="6" style="text-align:center;color:#999;">暂无关联商品</td></tr>');
$body.append('<tr><td colspan="5" style="text-align:center;color:#999;">暂无关联商品</td></tr>');
return;
}
linkedProducts.forEach(function (item, index) {
var priceText = item.sellPrice != null ? item.sellPrice + '元' : '--';
$body.append('<tr>' +
'<td>' + (item.spuId || '--') + '</td>' +
'<td>' + (item.coverPic ? '<img class="img-thumb" src="' + item.coverPic + '">' : '--') + '</td>' +
'<td>' + (item.name || '--') + '</td>' +
'<td>' + (item.shelfStatusLabel || '--') + '</td>' +
'<td>' + priceText + '</td>' +
'<td><button type="button" class="btn btn-danger btn-xs" onclick="removeLinkedProduct(' + index + ')">移除</button></td>' +
'</tr>');
});
......@@ -146,7 +146,6 @@
spuId: raw.spuId,
name: raw.name,
coverPic: raw.coverPic,
sellPrice: raw.sellPrice,
shelfStatusLabel: raw.shelfStatusLabel
});
renderLinkedProducts();
......@@ -157,7 +156,7 @@
renderLinkedProducts();
}
function saveProducts() {
function submitHandler(index, layero) {
var spuIds = linkedProducts.map(function (item) { return item.spuId; });
$.ajax({
url: prefix + '/products/save',
......@@ -166,8 +165,19 @@
data: JSON.stringify({ artistId: artistId, spuIds: spuIds }),
success: function (resp) {
if (resp.code === 0) {
if (parent && parent.$ && parent.$.modal) {
parent.$.modal.msgSuccess('保存成功');
if (parent.$.table) {
parent.$.table.refresh();
}
} else {
$.modal.msgSuccess('保存成功');
loadLinkedProducts();
}
if (typeof index !== 'undefined') {
parent.layer.close(index);
} else {
$.modal.close();
}
} else {
$.modal.alertError(resp.msg || '保存失败');
}
......
......@@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liquidnet.client.admin.zhengzai.goblin.utils.GoblinRedisUtils;
import com.liquidnet.client.admin.zhengzai.kylin.utils.DataUtils;
import com.liquidnet.client.admin.zhengzai.kylin.utils.SweetArtistCacheUtils;
import com.liquidnet.commons.lang.util.BeanUtil;
......@@ -19,7 +18,6 @@ import com.liquidnet.service.kylin.dto.param.ArtistSearchParam;
import com.liquidnet.service.kylin.dto.vo.ArtistGoodsOptionVo;
import com.liquidnet.service.kylin.dto.vo.ArtistVo;
import com.liquidnet.service.kylin.entity.KylinArtist;
import com.liquidnet.service.goblin.dto.vo.GoblinGoodsInfoVo;
import com.liquidnet.service.goblin.entity.GoblinGoods;
import com.liquidnet.service.goblin.mapper.GoblinGoodsMapper;
import com.liquidnet.service.kylin.entity.KylinArtistAlbum;
......@@ -39,8 +37,10 @@ import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -77,9 +77,6 @@ public class KylinArtistServiceImpl extends ServiceImpl<KylinArtistMapper, Kylin
@Autowired
private SweetArtistCacheUtils sweetArtistCacheUtils;
@Autowired
private GoblinRedisUtils goblinRedisUtils;
@Autowired
private GoblinGoodsMapper goblinGoodsMapper;
......@@ -346,14 +343,17 @@ public class KylinArtistServiceImpl extends ServiceImpl<KylinArtistMapper, Kylin
if (artist == null) {
return false;
}
List<String> normalizedSpuIds = spuIds == null ? Collections.emptyList() : spuIds;
String productError = validateProductSpuIds(normalizedSpuIds);
if (productError != null) {
throw new IllegalArgumentException(productError);
LinkedHashSet<String> uniqueSpuIds = new LinkedHashSet<>();
if (spuIds != null) {
for (String spuId : spuIds) {
if (spuId != null && !spuId.trim().isEmpty()) {
uniqueSpuIds.add(spuId.trim());
}
}
}
artistProductMapper.deleteByArtistId(artistId);
if (!normalizedSpuIds.isEmpty()) {
saveProductRelations(artistId, normalizedSpuIds);
if (!uniqueSpuIds.isEmpty()) {
saveProductRelations(artistId, new ArrayList<>(uniqueSpuIds));
}
operationLogService.recordLog(artistId, 2, "更新了艺人关联商品");
dataUtils.delArtistProductsCache(artistId);
......@@ -361,13 +361,19 @@ public class KylinArtistServiceImpl extends ServiceImpl<KylinArtistMapper, Kylin
}
@Override
public List<ArtistGoodsOptionVo> searchGoods(String keyword) {
public List<ArtistGoodsOptionVo> searchGoods(String keyword, String artistId, List<String> excludeSpuIds) {
Set<String> excludeSet = buildExcludeSpuIds(artistId, excludeSpuIds);
boolean hasKeyword = keyword != null && !keyword.trim().isEmpty();
LambdaQueryWrapper<GoblinGoods> query = Wrappers.lambdaQuery(GoblinGoods.class)
.ne(GoblinGoods::getDelFlg, "1")
.orderByDesc(GoblinGoods::getMid)
.last("LIMIT 50");
if (keyword != null && !keyword.trim().isEmpty()) {
.orderByDesc(GoblinGoods::getMid);
if (!excludeSet.isEmpty()) {
query.notIn(GoblinGoods::getSpuId, excludeSet);
}
if (hasKeyword) {
query.like(GoblinGoods::getName, keyword.trim());
} else {
query.last("LIMIT 20");
}
List<GoblinGoods> goodsList = goblinGoodsMapper.selectList(query);
List<ArtistGoodsOptionVo> result = new ArrayList<>();
......@@ -377,40 +383,26 @@ public class KylinArtistServiceImpl extends ServiceImpl<KylinArtistMapper, Kylin
return result;
}
@Override
public String validateProductSpuIds(List<String> spuIds) {
if (spuIds == null || spuIds.isEmpty()) {
return null;
private Set<String> buildExcludeSpuIds(String artistId, List<String> excludeSpuIds) {
Set<String> excludeSet = new HashSet<>();
if (artistId != null && !artistId.isEmpty()) {
List<KylinArtistProduct> relations = artistProductMapper.selectByArtistId(artistId);
if (relations != null) {
for (KylinArtistProduct relation : relations) {
if (relation.getSpuId() != null && !relation.getSpuId().isEmpty()) {
excludeSet.add(relation.getSpuId());
}
LinkedHashSet<String> uniqueIds = new LinkedHashSet<>();
for (String spuId : spuIds) {
if (spuId != null && !spuId.trim().isEmpty()) {
uniqueIds.add(spuId.trim());
}
}
List<String> invalidIds = new ArrayList<>();
for (String spuId : uniqueIds) {
if (!isProductExists(spuId)) {
invalidIds.add(spuId);
}
if (excludeSpuIds != null) {
for (String spuId : excludeSpuIds) {
if (spuId != null && !spuId.trim().isEmpty()) {
excludeSet.add(spuId.trim());
}
if (invalidIds.isEmpty()) {
return null;
}
return "以下商品不存在或已删除:" + String.join("、", invalidIds);
}
private boolean isProductExists(String spuId) {
GoblinGoodsInfoVo goods = goblinRedisUtils.getGoodsInfoVo(spuId);
if (goods != null && "0".equals(goods.getDelFlg())) {
return true;
}
Integer count = goblinGoodsMapper.selectCount(
Wrappers.lambdaQuery(GoblinGoods.class)
.eq(GoblinGoods::getSpuId, spuId)
.ne(GoblinGoods::getDelFlg, "1")
);
return count != null && count > 0;
return excludeSet;
}
private ArtistGoodsOptionVo buildGoodsOption(GoblinGoods goods) {
......@@ -419,19 +411,8 @@ public class KylinArtistServiceImpl extends ServiceImpl<KylinArtistMapper, Kylin
vo.setSpuNo(goods.getSpuNo());
vo.setName(goods.getName());
vo.setCoverPic(goods.getCoverPic());
GoblinGoodsInfoVo cache = goblinRedisUtils.getGoodsInfoVo(goods.getSpuId());
if (cache != null) {
vo.setSellPrice(cache.getSellPrice());
vo.setShelfStatusLabel(resolveShelfStatusLabel(cache.getShelvesStatus(), cache.getDelFlg()));
vo.setSelectable("0".equals(cache.getDelFlg()));
} else {
vo.setSellPrice(goods.getSellPrice());
vo.setShelfStatusLabel(resolveShelfStatusLabel(goods.getShelvesStatus(), goods.getDelFlg()));
vo.setSelectable(!"1".equals(goods.getDelFlg()));
}
if (vo.getSelectable() == null) {
vo.setSelectable(true);
}
return vo;
}
......@@ -507,12 +488,16 @@ public class KylinArtistServiceImpl extends ServiceImpl<KylinArtistMapper, Kylin
}
private ArtistVo.ProductVo buildProductVo(String spuId) {
GoblinGoodsInfoVo goods = goblinRedisUtils.getGoodsInfoVo(spuId);
GoblinGoods goods = goblinGoodsMapper.selectOne(
Wrappers.lambdaQuery(GoblinGoods.class)
.eq(GoblinGoods::getSpuId, spuId)
.ne(GoblinGoods::getDelFlg, "1")
);
if (goods == null) {
ArtistVo.ProductVo vo = new ArtistVo.ProductVo();
vo.setSpuId(spuId);
vo.setProductCode(spuId);
vo.setProductName("商品不存在或缓存未命中");
vo.setProductName("商品不存在");
vo.setStatus(0);
return vo;
}
......@@ -521,12 +506,7 @@ public class KylinArtistServiceImpl extends ServiceImpl<KylinArtistMapper, Kylin
vo.setProductCode(goods.getSpuNo() != null ? goods.getSpuNo() : goods.getSpuId());
vo.setProductName(goods.getName());
vo.setImageUrl(goods.getCoverPic());
vo.setCategory(goods.getStoreName() != null ? goods.getStoreName() : "--");
if (goods.getSellPrice() != null) {
vo.setPrice(goods.getSellPrice().toPlainString() + "元");
} else {
vo.setPrice("--");
}
vo.setCategory("--");
vo.setStatus("3".equals(goods.getShelvesStatus()) ? 1 : 0);
return vo;
}
......
......@@ -10,10 +10,9 @@
ORDER BY sort DESC, mid DESC
</select>
<update id="deleteByArtistId" parameterType="java.lang.String">
UPDATE kylin_artist_product
SET status = 0, updated_at = NOW()
<delete id="deleteByArtistId" parameterType="java.lang.String">
DELETE FROM kylin_artist_product
WHERE artist_id = #{artistId}
</update>
</delete>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment