Authored by kun

add new files

package com.yohobuy.ufo.controller.brand;
import com.yohobuy.ufo.model.common.ApiResponse;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* @author kun.wang
* @date 2018/9/11
*/
@Controller
@RestController(value = "/brand")
public class BrandController {
private static final Logger LOGGER = LoggerFactory.getLogger(BrandController.class);
@Resource
private IBrandService brandService;
@RequestMapping(value = "/saveOrUpdateBrand", method = RequestMethod.POST)
public ApiResponse<Object> saveOrUpdateBrand(@RequestBody BrandRequestBo brandRequestBo) {
LOGGER.info("saveOrUpdateBrand param = {}", brandRequestBo);
brandService.insertOrUpdateBrand(brandRequestBo);
return new ApiResponse<>();
}
@RequestMapping(value = "/getBrandById", method = RequestMethod.GET)
public ApiResponse<BrandResponseBo> getBrandById(Integer id) {
LOGGER.info("getBrandById param = {}", id);
return new ApiResponse<>(brandService.getBrandById(id));
}
@RequestMapping(value = "/getBrandPageList", method = RequestMethod.GET)
public ApiResponse<PageResponseBO<BrandResponseBo>> getBrandPageList(@RequestBody BrandRequestBo brandRequestBo) {
LOGGER.info("getBrandPageList param = {}", brandRequestBo);
return new ApiResponse<>(brandService.getBrandPageList(brandRequestBo));
}
@RequestMapping(value = "/updateBrandStatus", method = RequestMethod.POST)
public ApiResponse<Object> updateBrandStatus(@RequestBody BrandRequestBo brandRequestBo) {
return new ApiResponse<>();
}
}
... ...
package com.yohobuy.ufo.service;
import com.yohobuy.ufo.model.common.PageResponseBO;
import com.yohobuy.ufo.model.request.brand.BrandRequestBo;
import com.yohobuy.ufo.model.request.brand.BrandResponseBo;
/**
* @author kun.wang
* @date 2018/9/11
*/
public interface IBrandService {
/**
* 保存或更新一条品牌记录
* @param brandRequestBo
* @return
*/
int insertOrUpdateBrand(BrandRequestBo brandRequestBo);
/**
* 获取品牌分页列表
* @param brandRequestBo
* @return
*/
PageResponseBO<BrandResponseBo> getBrandPageList(BrandRequestBo brandRequestBo);
/**
* 根据主键获取一条品牌记录
* @param id
* @return
*/
BrandResponseBo getBrandById(Integer id);
/**
* 更新品牌状态
* @param requestBo
* @return
*/
int updateBrandStatus(BrandRequestBo requestBo);
}
... ...
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);
}
}
... ...