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

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

admin完善

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