Browse Source

商品功能更新

master
xyiege 4 years ago
parent
commit
70b5e34556
  1. 5
      src/main/java/cn/chjyj/szwh/controller/admin/AdminGoodsController.java
  2. 6
      src/main/java/cn/chjyj/szwh/mapper/GoodsDetailMapper.java
  3. 8
      src/main/java/cn/chjyj/szwh/service/GoodsDetailService.java
  4. 1
      src/main/java/cn/chjyj/szwh/service/GoodsService.java
  5. 32
      src/main/java/cn/chjyj/szwh/service/impl/GoodsDetailServiceImpl.java
  6. 43
      src/main/resources/mapper/szwh/GoodsDetailMapper.xml
  7. 14
      src/test/java/cn/chjyj/szwh/mapper/GoodsDetailMapperTest.java

5
src/main/java/cn/chjyj/szwh/controller/admin/AdminGoodsController.java

@ -12,7 +12,9 @@ import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@ -46,11 +48,14 @@ public class AdminGoodsController extends BaseController {
*/
@RequestMapping("/goodsDetail")
public JSONObject goodsDetail(String islicode){
// 需要返回的结果
Map result=new HashMap<>();
// 商品明细id
Goods goods = goodsService.getGoodsByIsli(islicode);
if(goods!=null){
// 查找用户信息
User user = userService.getApiUser(goods.getUserIslicode());
result.put("userinfo",user);
GoodsDetail goodsDetail = goodsDetailService.getGoodsDetailBygid(goods.getGoodsDetailsId());
}else{

6
src/main/java/cn/chjyj/szwh/mapper/GoodsDetailMapper.java

@ -14,4 +14,10 @@ public interface GoodsDetailMapper {
* @return
*/
GoodsDetail getGoodsDetailBygid(Integer goodDetailId);
/**
* 更新商品详情
* @param goodsDetail
* @return
*/
int updateGoodsDetail(GoodsDetail goodsDetail);
}

8
src/main/java/cn/chjyj/szwh/service/GoodsDetailService.java

@ -12,4 +12,12 @@ public interface GoodsDetailService {
* @return
*/
GoodsDetail getGoodsDetailBygid(Integer goodDetailId);
/**
* 远程获取商品产品图片并更新本地
* @param image 图片路径
* @param id 本地产品自编号
* @return
*/
int getRemoteGoodsImageAndUpdate(String image,Integer id);
}

1
src/main/java/cn/chjyj/szwh/service/GoodsService.java

@ -21,4 +21,5 @@ public interface GoodsService {
* @return
*/
Goods getGoodsByIsli(String goodsIsli);
}

32
src/main/java/cn/chjyj/szwh/service/impl/GoodsDetailServiceImpl.java

@ -1,13 +1,22 @@
package cn.chjyj.szwh.service.impl;
import cn.chjyj.szwh.bean.GoodsDetail;
import cn.chjyj.szwh.exception.ChException;
import cn.chjyj.szwh.mapper.GoodsDetailMapper;
import cn.chjyj.szwh.service.GoodsDetailService;
import cn.chjyj.szwh.utils.ProperUtils;
import cn.chjyj.szwh.utils.RequestUtils;
import cn.chjyj.szwh.utils.SignUtils;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class GoodsDetailServiceImpl implements GoodsDetailService {
// 日志
private static Log log = LogFactory.getLog(GoodsDetailServiceImpl.class);
@Autowired
private GoodsDetailMapper goodsDetailMapper;
@ -15,4 +24,27 @@ public class GoodsDetailServiceImpl implements GoodsDetailService {
public GoodsDetail getGoodsDetailBygid(Integer goodDetailId) {
return goodsDetailMapper.getGoodsDetailBygid(goodDetailId);
}
@Override
public int getRemoteGoodsImageAndUpdate(String image, Integer id) {
String remote_goodsurl= ProperUtils.getSzwhProp("REAL_URL")+ "/dist/api/v2/preview?url="+image;
// 签名
String sign= SignUtils.createSign("distribute");
JSONObject jsonObject = RequestUtils.doGetUrlData(remote_goodsurl,"dist_token",sign);
log.debug("remote result:"+jsonObject);
String retcode = jsonObject.getString("resultCode");
if(!"00000000".equalsIgnoreCase(retcode)){
log.warn("remote result code :"+retcode);
throw new ChException("数据获取失败");
}
//返回的图片数据
String imgdata= jsonObject.getString("data");
GoodsDetail goodsDetail = new GoodsDetail();
goodsDetail.setId(id);
goodsDetail.setGoodsImage(imgdata);
// 执行更新操作
goodsDetailMapper.updateGoodsDetail(goodsDetail);
return 0;
}
}

43
src/main/resources/mapper/szwh/GoodsDetailMapper.xml

@ -77,42 +77,15 @@
)
</insert>
<update id="upUser" parameterType="cn.chjyj.szwh.bean.Goods">
<!-- 更新详情信息-->
<update id="updateGoodsDetail" parameterType="cn.chjyj.szwh.bean.GoodsDetail">
update <include refid="tbName"/>
set
<if test="password!=null">
password=#{password},
</if>
<if test="urealname!=null">
urealname=#{urealname},
</if>
<if test="ubirth!=null">
ubirth =#{ubirth},
</if>
<if test="gender!=null">
gender=#{gender},
</if>
<if test="nickName!=null">
nickname=#{nickName},
</if>
<if test="avatarurl!=null">
avatarurl=#{avatarurl},
</if>
<if test="nickname!=null">
nickname=#{nickname},
</if>
<if test="platfrom!=null">
platfrom=#{platfrom},
</if>
<if test="sessionkey!=null">
sessionkey=#{sessionkey},
</if>
<if test="openid!=null">
openid=#{openid},
</if>
uname=#{uname}
where uid=#{uid};
<set>
<if test="goodsImage!=null">
goods_image=#{goodsImage},
</if>
</set>
where id=#{id};
</update>
</mapper>

14
src/test/java/cn/chjyj/szwh/mapper/GoodsDetailMapperTest.java

@ -3,9 +3,12 @@ package cn.chjyj.szwh.mapper;
import cn.chjyj.szwh.bean.GoodsDetail;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import static org.junit.Assert.*;
@ -21,4 +24,15 @@ public class GoodsDetailMapperTest {
GoodsDetail goodsDetail = goodsDetailMapper.getGoodsDetailBygid(gdid);
System.out.println(goodsDetail.getGoodsName());
}
@Transactional
@Rollback
@Test
public void updateGoodsImage(){
GoodsDetail goodsDetail = new GoodsDetail();
goodsDetail.setId(1);
goodsDetail.setGoodsImage("sss");
//
goodsDetailMapper.updateGoodsDetail(goodsDetail);
}
}
Loading…
Cancel
Save