作品集功能完善

This commit is contained in:
x ronger 2020-04-21 23:34:38 +08:00
parent 9c38e94b04
commit d747b6f9bc
5 changed files with 82 additions and 3 deletions

View File

@ -65,4 +65,12 @@ public interface PortfolioMapper extends Mapper<Portfolio> {
* @return * @return
*/ */
Integer updateArticleSortNo(@Param("idPortfolio") Integer idPortfolio, @Param("idArticle") Integer idArticle, @Param("sortNo") Integer sortNo); Integer updateArticleSortNo(@Param("idPortfolio") Integer idPortfolio, @Param("idArticle") Integer idArticle, @Param("sortNo") Integer sortNo);
/**
* 取消绑定文章
* @param idPortfolio
* @param idArticle
* @return
*/
Integer unbindArticle(@Param("idPortfolio") Integer idPortfolio, @Param("idArticle") Integer idArticle);
} }

View File

@ -62,4 +62,19 @@ public interface PortfolioService extends Service<Portfolio> {
* @return * @return
*/ */
Map updateArticleSortNo(PortfolioArticleDTO portfolioArticle); Map updateArticleSortNo(PortfolioArticleDTO portfolioArticle);
/**
* 取消绑定文章
* @param idPortfolio
* @param idArticle
* @return
*/
Map unbindArticle(Integer idPortfolio, Integer idArticle);
/**
* 删除作品集
* @param idPortfolio
* @return
*/
Map deletePortfolio(Integer idPortfolio);
} }

View File

@ -50,6 +50,9 @@ public class PortfolioServiceImpl extends AbstractService<Portfolio> implements
@Override @Override
public PortfolioDTO findPortfolioDTOById(Integer idPortfolio, Integer type) { public PortfolioDTO findPortfolioDTOById(Integer idPortfolio, Integer type) {
PortfolioDTO portfolio = portfolioMapper.selectPortfolioDTOById(idPortfolio,type); PortfolioDTO portfolio = portfolioMapper.selectPortfolioDTOById(idPortfolio,type);
if (portfolio == null) {
return new PortfolioDTO();
}
Author author = userService.selectAuthor(portfolio.getPortfolioAuthorId()); Author author = userService.selectAuthor(portfolio.getPortfolioAuthorId());
genPortfolioAuthor(portfolio,author); genPortfolioAuthor(portfolio,author);
Integer articleNumber = portfolioMapper.selectCountArticleNumber(portfolio.getIdPortfolio()); Integer articleNumber = portfolioMapper.selectCountArticleNumber(portfolio.getIdPortfolio());
@ -96,7 +99,7 @@ public class PortfolioServiceImpl extends AbstractService<Portfolio> implements
public Map bindArticle(PortfolioArticleDTO portfolioArticle) { public Map bindArticle(PortfolioArticleDTO portfolioArticle) {
Map map = new HashMap(1); Map map = new HashMap(1);
Integer count = portfolioMapper.selectCountPortfolioArticle(portfolioArticle.getIdArticle(), portfolioArticle.getIdPortfolio()); Integer count = portfolioMapper.selectCountPortfolioArticle(portfolioArticle.getIdArticle(), portfolioArticle.getIdPortfolio());
if (count == 0) { if (count.equals(0)) {
Integer maxSortNo = portfolioMapper.selectMaxSortNo(portfolioArticle.getIdPortfolio()); Integer maxSortNo = portfolioMapper.selectMaxSortNo(portfolioArticle.getIdPortfolio());
portfolioMapper.insertPortfolioArticle(portfolioArticle.getIdArticle(),portfolioArticle.getIdPortfolio(),maxSortNo); portfolioMapper.insertPortfolioArticle(portfolioArticle.getIdArticle(),portfolioArticle.getIdPortfolio(),maxSortNo);
map.put("message", "绑定成功!"); map.put("message", "绑定成功!");
@ -109,10 +112,10 @@ public class PortfolioServiceImpl extends AbstractService<Portfolio> implements
@Override @Override
public Map updateArticleSortNo(PortfolioArticleDTO portfolioArticle) { public Map updateArticleSortNo(PortfolioArticleDTO portfolioArticle) {
Map map = new HashMap(1); Map map = new HashMap(1);
if (portfolioArticle.getIdPortfolio() == null || portfolioArticle.getIdPortfolio() == 0) { if (portfolioArticle.getIdPortfolio() == null || portfolioArticle.getIdPortfolio().equals(0)) {
map.put("message", "作品集数据异常!"); map.put("message", "作品集数据异常!");
} }
if (portfolioArticle.getIdArticle() == null || portfolioArticle.getIdArticle() == 0) { if (portfolioArticle.getIdArticle() == null || portfolioArticle.getIdArticle().equals(0)) {
map.put("message", "文章数据异常!"); map.put("message", "文章数据异常!");
} }
if (portfolioArticle.getSortNo() == null) { if (portfolioArticle.getSortNo() == null) {
@ -127,6 +130,44 @@ public class PortfolioServiceImpl extends AbstractService<Portfolio> implements
return map; return map;
} }
@Override
public Map unbindArticle(Integer idPortfolio, Integer idArticle) {
Map map = new HashMap(1);
if (idPortfolio == null || idPortfolio.equals(0)) {
map.put("message", "作品集数据异常");
}
if (idArticle == null || idArticle.equals(0)) {
map.put("message", "文章数据异常");
}
Integer result = portfolioMapper.unbindArticle(idPortfolio,idArticle);
if (result > 0) {
map.put("message", "操作成功!");
} else {
map.put("message", "操作失败!");
}
return map;
}
@Override
public Map deletePortfolio(Integer idPortfolio) {
Map map = new HashMap(1);
if (idPortfolio == null || idPortfolio.equals(0)) {
map.put("message", "作品集数据异常");
}
Integer articleNumber = portfolioMapper.selectCountArticleNumber(idPortfolio);
if (articleNumber > 0) {
map.put("message", "该作品集已绑定文章不允许删除!");
} else {
Integer result = portfolioMapper.deleteByPrimaryKey(idPortfolio);
if (result.equals(0)) {
map.put("message", "操作失败!");
}
}
return map;
}
private PortfolioDTO genPortfolioAuthor(PortfolioDTO portfolioDTO, Author author) { private PortfolioDTO genPortfolioAuthor(PortfolioDTO portfolioDTO, Author author) {
portfolioDTO.setPortfolioAuthorAvatarUrl(author.getUserAvatarURL()); portfolioDTO.setPortfolioAuthorAvatarUrl(author.getUserAvatarURL());
portfolioDTO.setPortfolioAuthorName(author.getUserNickname()); portfolioDTO.setPortfolioAuthorName(author.getUserNickname());

View File

@ -61,4 +61,16 @@ public class PortfolioController {
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(map);
} }
@DeleteMapping("/unbind-article")
public GlobalResult unbindArticle(Integer idArticle,Integer idPortfolio) {
Map map = portfolioService.unbindArticle(idPortfolio,idArticle);
return GlobalResultGenerator.genSuccessResult(map);
}
@DeleteMapping("/delete")
public GlobalResult delete(Integer idPortfolio){
Map map = portfolioService.deletePortfolio(idPortfolio);
return GlobalResultGenerator.genSuccessResult(map);
}
} }

View File

@ -24,6 +24,9 @@
<update id="updateArticleSortNo"> <update id="updateArticleSortNo">
update vertical_portfolio_article set sort_no = #{sortNo} where id_vertical_portfolio = #{idPortfolio} and id_vertical_article = #{idArticle} update vertical_portfolio_article set sort_no = #{sortNo} where id_vertical_portfolio = #{idPortfolio} and id_vertical_article = #{idArticle}
</update> </update>
<delete id="unbindArticle">
delete from vertical_portfolio_article where id_vertical_portfolio = #{idPortfolio} and id_vertical_article = #{idArticle}
</delete>
<select id="selectUserPortfoliosByIdUser" resultMap="DTOResultMap"> <select id="selectUserPortfoliosByIdUser" resultMap="DTOResultMap">
select id, portfolio_head_img_url, portfolio_title, portfolio_author_id, portfolio_description, updated_time from vertical_portfolio where portfolio_author_id = #{idUser} select id, portfolio_head_img_url, portfolio_title, portfolio_author_id, portfolio_description, updated_time from vertical_portfolio where portfolio_author_id = #{idUser}
</select> </select>