...
|
...
|
@@ -3,12 +3,14 @@ package com.yohobuy.platform.grass.service.impl; |
|
|
|
|
|
import com.yohobuy.platform.common.util.BeanTool;
|
|
|
import com.yohobuy.platform.common.util.DateUtil;
|
|
|
import com.yohobuy.platform.dal.grass.IGrassArticleLabelDao;
|
|
|
import com.yohobuy.platform.dal.grass.IGrassLabelDAO;
|
|
|
import com.yohobuy.platform.dal.grass.IGrassLabelGroupDAO;
|
|
|
import com.yohobuy.platform.dal.grass.model.GrassLabel;
|
|
|
import com.yohobuy.platform.dal.grass.model.LabelGroup;
|
|
|
import com.yohobuy.platform.grass.service.IlabelGroupService;
|
|
|
import com.yohobuy.platform.grass.service.IlabelService;
|
|
|
import com.yohobuy.platform.model.common.ApiResponse;
|
|
|
import com.yohobuy.platform.model.common.PageResponseVO;
|
|
|
import com.yohobuy.platform.model.grass.request.GrassLabelReq;
|
|
|
import com.yohobuy.platform.model.grass.request.LabelGroupReq;
|
...
|
...
|
@@ -36,6 +38,9 @@ public class LabelServiceImpl implements IlabelService { |
|
|
@Autowired
|
|
|
private IGrassLabelGroupDAO labelGroupDAO;
|
|
|
|
|
|
@Autowired
|
|
|
private IGrassArticleLabelDao grassArticleLabelDao;
|
|
|
|
|
|
@Override
|
|
|
public PageResponseVO<GrassLabelBo> getGrassLabelList(GrassLabelReq req) {
|
|
|
logger.info("enter getGrassLabelList req={} ", req);
|
...
|
...
|
@@ -58,37 +63,53 @@ public class LabelServiceImpl implements IlabelService { |
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void addUpLabel(GrassLabelReq req) {
|
|
|
logger.info("enter addUpLabel req={}", req);
|
|
|
Integer id = req.getId();
|
|
|
GrassLabel record = new GrassLabel();
|
|
|
record.setId(id);
|
|
|
record.setLabelName(req.getLabelName());
|
|
|
record.setGroupId(req.getGroupId());
|
|
|
record.setStatus(req.getStatus());
|
|
|
if(id != null){//修改
|
|
|
record.setUpdateTime(DateUtil.getCurrentTimeSeconds());
|
|
|
GrassLabel oldGrassLabel = grassLabelDAO.selectByPrimaryKey(id);
|
|
|
if(oldGrassLabel.getGroupId().intValue() != req.getGroupId().intValue() ){//分组改变了,对应的分组的统计需要改下
|
|
|
labelGroupDAO.updateLabelNum(oldGrassLabel.getGroupId(), false);//减1
|
|
|
labelGroupDAO.updateLabelNum(req.getGroupId(), true);//加1
|
|
|
public ApiResponse addUpLabel(GrassLabelReq req) {
|
|
|
try{
|
|
|
logger.info("enter addUpLabel req={}", req);
|
|
|
Integer id = req.getId();
|
|
|
GrassLabel record = new GrassLabel();
|
|
|
record.setId(id);
|
|
|
record.setLabelName(req.getLabelName());
|
|
|
record.setGroupId(req.getGroupId());
|
|
|
record.setStatus(req.getStatus());
|
|
|
if(id != null){//修改
|
|
|
record.setUpdateTime(DateUtil.getCurrentTimeSeconds());
|
|
|
GrassLabel oldGrassLabel = grassLabelDAO.selectByPrimaryKey(id);
|
|
|
if(oldGrassLabel.getGroupId().intValue() != req.getGroupId().intValue() ){//分组改变了,对应的分组的统计需要改下
|
|
|
labelGroupDAO.updateLabelNum(oldGrassLabel.getGroupId(), false);//减1
|
|
|
labelGroupDAO.updateLabelNum(req.getGroupId(), true);//加1
|
|
|
}
|
|
|
grassLabelDAO.updateByPrimaryKeySelective(record);
|
|
|
logger.info("addUpLabel update success! req={},oldGrassLabel={}",req,oldGrassLabel);
|
|
|
}else{//新增
|
|
|
record.setCreateTime(DateUtil.getCurrentTimeSeconds());
|
|
|
grassLabelDAO.insert(record);
|
|
|
//组对应的数量加1
|
|
|
labelGroupDAO.updateLabelNum(req.getGroupId(), true);
|
|
|
logger.info("addUpLabel insert success! req={}",req);
|
|
|
}
|
|
|
grassLabelDAO.updateByPrimaryKeySelective(record);
|
|
|
logger.info("addUpLabel update success! req={},oldGrassLabel={}",req,oldGrassLabel);
|
|
|
}else{//新增
|
|
|
record.setCreateTime(DateUtil.getCurrentTimeSeconds());
|
|
|
grassLabelDAO.insert(record);
|
|
|
//组对应的数量加1
|
|
|
labelGroupDAO.updateLabelNum(req.getGroupId(), true);
|
|
|
logger.info("addUpLabel insert success! req={}",req);
|
|
|
|
|
|
return new ApiResponse.ApiResponseBuilder().build();
|
|
|
}catch (Exception e){
|
|
|
logger.warn("addUpLabel req={} error, e{}",req, e);
|
|
|
return new ApiResponse.ApiResponseBuilder().code(201).build();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void deleteLabel(GrassLabelReq req) {
|
|
|
public ApiResponse deleteLabel(GrassLabelReq req) {
|
|
|
logger.info("enter deleteLabel req={} ",req);
|
|
|
grassLabelDAO.deleteByPrimaryKey(req.getId());
|
|
|
Integer labelId = req.getId();
|
|
|
//文章 关联了 标签 则不允许删除
|
|
|
int count = grassArticleLabelDao.countByLabelId(labelId);
|
|
|
if(count > 0 ){
|
|
|
logger.info("deleteLabel req={} error! bind with articles ",req);
|
|
|
return new ApiResponse.ApiResponseBuilder().code(201).message("标签与文章绑定,不能删除").build();
|
|
|
}
|
|
|
grassLabelDAO.deleteByPrimaryKey(labelId);
|
|
|
labelGroupDAO.updateLabelNum(req.getGroupId(),false);
|
|
|
return new ApiResponse.ApiResponseBuilder().message("success").build();
|
|
|
}
|
|
|
|
|
|
@Override
|
...
|
...
|
|