Search in sources :

Example 1 with StorePhoto

use of com.ikoori.vip.common.persistence.model.StorePhoto in project vip by guangdada.

the class StoreServiceImpl method saveStore.

@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void saveStore(Store store, String pics) {
    if (store.getId() != null) {
        Wrapper<StorePhoto> wrapper = new EntityWrapper<StorePhoto>();
        wrapper.eq("store_id", store.getId());
        storePhotoMapper.delete(wrapper);
        storeMapper.updateById(store);
    } else {
        store.setStoreNo(RandomUtil.generateStoreNum());
        storeMapper.insert(store);
    }
    if (StringUtils.isNotBlank(pics)) {
        JSONArray picA = JSONArray.parseArray(pics);
        if (picA != null) {
            for (int i = 0; i < picA.size(); i++) {
                JSONObject pic = picA.getJSONObject(i);
                Long id = pic.getLong("id");
                StorePhoto storePhoto = new StorePhoto();
                storePhoto.setStoreId(store.getId());
                storePhoto.setPicId(id);
                storePhotoMapper.insert(storePhoto);
            }
        }
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) EntityWrapper(com.baomidou.mybatisplus.mapper.EntityWrapper) JSONArray(com.alibaba.fastjson.JSONArray) StorePhoto(com.ikoori.vip.common.persistence.model.StorePhoto) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 EntityWrapper (com.baomidou.mybatisplus.mapper.EntityWrapper)1 StorePhoto (com.ikoori.vip.common.persistence.model.StorePhoto)1 Transactional (org.springframework.transaction.annotation.Transactional)1