修复主键重名问题
This commit is contained in:
@@ -13,6 +13,8 @@ import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 品牌功能Controller
|
||||
*/
|
||||
@@ -54,7 +56,7 @@ public class PmsBrandController {
|
||||
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object updateBrand(@PathVariable("id") Long id, @Validated @RequestBody PmsBrandParam pmsBrandParam, BindingResult result) {
|
||||
if(result.hasErrors()){
|
||||
if (result.hasErrors()) {
|
||||
return new CommonResult().validateFailed(result.getFieldError().getDefaultMessage());
|
||||
}
|
||||
CommonResult commonResult;
|
||||
@@ -75,20 +77,21 @@ public class PmsBrandController {
|
||||
public Object deleteBrand(@PathVariable("id") Long id) {
|
||||
int count = brandService.deleteBrand(id);
|
||||
if (count == 1) {
|
||||
LOGGER.debug("deleteBrand success :id={}", id);
|
||||
LOGGER.debug("deleteBrand success:id={}", id);
|
||||
return new CommonResult().success(null);
|
||||
} else {
|
||||
LOGGER.debug("deleteBrand failed :id={}", id);
|
||||
LOGGER.debug("deleteBrand failed:id={}", id);
|
||||
return new CommonResult().failed();
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "分页获取品牌列表")
|
||||
@ApiOperation(value = "根据品牌名称分页获取品牌列表")
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Object listBrand(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
|
||||
public Object listBrand(@RequestParam(value = "keyword", required = false) String keyword,
|
||||
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(value = "pageSize", defaultValue = "3") Integer pageSize) {
|
||||
return new CommonResult().pageSuccess(brandService.listBrand(pageNum, pageSize));
|
||||
return new CommonResult().pageSuccess(brandService.listBrand(keyword, pageNum, pageSize));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据编号查询品牌信息")
|
||||
@@ -97,4 +100,32 @@ public class PmsBrandController {
|
||||
public Object getBrand(@PathVariable("id") Long id) {
|
||||
return new CommonResult().success(brandService.getBrand(id));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "批量删除品牌")
|
||||
@RequestMapping(value = "/delete/batch", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object deleteBrandBatch(@RequestParam("ids") List<Long> ids) {
|
||||
int count = brandService.deleteBrand(ids);
|
||||
if (count > 0) {
|
||||
LOGGER.debug("deleteBrandBatch success:ids={}", ids);
|
||||
return new CommonResult().success(count);
|
||||
} else {
|
||||
LOGGER.debug("deleteBrandBatch failed:ids={}", ids);
|
||||
return new CommonResult().failed();
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "批量更新显示状态")
|
||||
@RequestMapping(value = "/update/showStatus", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object updateShowStatus(@RequestParam("ids") List<Long> ids, @RequestParam("showStatus") Integer showStatus) {
|
||||
int count = brandService.updateShowStatus(ids, showStatus);
|
||||
if (count > 0) {
|
||||
LOGGER.debug("updateShowStatus success:ids={}", ids);
|
||||
return new CommonResult().success(count);
|
||||
} else {
|
||||
LOGGER.debug("updateShowStatus failed:ids={}", ids);
|
||||
return new CommonResult().failed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,11 @@ public interface PmsBrandService {
|
||||
|
||||
int deleteBrand(Long id);
|
||||
|
||||
List<PmsBrand> listBrand(int pageNum, int pageSize);
|
||||
int deleteBrand(List<Long> ids);
|
||||
|
||||
List<PmsBrand> listBrand(String keyword,int pageNum, int pageSize);
|
||||
|
||||
PmsBrand getBrand(Long id);
|
||||
|
||||
int updateShowStatus(List<Long> ids, Integer showStatus);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.macro.mall.service.PmsBrandService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -29,6 +30,10 @@ public class PmsBrandServiceImpl implements PmsBrandService{
|
||||
public int createBrand(PmsBrandParam pmsBrandParam) {
|
||||
PmsBrand pmsBrand = new PmsBrand();
|
||||
BeanUtils.copyProperties(pmsBrandParam,pmsBrand);
|
||||
//如果创建时首字母为空,取名称的第一个为首字母
|
||||
if(StringUtils.isEmpty(pmsBrand.getFirstLetter())){
|
||||
pmsBrand.setFirstLetter(pmsBrand.getName().substring(0,1));
|
||||
}
|
||||
return brandMapper.insertSelective(pmsBrand);
|
||||
}
|
||||
|
||||
@@ -37,6 +42,10 @@ public class PmsBrandServiceImpl implements PmsBrandService{
|
||||
PmsBrand pmsBrand = new PmsBrand();
|
||||
BeanUtils.copyProperties(pmsBrandParam,pmsBrand);
|
||||
pmsBrand.setId(id);
|
||||
//如果创建时首字母为空,取名称的第一个为首字母
|
||||
if(StringUtils.isEmpty(pmsBrand.getFirstLetter())){
|
||||
pmsBrand.setFirstLetter(pmsBrand.getName().substring(0,1));
|
||||
}
|
||||
return brandMapper.updateByPrimaryKeySelective(pmsBrand);
|
||||
}
|
||||
|
||||
@@ -46,13 +55,33 @@ public class PmsBrandServiceImpl implements PmsBrandService{
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PmsBrand> listBrand(int pageNum, int pageSize) {
|
||||
public int deleteBrand(List<Long> ids) {
|
||||
PmsBrandExample pmsBrandExample = new PmsBrandExample();
|
||||
pmsBrandExample.createCriteria().andIdIn(ids);
|
||||
return brandMapper.deleteByExample(pmsBrandExample);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PmsBrand> listBrand(String keyword,int pageNum, int pageSize) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
return brandMapper.selectByExample(new PmsBrandExample());
|
||||
PmsBrandExample pmsBrandExample = new PmsBrandExample();
|
||||
if(!StringUtils.isEmpty(keyword)){
|
||||
pmsBrandExample.createCriteria().andNameLike("%"+keyword+"%");
|
||||
}
|
||||
return brandMapper.selectByExample(pmsBrandExample);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PmsBrand getBrand(Long id) {
|
||||
return brandMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateShowStatus(List<Long> ids, Integer showStatus) {
|
||||
PmsBrand pmsBrand = new PmsBrand();
|
||||
pmsBrand.setShowStatus(showStatus);
|
||||
PmsBrandExample pmsBrandExample = new PmsBrandExample();
|
||||
pmsBrandExample.createCriteria().andIdIn(ids);
|
||||
return brandMapper.updateByExampleSelective(pmsBrand,pmsBrandExample);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user