1.优化
Showing
6 changed files
with
54 additions
and
42 deletions
... | @@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository; | ... | @@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository; |
5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
6 | import org.springframework.data.jpa.repository.Modifying; | 6 | import org.springframework.data.jpa.repository.Modifying; |
7 | 7 | ||
8 | import java.util.List; | ||
8 | import java.util.Optional; | 9 | import java.util.Optional; |
9 | 10 | ||
10 | /** | 11 | /** |
... | @@ -16,5 +17,6 @@ public interface UserCollectionDetailRepository extends JpaRepository<UserCollec | ... | @@ -16,5 +17,6 @@ public interface UserCollectionDetailRepository extends JpaRepository<UserCollec |
16 | @Modifying | 17 | @Modifying |
17 | void deleteAllByUserCollectionId(Long userCollectionId); | 18 | void deleteAllByUserCollectionId(Long userCollectionId); |
18 | 19 | ||
19 | Optional<UserCollectionDetail> findByDetailIdAndDetailTypeAndUserCollectionId(Long detailId, String detailType, Long userCollectionId); | 20 | // Optional<UserCollectionDetail> findByDetailIdAndDetailTypeAndUserCollectionId(Long detailId, String detailType, Long userCollectionId); |
21 | List<UserCollectionDetail> findByDetailIdAndDetailTypeAndUserCollectionId(Long detailId, String detailType, Long userCollectionId); | ||
20 | } | 22 | } | ... | ... |
... | @@ -505,9 +505,11 @@ public class UserOperationController { | ... | @@ -505,9 +505,11 @@ public class UserOperationController { |
505 | @AnonymousAccess | 505 | @AnonymousAccess |
506 | public ResultInfo addCollection(@RequestBody String content) { | 506 | public ResultInfo addCollection(@RequestBody String content) { |
507 | log.info("UserOperationController ==> addCollection ==>> param ==> [{}]",content); | 507 | log.info("UserOperationController ==> addCollection ==>> param ==> [{}]",content); |
508 | 508 | if (StringUtils.isNotBlank(content)) { | |
509 | boolean result = this.userOperationService.addCollection(content); | 509 | boolean result = this.userOperationService.addCollection(content); |
510 | return ResultInfo.success(result); | 510 | return ResultInfo.success(result); |
511 | } | ||
512 | return ResultInfo.success(); | ||
511 | } | 513 | } |
512 | 514 | ||
513 | } | 515 | } | ... | ... |
... | @@ -771,6 +771,10 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -771,6 +771,10 @@ public class UserOperationServiceImpl implements UserOperationService { |
771 | this.userCollectionService.findFirstByUserIdAndTypeAndName(id, userCollectionMq.getType(), | 771 | this.userCollectionService.findFirstByUserIdAndTypeAndName(id, userCollectionMq.getType(), |
772 | userCollectionMq.getName()); | 772 | userCollectionMq.getName()); |
773 | 773 | ||
774 | if (Objects.isNull(userCollection.getId())) { | ||
775 | return true; | ||
776 | } | ||
777 | |||
774 | int count = 0; | 778 | int count = 0; |
775 | for (UserCollectionMq collectionMq : value) { | 779 | for (UserCollectionMq collectionMq : value) { |
776 | 780 | ||
... | @@ -850,23 +854,52 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -850,23 +854,52 @@ public class UserOperationServiceImpl implements UserOperationService { |
850 | for (UserCollectionMq collectionMq : value) { | 854 | for (UserCollectionMq collectionMq : value) { |
851 | 855 | ||
852 | UserCollectionDetail userCollectionDetail = collectionMq2DetailMapper.toEntity(collectionMq); | 856 | UserCollectionDetail userCollectionDetail = collectionMq2DetailMapper.toEntity(collectionMq); |
853 | Optional<UserCollectionDetail> userCollectionDetailOptional = userCollectionDetailRepository | 857 | |
858 | List<UserCollectionDetail> userCollectionDetailOptional = userCollectionDetailRepository | ||
854 | .findByDetailIdAndDetailTypeAndUserCollectionId(userCollectionDetail.getDetailId(), | 859 | .findByDetailIdAndDetailTypeAndUserCollectionId(userCollectionDetail.getDetailId(), |
855 | userCollectionDetail.getDetailType(), userCollection.getId()); | 860 | userCollectionDetail.getDetailType(), userCollection.getId()); |
856 | //观影记录同一天只存一条记录 | ||
857 | if (userCollectionDetailOptional.isPresent() && | ||
858 | DateUtil.isSameDay(new Date(userCollectionDetailOptional.get().getCreateTime().getTime()), new Date())) { | ||
859 | 861 | ||
860 | userCollectionDetail.setId(userCollectionDetailOptional.get().getId()); | 862 | if (CollectionUtils.isEmpty(userCollectionDetailOptional)) { |
861 | |||
862 | } else { | ||
863 | 863 | ||
864 | userCollectionDetail.setId(null) | 864 | userCollectionDetail.setId(null) |
865 | .setUserCollectionId(userCollection.getId()); | 865 | .setUserCollectionId(userCollection.getId()); |
866 | userCollectionDetailRepository.save(userCollectionDetail); | ||
867 | |||
868 | } else { | ||
869 | |||
870 | for (UserCollectionDetail collectionDetail : userCollectionDetailOptional) { | ||
871 | //观影记录同一天只存一条记录 | ||
872 | boolean sameDay = DateUtil.isSameDay(new Date(collectionDetail.getCreateTime().getTime()), new Date()); | ||
873 | if (sameDay) { | ||
874 | continue; | ||
875 | } else { | ||
876 | userCollectionDetail.setId(null) | ||
877 | .setUserCollectionId(userCollection.getId()); | ||
878 | userCollectionDetailRepository.save(userCollectionDetail); | ||
879 | continue; | ||
880 | } | ||
881 | |||
882 | } | ||
866 | 883 | ||
867 | } | 884 | } |
885 | /*if (userCollectionDetailOptional.isPresent()) { | ||
886 | //观影记录同一天只存一条记录 | ||
887 | boolean sameDay = DateUtil.isSameDay(new Date(userCollectionDetailOptional.get().getCreateTime().getTime()), new Date()); | ||
888 | if (sameDay) { | ||
889 | userCollectionDetail.setId(userCollectionDetailOptional.get().getId()); | ||
890 | userCollectionDetailRepository.save(userCollectionDetail); | ||
891 | } else { | ||
892 | |||
893 | continue; | ||
894 | } | ||
895 | |||
896 | } else { | ||
897 | |||
898 | userCollectionDetail.setId(null) | ||
899 | .setUserCollectionId(userCollection.getId()); | ||
900 | userCollectionDetailRepository.save(userCollectionDetail); | ||
901 | }*/ | ||
868 | 902 | ||
869 | userCollectionDetailRepository.save(userCollectionDetail); | ||
870 | 903 | ||
871 | } | 904 | } |
872 | } | 905 | } | ... | ... |
... | @@ -45,6 +45,7 @@ spring: | ... | @@ -45,6 +45,7 @@ spring: |
45 | hibernate: | 45 | hibernate: |
46 | # 生产环境设置成 none,避免程序运行时自动更新数据库结构 | 46 | # 生产环境设置成 none,避免程序运行时自动更新数据库结构 |
47 | ddl-auto: none | 47 | ddl-auto: none |
48 | show-sql: false | ||
48 | servlet: | 49 | servlet: |
49 | multipart: | 50 | multipart: |
50 | file-size-threshold: 2KB | 51 | file-size-threshold: 2KB | ... | ... |
... | @@ -64,12 +64,12 @@ | ... | @@ -64,12 +64,12 @@ |
64 | 64 | ||
65 | 65 | ||
66 | <!--监控sql日志输出 --> | 66 | <!--监控sql日志输出 --> |
67 | <logger name="jdbc.sqlonly" level="INFO" additivity="false"> | 67 | <logger name="jdbc.sqlonly" level="OFF" additivity="false"> |
68 | <appender-ref ref="console" /> | 68 | <appender-ref ref="console" /> |
69 | <appender-ref ref="info" /> | 69 | <appender-ref ref="info" /> |
70 | </logger> | 70 | </logger> |
71 | 71 | ||
72 | <logger name="jdbc.resultset" level="ERROR" additivity="false"> | 72 | <logger name="jdbc.resultset" level="OFF" additivity="false"> |
73 | <appender-ref ref="console" /> | 73 | <appender-ref ref="console" /> |
74 | <appender-ref ref="info" /> | 74 | <appender-ref ref="info" /> |
75 | </logger> | 75 | </logger> | ... | ... |
... | @@ -22,10 +22,7 @@ public class UserOperationControllerTest extends BaseTest { | ... | @@ -22,10 +22,7 @@ public class UserOperationControllerTest extends BaseTest { |
22 | @Test | 22 | @Test |
23 | public void deleteCollection() { | 23 | public void deleteCollection() { |
24 | try { | 24 | try { |
25 | String a = "{\n" + | 25 | String a = "eyJkYXRhIjpbeyJ1c2VyQ29sbGVjdGlvbklkIjo0LCJkZXRhaWxOYW1lIjoi6amv6b6Z5a6d5YW4IiwiY291bnQiOjIsImRldGFpbElkIjo0MDAsImRldGFpbFRvdGFsSW5kZXgiOjEsInVwZGF0ZVRpbWUiOjE2NTM1ODM2OTQwMDAsInR5cGUiOjEsImRldGFpbENvZGUiOiJtZWRpYV9lMmQ3NTIyMC1jNDExLTRkMWItOTM0ZS1jMWVhMjQ4Yzg4YTYiLCJ1c2VySWQiOjEsImRldGFpbFR5cGUiOiJNRURJQSIsImNyZWF0ZVRpbWUiOjE2NTM1ODM2OTQwMDAsImRldGFpbFNlcXVlbmNlIjoxLCJhcHBJZCI6NTcsIm5hbWUiOiJQZXJzb25hbENvbGxlY3Rpb25SZWNvcmRzIiwiZGV0YWlsRm9sZGVyQ29kZSI6IkRlZmF1bHQiLCJpZCI6OH1dLCJwbGF0Zm9ybUFjY291bnQiOiJ0b3BkcmF3In0="; |
26 | "\t\"platformAccount\": \"topdraw\",\n" + | ||
27 | "\t\"data\": \"[{\\\"appId\\\":\\\"57\\\",\\\"userId\\\":\\\"5\\\",\\\"type\\\":\\\"1\\\",\\\"name\\\":\\\"PersonalCollectionRecords\\\",\\\"count\\\":\\\"1\\\",\\\"images\\\":\\\"\\\",\\\"userCollectionId\\\":\\\"\\\",\\\"detailFolderCode\\\":\\\"\\\",\\\"detailType\\\":\\\"\\\"},\\\"detailId\\\":\\\"\\\",\\\"detailEpisodeId\\\":\\\"\\\",\\\"detailEpisodeCode\\\":\\\"\\\",\\\"detailName\\\":\\\"\\\",\\\"detailMark\\\":\\\"\\\",\\\"detailImg\\\":\\\"\\\",\\\"detailImg\\\":\\\"\\\",\\\"detailIndex\\\":\\\"\\\",\\\"detailTotalIndex\\\":\\\"\\\",\\\"detailPlayTime\\\":\\\"\\\",\\\"detailTotalTime\\\":\\\"\\\",\\\"detailSequence\\\":\\\"\\\",\\\"detailScore\\\":\\\"\\\",\\\"detailLike\\\":\\\"\\\",\\\"detailExtData\\\":\\\"\\\"}]\"\n" + | ||
28 | "}"; | ||
29 | ResultInfo weixinUserAndMember = this.userOperationController.deleteCollection(a); | 26 | ResultInfo weixinUserAndMember = this.userOperationController.deleteCollection(a); |
30 | System.out.println(weixinUserAndMember); | 27 | System.out.println(weixinUserAndMember); |
31 | } catch (Exception e) { | 28 | } catch (Exception e) { |
... | @@ -50,30 +47,7 @@ public class UserOperationControllerTest extends BaseTest { | ... | @@ -50,30 +47,7 @@ public class UserOperationControllerTest extends BaseTest { |
50 | @Test | 47 | @Test |
51 | public void addCollection() { | 48 | public void addCollection() { |
52 | try { | 49 | try { |
53 | String a = "{\n" + | 50 | String a = "eyJkYXRhIjpbeyJ1c2VyQ29sbGVjdGlvbklkIjo0LCJpbWFnZXMiOiJ7XCJsaXN0XCI6W3tcInNpemVcIjowLFwiZW5hYmxlXCI6ZmFsc2UsXCJ3aWR0aFwiOjI5MSxcImZpbGVVcmxcIjpcInVwbG9hZC9pbWFnZS9tZWRpYS8yY2YzNjIxMS03ZjZjLTQ3N2YtYjFjZi0wYjViNDVkMDljNDYucG5nXCIsXCJpZFwiOjY5NDEsXCJoZWlnaHRcIjozNTV9LHtcInNpemVcIjowLFwiZW5hYmxlXCI6ZmFsc2UsXCJ3aWR0aFwiOjI3NCxcImZpbGVVcmxcIjpcInVwbG9hZC9pbWFnZS9tZWRpYS9jYTZkMzEyYS05ZjA1LTQ4YjAtYTJlMi1kOGExMTdhZjhlN2QucG5nXCIsXCJpZFwiOjY5NDIsXCJoZWlnaHRcIjoxNjh9LHtcInNpemVcIjowLFwiZW5hYmxlXCI6ZmFsc2UsXCJ3aWR0aFwiOjI2MCxcImZpbGVVcmxcIjpcInVwbG9hZC9pbWFnZS9tZWRpYS80NzE3YzYzYy03NjQ1LTRiMmYtYTA2MS03NTBhZDYyYTI3ZGYuanBnXCIsXCJpZFwiOjY5NDMsXCJoZWlnaHRcIjozNjB9XSxcIm1hcFwiOntcImNoYW5uZWxfbG9nb1wiOlsyXSxcInN0aWxsc1wiOlswXSxcInBvc3RlclwiOlsxXX19IiwiZGV0YWlsTmFtZSI6Iumpr+m+meWuneWFuCIsImNvdW50IjoyLCJkZXRhaWxJZCI6NDAwLCJkZXRhaWxUb3RhbEluZGV4IjoxLCJ1cGRhdGVUaW1lIjoxNjUzNTgzNjk0MDAwLCJ0eXBlIjoxLCJkZXRhaWxDb2RlIjoibWVkaWFfZTJkNzUyMjAtYzQxMS00ZDFiLTkzNGUtYzFlYTI0OGM4OGE2Iiwid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||
56 | "\t\"app_id\": 57,\n" + | ||
57 | "\t\"user_id\": 1,\n" + | ||
58 | "\t\"type\": 1,\n" + | ||
59 | "\t\"name\": \"PersonalCollectionRecords\",\n" + | ||
60 | "\t\"count\": 22,\n" + | ||
61 | "\t\"images\": \"{\\\"map\\\":{\\\"poster\\\":[0]},\\\"list\\\":[{\\\"id\\\":47422,\\\"type\\\":2,\\\"width\\\":222,\\\"height\\\":294,\\\"fileUrl\\\":\\\"upload/image/media/2020-07-30/9a8a02db-9444-4bff-ba54-ea784ae4f88c.jpg\\\",\\\"size\\\":104643}]}\",\n" + | ||
62 | "\t\"id\": 756756,\n" + | ||
63 | "\t\"user_collection_id\": 1,\n" + | ||
64 | "\t\"detail_folder_code\": \"Default\",\n" + | ||
65 | "\t\"detail_type\": \"MEDIA\",\n" + | ||
66 | "\t\"detail_id\": 46532,\n" + | ||
67 | "\t\"detail_code\": \"media_558bc45a-5480-46ec-be9a-c749ffdbdf49\",\n" + | ||
68 | "\t\"detail_name\": \"熊出没之探险日记2\",\n" + | ||
69 | "\t\"detail_total_index\": 40,\n" + | ||
70 | "\t\"detail_sequence\": 1,\n" + | ||
71 | "\t\"create_time\": 1644503167000,\n" + | ||
72 | "\t\"update_time\": 1644503167000\n" + | ||
73 | "\t}\n" + | ||
74 | "\t],\n" + | ||
75 | "\t\"platformAccount\": \"topdraw\"\n" + | ||
76 | "}"; | ||
77 | ResultInfo weixinUserAndMember = this.userOperationController.addCollection(a); | 51 | ResultInfo weixinUserAndMember = this.userOperationController.addCollection(a); |
78 | System.out.println(weixinUserAndMember); | 52 | System.out.println(weixinUserAndMember); |
79 | } catch (Exception e) { | 53 | } catch (Exception e) { | ... | ... |
-
Please register or sign in to post a comment