Authored by caoyan

二手商品审核

... ... @@ -9,4 +9,6 @@ public interface SecondhandFlawMapper {
List<SecondhandFlaw> selectByType(@Param("type") Integer type);
List<SecondhandFlaw> selectByIds(@Param("ids") String ids);
List<SecondhandFlaw> selectBatchByIds(@Param("idList") List<Integer> idList);
}
\ No newline at end of file
... ...
... ... @@ -75,4 +75,6 @@ public interface StoragePriceMapper {
Integer selectFirstUidByProductIdAndUidList(@Param("productId") Integer productId, @Param("uidList") List<Integer> uidList);
List<StoragePrice> selectBySkupList(@Param("skupList") List<Integer> skupList);
int updateStatusBySkup(@Param("status") Integer status, @Param("skup") Integer skup);
}
\ No newline at end of file
... ...
... ... @@ -19,5 +19,13 @@
<select id="selectByIds" resultMap="BaseResultMap">
select * from secondhand_flaw where id in(${ids})
</select>
<select id="selectBatchByIds" resultMap="BaseResultMap">
select id, type, name, attr, order_by
from secondhand_flaw where id in
<foreach collection="idList" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -371,4 +371,7 @@
</foreach>
</select>
<update id="updateStatusBySkup">
update storage_price set status=#{status}, update_time=unix_timestamp() where skup=#{skup}
</update>
</mapper>
\ No newline at end of file
... ...
package com.yoho.ufo.controller.product;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
... ... @@ -8,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yoho.product.model.SecondhandImages;
import com.yoho.product.model.SecondhandReq;
import com.yoho.product.model.SecondhandRsp;
import com.yoho.ufo.service.ISecondhandProductService;
... ... @@ -45,7 +47,13 @@ public class SecondhandProductController {
}else {
return new ApiResponse.ApiResponseBuilder().code(500).message("查询失败").build();
}
}
@RequestMapping(value = "/queryImageList")
public ApiResponse queryImageList(SecondhandReq req) {
LOGGER.info("querySkupList in. req is {}", req);
List<SecondhandImages> result = secondhandProductService.queryImageList(req.getSkup());
return new ApiResponse.ApiResponseBuilder().code(200).message("查询成功").data(result).build();
}
}
... ...
package com.yoho.ufo.service;
import java.util.List;
import java.util.Map;
import com.yoho.product.model.SecondhandImages;
import com.yoho.product.model.SecondhandReq;
import com.yoho.product.model.SecondhandRsp;
import com.yoho.ufo.service.model.PageResponseBO;
... ... @@ -15,4 +17,6 @@ public interface ISecondhandProductService {
int updateStatus(SecondhandReq req);
List<SecondhandImages> queryImageList(Integer skup);
}
... ...
package com.yoho.ufo.service.impl;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.elasticsearch.common.collect.Lists;
import org.elasticsearch.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.order.dal.SellerOrderGoodsMapper;
import com.yoho.order.model.SellerOrderGoods;
import com.yoho.product.dal.SecondhandFlawMapper;
import com.yoho.product.dal.SecondhandImagesMapper;
import com.yoho.product.dal.SecondhandInfoMapper;
import com.yoho.product.model.SecondhandFlaw;
import com.yoho.product.model.SecondhandImages;
import com.yoho.product.model.SecondhandInfo;
import com.yoho.product.model.SecondhandReq;
... ... @@ -27,10 +35,13 @@ import com.yoho.ufo.service.model.PageResponseBO;
import com.yoho.ufo.util.DateUtil;
import com.yohobuy.ufo.model.enums.ProductSkupStatusEnum;
import com.yohobuy.ufo.model.enums.StorageTypeEnum;
import com.yohobuy.ufo.model.order.req.SellerOrderCancelReq;
@Service
public class SecondhandProductService implements ISecondhandProductService{
private static final Logger LOGGER = LoggerFactory.getLogger(SecondhandProductService.class);
@Autowired
private SecondhandInfoMapper secondhandInfoMapper;
... ... @@ -46,6 +57,12 @@ public class SecondhandProductService implements ISecondhandProductService{
@Autowired
private ProductMapper productMapper;
@Autowired
private SecondhandFlawMapper secondhandFlawMapper;
@Autowired
private ServiceCaller serviceCaller;
private static final Integer STATUS_NEW = 0;
private static final Integer STATUS_WAIT_TO_BE_AUDITED = 10;
... ... @@ -102,8 +119,13 @@ public class SecondhandProductService implements ISecondhandProductService{
List<Product> productList = productMapper.selectProductListByIds(productIdList);
Map<Integer, String> productIdNameMap = productList.stream().collect(Collectors.toMap(Product::getId, Product::getProductName));
//查询secondhand_flaw
List<String> flawIdStrList = infoList.stream().map(SecondhandInfo::getFlawId).collect(Collectors.toList());
List<SecondhandFlaw> flawList = secondhandFlawMapper.selectBatchByIds(getFlawIdList(flawIdStrList));
Map<Integer, String> flawMap = flawList.stream().collect(Collectors.toMap(SecondhandFlaw::getId, SecondhandFlaw::getName));
//组装
List<SecondhandRsp> respList = convertToResp(infoList, skupImageMap, storagePriceMap, sellerGoodsMap, productIdNameMap);
List<SecondhandRsp> respList = convertToResp(infoList, skupImageMap, storagePriceMap, sellerGoodsMap, productIdNameMap, flawMap);
PageResponseBO<SecondhandRsp> result=new PageResponseBO<>();
result.setList(respList);
... ... @@ -124,26 +146,85 @@ public class SecondhandProductService implements ISecondhandProductService{
auditInfo.setAuditName(userInfo.getUserName());
auditInfo.setAuditUid(userInfo.getUserId());
auditInfo.setAuditTime(DateUtil.getCurrentTimeSeconds());
return secondhandInfoMapper.updateAuditInfoBySkup(auditInfo);
int num = secondhandInfoMapper.updateAuditInfoBySkup(auditInfo);
if(num ==0) {
return num;
}
//更新storage_price
num = storagePriceMapper.updateStatusBySkup(req.getStatus(), req.getSkup());
if(num == 0) {
return num;
}
//审核不通过,调用前台接口/erp/auditFailed
if(req.getStatus().equals(ProductSkupStatusEnum.CHECK_REJEST.getStatus())) {
asyncCallAuditFail("ufo-gateway.auditFailed", req.getSkup(), req.getRejectReason());
}
return num;
}
public List<SecondhandImages> queryImageList(Integer skup){
List<SecondhandImages> list = secondhandImagesMapper.selectBySkups(Lists.newArrayList(skup));
List<Integer> codeList = list.stream().map(SecondhandImages::getCode).collect(Collectors.toList());
List<SecondhandFlaw> flawList = secondhandFlawMapper.selectBatchByIds(codeList);
Map<Integer, String> flawIdNameMap = flawList.stream().collect(Collectors.toMap(SecondhandFlaw::getId, SecondhandFlaw::getName));
rebuiltImageList(list, flawIdNameMap);
return list;
}
private JSONObject asyncCallAuditFail(String args, Integer skup, String rejectReason) {
LOGGER.info("asyncCallAuditFail call ufo-gateway enter skup is {}, interface is {}", skup, args);
SellerOrderCancelReq request = new SellerOrderCancelReq();
request.setSkup(skup);
request.setRejectReason(rejectReason);
JSONObject jsonObject = serviceCaller.asyncCall(args, request, JSONObject.class).get(5, TimeUnit.SECONDS);
LOGGER.info("asyncCallAuditFail call ufo-gateway skup is {}, interface is {},result is {}", skup, args, jsonObject);
return jsonObject;
}
private List<Integer> getFlawIdList(List<String> flawIdStrList){
List<Integer> flawIdList = Lists.newArrayList();
for(String item : flawIdStrList) {
String[] idStrArr = item.split(",");
for(int i=0; i<idStrArr.length; i++) {
flawIdList.add(Integer.parseInt(idStrArr[i]));
}
}
return removeDuplicate(flawIdList);
}
public static List removeDuplicate(List list) {
HashSet h = new HashSet(list);
list.clear();
list.addAll(h);
return list;
}
private List<SecondhandRsp> convertToResp(List<SecondhandInfo> infoList, Map<Integer, List<SecondhandImages>> skupImageMap,
Map<Integer, StoragePrice> storagePriceMap, Map<Integer, SellerOrderGoods> sellerGoodsMap,
Map<Integer, String> productIdNameMap){
Map<Integer, String> productIdNameMap, Map<Integer, String> flawMap){
List<SecondhandRsp> respList = Lists.newArrayList();
for(SecondhandInfo item : infoList) {
SecondhandRsp rsp = new SecondhandRsp();
Integer skup = item.getSkup();
rsp.setSkup(skup);
StoragePrice storagePrice = storagePriceMap.get(skup);
if(null == storagePrice) {
continue;
}
rsp.setSkupType(storagePrice.getPreSaleFlag());
rsp.setSkupTypeStr(StorageTypeEnum.getTypeName(storagePrice.getPreSaleFlag()));
List<SecondhandImages> secondhandImagesList = skupImageMap.get(skup);
rebuiltImageList(secondhandImagesList, flawMap);
rsp.setImageList(secondhandImagesList);
rsp.setProductImage(getProductImage(secondhandImagesList));
rsp.setDescribeInfo(item.getDescribeInfo());
rsp.setSku(storagePrice.getStorageId());
SellerOrderGoods sellerGoods = sellerGoodsMap.get(skup);
if(null == sellerGoods) {
continue;
}
rsp.setColorName(sellerGoods.getColorName());
rsp.setSizeName(sellerGoods.getSizeName());
rsp.setSellerUid(storagePrice.getSellerUid());
... ... @@ -162,6 +243,12 @@ public class SecondhandProductService implements ISecondhandProductService{
return respList;
}
private void rebuiltImageList(List<SecondhandImages> imageList, Map<Integer, String> flawIdNameMap) {
for(SecondhandImages image : imageList) {
image.setImageDesc(flawIdNameMap.get(image.getCode()));
}
}
private String getProductImage(List<SecondhandImages> imageList) {
String imageUrl = "";
if(CollectionUtils.isNotEmpty(imageList)) {
... ...
... ... @@ -31,10 +31,24 @@
<img id="simg" src="" alt="" width="800">
</div>
</div>
<div id="w" class="easyui-window" title="卖家上传图片" data-options="modal:true,closed:true" style="width:500px;height:600px;padding:10px;">
<div align="center">
<img id="showImg" height="500px;" width="400px;" onclick="window.open(this.src)"/>
</div>
<div align="center">
<span id="imageInfo"></span>
</div>
<div align="center">
<input style="float:left" type="button" value="上一张" onclick="lastImg()"/>
<input style="float:right" type="button" value="下一张" onclick="nextImg()"/>
</div>
</div>
<script>
const tab_status_to_be_audited=10;
const tab_status_audit_pass=1;
const tab_status_audit_reject=11;
var index=0;
var images;
$(function() {
//获取状态对应的记录数
getCountByStatus();
... ... @@ -46,13 +60,6 @@ $(function() {
}
});
//放大图片预览
$(".pimg1").on('click', function(){
alert("+++++++++****");
var _this = $(this);//将当前的pimg元素作为_this传入函数
download(_this.attr("src"));
});
function tabsSelected(index) {
if(index == 0){
getAllList();
... ... @@ -171,7 +178,7 @@ function addRejectPage(skup) {
id: "rejectBtn",
iconCls: "icon-save",
onClick: function () {
$('#rejectBtn').linkbutton('disable');
//$('#rejectBtn').linkbutton('disable');
auditReject(skup, div);
}
}]
... ... @@ -180,10 +187,15 @@ function addRejectPage(skup) {
//审核不通过
function auditReject(skup, div) {
var rejectReason = $("#rejectReason").textbox("getValue");
if(null == rejectReason || rejectReason == ''){
alert("审核不通过原因必填!");
return;
}
$.post(contextPath + "/secondhand/updateAuditInfo", {
skup : skup,
status : tab_status_audit_reject,
rejectReason: $("#rejectReason").textbox("getValue")
rejectReason: rejectReason
}, function(data) {
if (data.code == 200) {
reloadTableAndFreshCount();
... ... @@ -245,7 +257,7 @@ function getTableColumn() {
formatter: function (value, rowData, rowIndex) {
var imageStr = "<table><tbody><tr>";
for (var i = 0 ;i < value.length; i++){
imageStr += "<td><img height='70px;' width='50px;' src='"+value[i].imageUrl+"'/></td>";
imageStr += "<td><a href='javascript:void(0)' onclick='openModal("+i+",\""+value[i].imageUrl+"\", \""+value[i].imageDesc+"\","+rowData.skup+")'><img height='70px;' width='50px;' src='"+value[i].imageUrl+"'/></td></a>";
if((i+1) % 4 == 0 && 0 != i && i != (value.length - 1)) {
imageStr += "</tr><tr>";
}
... ... @@ -309,18 +321,57 @@ function getTableColumn() {
}]
}
function download(url) {
alert("++++++*********");
$('#dlg').dialog({
title: '预览',
width: 800,
height: 600,
resizable: false,
closed: false,
cache: false,
modal: true
});
$("#simg").attr("src", url);
function openModal(indexNo, imageUrl, imageInfo, skup){
$("#showImg").attr("src",imageUrl);
$("#imageInfo").text(imageInfo);
var form = new FormData();
form.append("skup", skup);
//发送请求
$.ajax({
type: "POST",
url: contextPath + '/secondhand/queryImageList',
data: form,
async: false,
cache: false,
contentType: false,
processData: false,
dataType: 'json',
success: function (result) {
if(result.code == 200) {
images = result.data;
}else{
alert("error!");
}
}
});
index = indexNo;
$("#w").window("open");
}
//建立 上一张 按钮函数
function lastImg(){
//下一张是index++ 上一张是index--
index--;
if(index<0){
//数组中的最小下标为0,不可能有比0还小的下标,所以当index到达0这个下标位置的时候就已经到头,
//如果还要继续向前遍历则 index<0 此时我们使index = images.length-1(数组的最后一个下标) 实现重复展示图片效果
index = images.length-1;
}
$("#showImg").attr("src",images[index].imageUrl);
$("#imageInfo").text(images[index].imageDesc);
}
//建立 下一张 函数
function nextImg(){
index++;
if(index>=images.length){
//因为数组的最大下标为length-1,所以length实际上是已经超出了数组长度,index中文含义为下标,
//所以当下标等于length-1的时候已经到了数组的最后一个元素位置,当index = lengeh的时候使index=0,这样可以循环点击
index = 0;
}
$("#showImg").attr("src",images[index].imageUrl);
$("#imageInfo").text(images[index].imageDesc);
}
function getCountByStatus(){
... ...