Browse Source

商品资源入库服务层实现

master
xyiege 3 years ago
parent
commit
2799d9ae5a
  1. 8
      src/main/java/cn/chjyj/szwh/service/GoodsSourceService.java
  2. 65
      src/main/java/cn/chjyj/szwh/service/impl/GoodsSourceServiceImpl.java

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

@ -16,4 +16,12 @@ public interface GoodsSourceService {
* @return
*/
Map<String,Object> getGoodsSourceDetail(String isli, String islicode, String batchcode);
/**
* 增加商品资源 GoodsSource
* @param res
* @param idlicode
* @return
*/
int insertGoodsSource(String res,String idlicode);
}

65
src/main/java/cn/chjyj/szwh/service/impl/GoodsSourceServiceImpl.java

@ -18,6 +18,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.*;
@Service
@ -154,4 +155,68 @@ public class GoodsSourceServiceImpl implements GoodsSourceService {
retmap.put("gather_arr",gatherList);
return retmap;
}
/**
* add new GoodsSource
* @param res 传递过来的json字符串
* @param islicode 商品编码
* @return
*/
@Override
public int insertGoodsSource(String res, String islicode) {
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 抽取出现对应数据
JSONArray jarr = JSONObject.parseArray(res);
for(int i=0;i<jarr.size();i++){
JSONObject innerJson = (JSONObject) jarr.get(i);
// 转为对象
GoodsSource goodsSource = new GoodsSource();
goodsSource.setServicecode(innerJson.getString("'serviceCode'"));
goodsSource.setLinkcode(innerJson.getString("linkCode"));
// 发布 id
String pubid = innerJson.getString("publisherId");
goodsSource.setPublisherid(Integer.valueOf(pubid));
goodsSource.setRegistrant(innerJson.getString("register"));
goodsSource.setResolutionUrl(innerJson.getString("resolutionUrl"));
goodsSource.setSourceType(innerJson.getString("sourceType"));
goodsSource.setSourceNameType(innerJson.getString("sourceNameType"));
goodsSource.setSourceName(innerJson.getString("sourceName"));
//
goodsSource.setSourceidentify(innerJson.getString("sourceIdentify"));
goodsSource.setSourceFragment(innerJson.getString("sourceFragment"));
goodsSource.setTargetName(innerJson.getString("targetName"));
goodsSource.setTargetNameType(innerJson.getString("targetNameType"));
goodsSource.setTargetidentify(innerJson.getString("targetIdentify"));
//
goodsSource.setTargetFragment(innerJson.getString("targetFragment"));
goodsSource.setTargetformat(innerJson.getString("targetFormat"));
// 存放了json字符串
goodsSource.setSourceData(innerJson.getString("sourceData"));
goodsSource.setTargetData(innerJson.getString("targetData"));
//
goodsSource.setMetadataxml(innerJson.getString("metadataXml"));
goodsSource.setCancellationReason(innerJson.getString("cancellationReason"));
// 字符串转为日期时间格式
String aldate =innerJson.getString("allocationDate");
try {
Date ndate = sdf.parse(aldate);
goodsSource.setAllocationtime(ndate);
}catch (Exception ex){
// do nothing
}
goodsSource.setSourceType(innerJson.getString("dataType"));
try{
String cldate = innerJson.getString("cancellationDate");
Date cndate =sdf.parse(cldate);
goodsSource.setCancellationtime(cndate);
}catch (Exception ex){
//do nothing
}
// 产品主键
goodsSource.setGoodsIsliCode(islicode);
// 执行插入
goodsSourceMapper.add(goodsSource);
}
return 0;
}
}

Loading…
Cancel
Save