1111import com .lzq .web .utils .ExampleUtils ;
1212import com .lzq .web .utils .QiniuyunUtils ;
1313import com .lzq .web .utils .ResultMapUtils ;
14- import com .qiniu .util .StringUtils ;
1514import io .swagger .annotations .Api ;
1615import io .swagger .annotations .ApiOperation ;
1716import lombok .extern .slf4j .Slf4j ;
1817import org .apache .commons .io .FileUtils ;
18+ import org .apache .commons .lang .StringUtils ;
1919import org .apache .dubbo .config .annotation .Reference ;
2020import org .springframework .amqp .AmqpException ;
2121import org .springframework .amqp .core .Message ;
@@ -88,7 +88,7 @@ public Map<String, Object> CreateFile(Example example, Content exampleContent, S
8888 example .setImg (query .getImg ());
8989 //用户保存实例
9090 bol = ExampleUtils .SaveExampleContent (example , exampleContent , content , exampleService , contentService );
91- return ResultMapUtils .ResultMap (bol ,0 ,"保存实例内容 " );
91+ return ResultMapUtils .ResultMap (bol ,0 ,"保存实例内容成功 " );
9292 } catch (IOException e ) {
9393 e .printStackTrace ();
9494 return ResultMapUtils .ResultMap (false ,0 ,"修改文件失败" );
@@ -138,7 +138,8 @@ public Map<String, Object> CreateFile(Example example, Content exampleContent, S
138138 @ ApiOperation ("添加喜爱" )
139139 public Map <String ,Object > addFavorites (Favorites favorites ){
140140 //判断是否用户已登录,登录则进行数据插入,否则则不做任何操作
141- if (!StringUtils .isNullOrEmpty (favorites .getUsername ())){
141+ if (StringUtils .isNotBlank (favorites .getUsername ())
142+ && StringUtils .isNotBlank (favorites .getExampleId ())){
142143 Boolean bol = favoritesService .addFavorites (favorites );
143144 //添加到缓存
144145 if (bol ){
@@ -162,28 +163,35 @@ public Map<String,Object> addFavorites(Favorites favorites){
162163 @ DeleteMapping ("/" )
163164 @ ApiOperation ("放入回收站" )
164165 public Map <String ,Object > deleteExample (Example example ){
165- //逻辑删除实例放入回收站中
166- boolean b = exampleService .deleteById (example .getExampleId ());
167- if (b ){
168- SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss" );
169- log .info ("消息接收时间:" +sdf .format (new Date ()));
170- //发送消息到队列中
171- rabbitTemplate .convertAndSend ("delete_exchange" , "delete" , example , new MessagePostProcessor () {
172- @ Override
173- public Message postProcessMessage (Message message ) throws AmqpException {
174- //设置延迟时间 1天
175- message .getMessageProperties ().setHeader ("x-delay" ,1000 *60 *60 *24 *1 );
176- return message ;
177- }
178- });
179- //减少用户作品数
180- accountService .reduceWorks (example .getUsername ());
181- //回收站数量增加
182- accountService .increaseRecycle (example .getUsername ());
183- return ResultMapUtils .ResultMap (b ,0 ,null );
166+ //查询是否存在该实例
167+ Example query = exampleService .queryByIdUsername (example );
168+ if (query !=null ){
169+ //逻辑删除实例放入回收站中
170+ boolean b = exampleService .deleteById (example .getExampleId ());
171+ if (b ){
172+ SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss" );
173+ log .info ("消息接收时间:" +sdf .format (new Date ()));
174+ //发送消息到队列中
175+ rabbitTemplate .convertAndSend ("delete_exchange" , "delete" , example , new MessagePostProcessor () {
176+ @ Override
177+ public Message postProcessMessage (Message message ) throws AmqpException {
178+ //设置延迟时间 1天
179+ message .getMessageProperties ().setHeader ("x-delay" ,1000 *60 *60 *24 *1 );
180+ return message ;
181+ }
182+ });
183+ //减少用户作品数
184+ accountService .reduceWorks (example .getUsername ());
185+ //回收站数量增加
186+ accountService .increaseRecycle (example .getUsername ());
187+ return ResultMapUtils .ResultMap (b ,0 ,null );
188+ }else {
189+ return ResultMapUtils .ResultMap (b ,0 ,null );
190+ }
184191 }else {
185- return ResultMapUtils .ResultMap (b , 0 , null );
192+ return ResultMapUtils .ResultMap (false , 1 , "请传入正确的值" );
186193 }
194+
187195 }
188196
189197 /**
0 commit comments