|
|
package com.yohobuy.ufo.service.impl;
|
|
|
|
|
|
import com.yoho.core.common.utils.DateUtil;
|
|
|
import com.yohobuy.ufo.dal.brand.BrandMapper;
|
|
|
import com.yohobuy.ufo.model.brand.Brand;
|
|
|
import com.yohobuy.ufo.model.common.PageModel;
|
|
|
import com.yohobuy.ufo.model.common.PageResponseBO;
|
|
|
import com.yohobuy.ufo.model.request.brand.BrandRequestBo;
|
|
|
import com.yohobuy.ufo.model.request.brand.BrandResponseBo;
|
|
|
import com.yohobuy.ufo.service.IBrandService;
|
|
|
import com.yohobuy.ufo.util.OrikaUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* @author kun.wang
|
|
|
* @date 2018/9/11
|
|
|
*/
|
|
|
@Service
|
|
|
public class BrandServiceImpl implements IBrandService {
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(BrandServiceImpl.class);
|
|
|
|
|
|
@Resource
|
|
|
private BrandMapper brandMapper;
|
|
|
|
|
|
@Override
|
|
|
public int insertOrUpdateBrand(BrandRequestBo brandRequestBo) {
|
|
|
LOGGER.info("insertOrUpdateBrand param = {}", brandRequestBo);
|
|
|
Brand brand = OrikaUtils.map(brandRequestBo, Brand.class);
|
|
|
brand.setEditTime(DateUtil.currentTimeSeconds());
|
|
|
brand.setEditPid(0);
|
|
|
if (brand.getId() == null) {
|
|
|
// 新增一条品牌记录
|
|
|
brand.setCreateTime(DateUtil.currentTimeSeconds());
|
|
|
return brandMapper.insertBrand(brand);
|
|
|
} else {
|
|
|
// 更新一条品牌记录
|
|
|
return brandMapper.updateBrand(brand);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public PageResponseBO<BrandResponseBo> getBrandPageList(BrandRequestBo brandRequestBo) {
|
|
|
LOGGER.info("getBrandPageList param = {}", brandRequestBo);
|
|
|
Brand brand = OrikaUtils.map(brandRequestBo, Brand.class);
|
|
|
PageModel pageModel = brandRequestBo.toPageModel();
|
|
|
int count = brandMapper.selectBrandCount(brand);
|
|
|
if (count == 0) {
|
|
|
LOGGER.warn("getBrandPageList count is 0, param = {}", brandRequestBo);
|
|
|
return new PageResponseBO<>();
|
|
|
}
|
|
|
List<BrandResponseBo> brandResponseBos = new ArrayList<>();
|
|
|
List<Brand> brands = brandMapper.getBrandPageList(brand, pageModel);
|
|
|
BrandResponseBo responseBo;
|
|
|
for (Brand brand1 : brands) {
|
|
|
responseBo = OrikaUtils.map(brand1, BrandResponseBo.class);
|
|
|
responseBo.setCreateTime(DateUtil.getDateStrBySecond(brand1.getCreateTime(), DateUtil.DATE_TIME_FORMAT));
|
|
|
brandResponseBos.add(responseBo);
|
|
|
}
|
|
|
return new PageResponseBO<>(count, brandResponseBos, pageModel.getCurrentPage(), pageModel.getPageSize());
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public BrandResponseBo getBrandById(Integer id) {
|
|
|
LOGGER.info("getBrandById id = {}", id);
|
|
|
Brand brand = brandMapper.selectOneById(id);
|
|
|
BrandResponseBo brandResponseBo = OrikaUtils.map(brand, BrandResponseBo.class);
|
|
|
brandResponseBo.setCreateTime(DateUtil.getDateStrBySecond(brand.getCreateTime(), DateUtil.DATE_TIME_FORMAT));
|
|
|
return brandResponseBo;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int updateBrandStatus(BrandRequestBo requestBo) {
|
|
|
LOGGER.info("updateBrandStatus param = {}", requestBo);
|
|
|
Brand brand = OrikaUtils.map(requestBo, Brand.class);
|
|
|
brand.setEditTime(DateUtil.currentTimeSeconds());
|
|
|
return brandMapper.updateBrandStatus(brand);
|
|
|
}
|
|
|
} |
...
|
...
|
|